Post by tsh73 on Nov 11, 2020 9:09:58 GMT
So if you go, and turn, and loop it - you get arc
But if you spawn another arc in the process?
Probably could be tweaked forever
But if you spawn another arc in the process?
Probably could be tweaked forever
'random vegetation-like things
'tsh73 Nov 2020
nomainwin
global pi, deg2rad, rad2deg
pi = acs(-1)
deg2rad = pi/180
rad2deg = 1/deg2rad
global cx, cy, handle$
global stackTop, maxStack
global ix, iy, ia, idd, ida
maxStack=100
stackTop = 0 'empty
ix=1: iy=2: ia=3: idd=4: ida=5
'for call arc x0,y0, a, dd,da
dim stack(maxStack, ida)
WindowHeight = 350
WindowWidth = DisplayWidth
open "test" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
#gr "home; posxy cx cy"
handle$ = "#gr"
for x00 = 150 to DisplayWidth-150 step 150
'values for first arc
x0=x00
y0=cy*1.5
a=0
dd = 9
'dd = 7
da = 7
if rnd(0)<1/2 then da = 0-da
while 1
'#gr "place 10 ";(11-dd)*20
'#gr "\";dd
'print ">",x0,y0, a, dd,da
call arc x0,y0, a, dd,da
if stackTop=0 then exit while
'else get from the stack
x0=stack(stackTop, ix)
y0=stack(stackTop, iy)
a=stack(stackTop, ia)
dd=stack(stackTop, idd)
da=stack(stackTop, ida)
stackTop = stackTop-1
wend
timer 500, [nxt]
wait
[nxt]
timer 0
next
wait
[quit]
close #gr
end
sub arc x0,y0, a, dd,da
#handle$ "place ";x0 ;" ";y0
#handle$ "north"
#handle$ "turn ";a
n = 30
n0 = n/3 'branch only before n0
j0= int(rnd(0)*n0)+1 '+smth so no empty branches due to 0
'print dd, j0
flag=1
for j = 1 to n
#handle$ "go ";dd
#handle$ "turn ";da
'if ((j = 10) or (j = 20)) and (dd >1) then
'if ((j = 10)) and (dd >1) then
'if ((j = 15)) and (dd >1) then
'if flag and (rnd(0)<1/n0) and(j<n0) and (dd >1) then
if flag and (j=j0) and (dd >1) then
stackTop = stackTop+1
#handle$ "posxy x y"
stack(stackTop, ix) =x
stack(stackTop, iy) =y
stack(stackTop, ia) =getAngle()-sign(da)*30
stack(stackTop, idd)=dd-1
stack(stackTop, ida)=0-da
'print "<",x,y, stack(stackTop, ia), dd-1,0-da
flag=0
end if
dd=dd*0.99'5
next
'final circle
for j = 1 to 50
#handle$ "go ";dd/3
#handle$ "turn ";da
next
end sub
'------------------------------
function getAngle()
#handle$, "posxy x0 y0"
#handle$, "up"
#handle$, "go 1000" 'probably well offscreen, doesn't matter
#handle$, "posxy x1 y1"
'now, we should put pen down and restore previous point
#handle$, "go -1000; down" 'is the easiest way
getAngle = arctan2(0-(y1-y0),x1-x0) *rad2deg
end function
function sign(x)
sign = (x>0)-(x<0)
end function
function rand(n)
rand = rnd(1)*n
end function
'by nukesrus21, returns -Pi..Pi as C standard library version (though in C it's atan2(y,x) - note argument order)
Function arctan2(x, y)
On Error GoTo [Error] 'For the first 0, 0 to prevent divide by zero error
arctan2 = (2 * (atn((sqr((x * x) + (y * y)) - x)/ y)))
[Error]
End Function