61 lines
1.4 KiB
Plaintext
61 lines
1.4 KiB
Plaintext
'Fractal Tree - for Run Basic - 29 Apr 2018
|
|
'from BASIC256 - http://rosettacode.org/wiki/Fractal_tree#BASIC256
|
|
'copy this text and go to http://www.runbasic.com
|
|
|
|
WindowWidth = 500 'Run Basic max size 800 x 600
|
|
WindowHeight = 350
|
|
c = 255 '255 for white '0 for black
|
|
|
|
graphic #w, WindowWidth, WindowHeight
|
|
#w cls("black") 'black background color
|
|
#w color(c,c,c) 'changes color to white
|
|
|
|
level = 10 ' initial values
|
|
leng = 50
|
|
x = 230: y = 325 ' initial values x = 230: y = 285
|
|
pi = 3.1415
|
|
rotation = 3.1415/2
|
|
|
|
'A1 = pi/27 : A2 = pi/8 ' constants which determine shape
|
|
'C1 = 0.7 : C2 = 0.85 ' tree is drifted left
|
|
|
|
A1 = pi/9 : A2 = pi/9 ' constants which determine shape
|
|
C1 = 0.85 : C2 = 0.85 ' Symmetrical Tree
|
|
|
|
dim xs(level+1) : dim ys(level+1) ' stacks
|
|
|
|
print : print "Welcome to the Run BASIC Fractal Tree Program"
|
|
#w color("green") 'color green
|
|
gosub [tree]
|
|
render #w
|
|
' imgsave "Fractal_tree_BASIC-256.png", "PNG"
|
|
Print "Thank you and goodbye"
|
|
end
|
|
|
|
[tree]
|
|
xs(level) = x : ys(level) = y
|
|
gosub [putline]
|
|
if level>0 then
|
|
level = level - 1
|
|
leng = leng*C1
|
|
rotation = rotation - A1
|
|
gosub [tree]
|
|
leng = leng/C1*C2
|
|
rotation = rotation + A1 + A2
|
|
gosub [tree]
|
|
rotation = rotation - A2
|
|
leng = leng/C2
|
|
level = level + 1
|
|
end if
|
|
x = xs(level) : y = ys(level)
|
|
return
|
|
|
|
[putline]
|
|
yn = -1*sin(rotation)*leng + y
|
|
xn = cos(rotation)*leng + x
|
|
#w line(x,y,xn,yn)
|
|
x = xn : y = yn
|
|
return
|
|
'end of code
|
|
End
|