Post by tsh73 on Feb 11, 2023 20:45:52 GMT
We can easily split a picture with random walk.
But how to run it backwards to *assemble* picture with random walk?
Here's one of ways
(works in JB 1.01, JB 2 and LB 4.51 - because they all give same RND sequence after RANDOMIZE 0.5)
So the trick was
* start with goal,
* write ending coords,
* put them in DATA statement,
* and on back pass reverse the process (+ to - etc)
And for picture we need whole pre-garbled picture instead of DATA statements.
But how to run it backwards to *assemble* picture with random walk?
Here's one of ways
(works in JB 1.01, JB 2 and LB 4.51 - because they all give same RND sequence after RANDOMIZE 0.5)
'how to make random walk converge to a goal?
'one of ways
'tsh73 Feb 2023
nomainwin
open "Randomly to a goal" for graphics_nsb_nf as #gr
#gr "home; down; posxy cx cy"
#gr "trapclose [quit]"
global sz, cx, cy
sz=30
nPts=4
dim x(nPts), y(nPts), colr$(nPts)
for i = 1 to nPts
read x,y,c$
'x(i)=x: y(i)=y: colr$(i)=c$ 'forth pass
x(i)=0-x: y(i)=0-y: colr$(i)=c$ 'back pass
next
dim dx(4), dy(4) 'directions
for i = 1 to 4
read dx,dy
dx(i)=dx: dy(i)=dy
next
randomize 0.5
'initial
for i = 1 to nPts
call putBox x(i), y(i), colr$(i)
next
call pause 60
for k = 1 to 150 'just make sure thigs went off screen from initial pos
for i = 1 to nPts
scan
dir = int(rnd(0)*4+1)
call putBox x(i), y(i), "white"
'print i, x(i),y(i),dx(dir), dy(dir)
'x(i)=x(i)+dx(dir) 'forth pass
'y(i)=y(i)+dy(dir)
x(i)=x(i)-dx(dir) 'back pass
y(i)=y(i)-dy(dir)
call putBox x(i), y(i), colr$(i)
next
call pause 60
next
for i = 1 to nPts
'redraw boxed on last position 'cause previous pos might obscure of of them
call putBox x(i), y(i), colr$(i)
'positions to be used in DATA
print 0-x(i);",";0-y(i)
next
#gr "flush"
'r g
'b y
'back pass
data 0,-12, "yellow"
data 6,8, "red"
data 12,-1, "green"
data 3,-6, "blue"
'goal position - forth pass
'data 0, 0, "yellow"
'data -1, -1, "red"
'data 0, -1, "green"
'data -1, 0, "blue"
'directions
data 1,0, 0,1, -1,0, 0,-1
wait
[quit]
timer 0
close #gr
end
sub putBox x, y, colr$
#gr "color ";colr$
#gr "backcolor ";colr$
xx=cx+x*sz
yy=cy+y*sz
#gr "place ";xx; " "; yy
#gr "boxfilled ";xx+sz; " "; yy+sz
end sub
sub pause mil
t=time$("ms")+mil
while time$("ms")<t
scan
wend
exit sub
[quit]
close #gr
end
end sub
So the trick was
* start with goal,
* write ending coords,
* put them in DATA statement,
* and on back pass reverse the process (+ to - etc)
And for picture we need whole pre-garbled picture instead of DATA statements.