Beat the sub routine for drawing Sierpinski, I don't mean beat this code that demo's that sub's flexibility.
Sierpinski in Space is the title for this demo when I get around to cleaning it up:
' ss3 w RECR sier.bas SmallBASIC 0.12.6 [B+=MGA] 2016-05-20
'from screen saver number 1.bas 2016-02-11 SmallBASIC 0.12.0 [B+=MGA]
' this version replaces solid triangle with Sierpinski
randomize
label restart
ntri=(rnd*5)\1+1
dim x1(ntri),x2(ntri),x3(ntri),y1(ntri),y2(ntri),y3(ntri),ct(ntri)
dim dx1(ntri),dx2(ntri),dx3(ntri),dy1(ntri),dy2(ntri),dy3(ntri)
for i=1 to ntri
x1(i)=(xmax+200)*rnd-100 : x2(i)=(xmax+200)*rnd-100 : x3(i)=(xmax+200)*rnd-100
y1(i)=(ymax+200)*rnd-100 : y2(i)=(ymax+200)*rnd-100 : y3(i)=(ymax+200)*rnd-100
dx1(i)=10*rnd*rdir : dx2(i)=10*rnd*rdir : dx3(i)=10*rnd*rdir
dy1(i)=5*rnd*rdir : dy2(i)=5*rnd*rdir : dy3(i)=5*rnd*rdir
c1=int(rnd*2):c2=int(rnd*2):c3=int(rnd*2)
ct(i)=rgb((55+200*rnd)*c1,(50+200*rnd)*c2,(55+200*rnd)*c3)
if ct(i)=0 then ct(i)=rgb(255,0,0)
next
timesup = rnd*5000+15000
t=ticks
while ticks-t<timesup
if len(inkey) then goto restart
cls
for i=1 to ntri
color ct(i)
SierLineTri x1(i),y1(i),x2(i),y2(i),x3(i),y3(i),0
x1(i)=x1(i)+dx1(i)
if x1(i)<-100 then dx1(i)=dx1(i)*-1
if x1(i)>xmax+100 then dx1(i)=dx1(i)*-1
x2(i)=x2(i)+dx2(i)
if x2(i)<-100 then dx2(i)=dx2(i)*-1
if x2(i)>xmax+100 then dx2(i)=dx2(i)*-1
x3(i)=x3(i)+dx3(i)
if x3(i)<-100 then dx3(i)=dx3(i)*-1
if x3(i)>xmax+100 then dx3(i)=dx3(i)*-1
y1(i)=y1(i)+dy1(i)
if y1(i)<-100 then dy1(i)=dy1(i)*-1
if y1(i)>ymax+100 then dy1(i)=dy1(i)*-1
y2(i)=y2(i)+dy2(i)
if y2(i)<-100 then dy2(i)=dy2(i)*-1
if y2(i)>ymax+100 then dy2(i)=dy2(i)*-1
y3(i)=y3(i)+dy3(i)
if y3(i)<-100 then dy3(i)=dy3(i)*-1
if y3(i)>ymax+100 then dy3(i)=dy3(i)*-1
next
showpage
delay 10
wend
goto restart
func rdir()
if int(rnd*2) then rdir=1 else rdir=-1
end
'first a sub, given 3 points of a triangle draw the traiangle within
'from the midpoints of each line forming the outer triangle
'this is the basic Sierpinski Unit that is repeated at greater depths
'3 points is 6 arguments to function plus a depth level
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Beat this!
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sub SierLineTri(x1, y1, x2, y2, x3, y3, depth)
local mx1, mx2, mx3, my1, my2, my3
if depth = 0 then 'draw outer most "skin"
line x1, y1, x2, y2
line x2, y2, x3, y3
line x1, y1, x3, y3
end if
'find midpoints
if x2 < x1 then mx1 = (x1 - x2)/2 + x2 else mx1 = (x2 - x1)/2 + x1
if y2 < y1 then my1 = (y1 - y2)/2 + y2 else my1 = (y2 - y1)/2 + y1
if x3 < x2 then mx2 = (x2 - x3)/2 + x3 else mx2 = (x3 - x2)/2 + x2
if y3 < y2 then my2 = (y2 - y3)/2 + y3 else my2 = (y3 - y2)/2 + y2
if x3 < x1 then mx3 = (x1 - x3)/2 + x3 else mx3 = (x3 - x1)/2 + x1
if y3 < y1 then my3 = (y1 - y3)/2 + y3 else my3 = (y3 - y1)/2 + y1
'draw inner triangle
line mx1, my1, mx2, my2
line mx2, my2, mx3, my3
line mx1, my1, mx3, my3
'IF YOU WANT DEPTH FLEXIBILITY THEN
'in next line change 4 to MaxDepth and make MaxDepth either a constant or another parameter in call
'END IF
if depth < 4 then ' are we done drawing? no, call me
SierLineTri(x1, y1, mx1, my1, mx3, my3, depth + 1)
SierLineTri(x2, y2, mx1, my1, mx2, my2, depth + 1)
SierLineTri(x3, y3, mx3, my3, mx2, my2, depth + 1)
end if
end sub
Flexible, easy to use and understand. It can draw a Sierpinskiy at a given depth from any 3 points.