Code: Select all
'Random centripetal motion
' test program for "Brownian tree"
'by Dutchman, january 2017
option base 1
randomize
graphics
GRAPhics clear 0.7,0.7,0
OPTION SPRITE POS CENTRAL
' ---- 'brownian tree' variables
GET Screen size sw,sh
mid=sw/2+1i*sh/2
pi=ARG(-1)
pipi=2*pi
size=sw/15
parts=1 ! dim pos(parts)
margin=5*size
speed=1
'--- end 'brownian' variables
'
core=margin/5
x0=sw/2 ! y0=sh/2
draw color 0,0,0
draw size 3
draw line x0-100,y0 TO x0+100,y0
draw line x0,y0+100 TO x0,y0-100
draw circle x0,y0 SIZE core
n=1
SPRITE n BEGIN size,size
fill color 0,0,1
fill circle size/2,size/2 size size/2
sprite end
sprite n show
sprite n alpha 0.5
DO
pos(n)=mid+margin*EXP(1i*RND(1)*pipi)
x=REAL(.pos(n)) ! y=IMAG(.pos(n))
sprite n at x,y
pause 0.1
DO
move(n)
pause 0.2
until ABS(pos(n)-mid)<core
SPRITE n STAMP
UNTIL 0
END
'======= move-function for "Brownian tree"
'r'
DEF move(n)
' --- random centripetal move
z=.pos(n)-.mid
r=ABS(z) ! phi=ARG(z)
dr=.size/2
z=dr*EXP(1i*(phi+.pi)) ' towards center
.pos(n)+=z+dr*EXP(1i*RND(1)*.pipi)
x=REAL(.pos(n)) ! y=IMAG(.pos(n))
SPRITE n AT x,y
/* decomment in Brownian tree
' --- restart if outside "area"
n$=n
IF NOT SPRITES_COLLIDE(n$,"area") THEN
SetParticle(n,.mid,.extent+.margin)
ENDIF
*/
END DEF
''