Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:57 14 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Back to the ’70’s - Lava Lamp

Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5922
Posted: 09:17pm 03 Sep 2015
Copy link to clipboard 
Print this post

I saw this program on the PureBasic forum and thought it could be translated to MMBasic.

It is very slow but not too bad considering the amount of processing for each pixel.

' TassyJim
' 4th September 2015
' from a program in PureBasic by 'Idle' on the PureBasic forum.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
OPTION EXPLICIT

DIM NumCircles = 5, Width = 240, Height = 200, pix = 2
DIM re
DIM mc(NumCircles,6)
main:
CLS
DO
re = initialise(NumCircles)
re = draw(NumCircles,pix)
LOOP
END

FUNCTION initialise(NumCircles)
LOCAL i
FOR i = 0 TO NumCircles
mc(i,1) = RRandom(0, Width) 'x
mc(i,2) = RRandom(0, Height) 'y
mc(i,3) = RRandom(20, 80) 'd
mc(i,4) = mc(i,3)/ 2 'r
mc(i,5) = RRandom(-3, 3) 'vx
mc(i,6) = RRandom(-3, 3) 'vy
NEXT i
END FUNCTION

FUNCTION draw(NumCircles,sx)
LOCAL x, y, dx, dy, sum, dd, i
FOR i = 0 TO NumCircles 'move circles AND keep in bounds
mc(i,1) = mc(i,1) + mc(i,5)
mc(i,2) = mc(i,2) + mc(i,6)
IF mc(i,1) - mc(i,4) <= 0 THEN
mc(i,5) = ABS(mc(i,5))
ENDIF
IF mc(i,1) + mc(i,4) >= Width THEN
mc(i,5) = -ABS(mc(i,5))
ENDIF
IF mc(i,2)- mc(i,4) <= 0 THEN
mc(i,6) = ABS(mc(i,6))
ENDIF
IF mc(i,2) + mc(i,4) >= Height THEN
mc(i,6) = -ABS(mc(i,6))
ENDIF
NEXT i
x = 0
WHILE x < Width 'plot routine
'print x
y=0
WHILE y < Height
sum = 0
FOR i = 0 TO NumCircles
dx = x - mc(i,1)
dy = y - mc(i,2)
dd = dx * dx + dy * dy
sum = sum + (mc(i,3) * mc(i,3) / dd)
NEXT
IF sum > 3 THEN
PIXEL x,y,RGB(0, 255, 0)
ELSE
PIXEL x,y,RGB(0, 0, 0)
ENDIF
y = y + sx
WEND
x = x + sx
WEND
END FUNCTION

FUNCTION RRandom(min,max)
RRandom = RND()*(max-min) + min
END FUNCTION


You can change the default settings.
NumCircles = 5, Width = 240, Height = 200, pix = 2
pix is the 'resolution' 2 sets every second pixel. 1 is nicer to look at but 4 times as long to paint a screen.

I have tested it on MX170 with 2.4 inch display and MX470 with 7 inch.
Start with the default settings - if you try a full screen 7inch be prepared for a long wait.

Jim

VK7JH
MMedit   MMBasic Help
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9075
Posted: 09:30pm 03 Sep 2015
Copy link to clipboard 
Print this post

Cute.
Smoke makes things work. When the smoke gets out, it stops!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 02:10am 04 Sep 2015
Copy link to clipboard 
Print this post

Slow alright - thank heavens for CFunctions!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9075
Posted: 04:09pm 04 Sep 2015
Copy link to clipboard 
Print this post

I remember these kinds of line-by-line graphics drawings from my days with the Atari.
This was EXACTLY how it used to draw the images too.
Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024