Skip to content

Instantly share code, notes, and snippets.

Created August 14, 2017 08:57
Show Gist options
  • Save anonymous/1106282814e62e7b9ddce618901b80cb to your computer and use it in GitHub Desktop.
Save anonymous/1106282814e62e7b9ddce618901b80cb to your computer and use it in GitHub Desktop.
SmallBASIC: dd
#sec:Main
' sier2.bs
' From "Fractals" by Hans Lauwerier
' Heavily modified for SB :-)
' Method 2 to draw Sierpinski Triangle
cls
c=3
rect 0,0,160,160 color o filled
p=5: dim T(p): a= SQR(3)
for m=0 to p
for n=0 to 3^m-1
n1=n
for l = 0 to m-1
t(l) = n1 mod 3 : n1=n1\3: next l
x=0: y=0
for k=0 to m-1
x = x+cos((4*t(k)+1)*PI/6)/2^k
y= y+sin((4*t(k)+1)*PI/6)/2^k
next k
u1 =45*(x+a/2^(m+1))+80
u2=45*(x-a/2^(m+1))+80
v1=45*(y-1/2^(m+1))+100
v2=45*(y+1/2^m)+100
x = 45*x+80
y = 45*y+100
line u1, v1, x, v2 COLOR c
line x,v2, u2, v1 COLOR c
line u2,v1,u1,v1 COLOR c
next n
c=c+2
next m
beep
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment