Author Topic: Sierpinski Carpet  (Read 1558 times)

B+

  • Guest
Sierpinski Carpet
« on: February 13, 2016, 09:54:26 pm »
without recursion, random, modulus, division or even a while loop!
Code: [Select]
'Sier Carpet v3.bas SmallBASIC 0.12.2 [B+=MGA] 2016-02-13

sq=512
s=2
stepper=2*s
start=1
lc=0
label doloop
  for x=start to sq step stepper
    for y=start to sq step stepper
      rect x,y,x+s,y+s,rgb(0,lc*15+128,0) filled
    next
  next
  start=start+s
  s=2*s
  stepper=2*stepper
  lc=lc+1
if stepper<=sq then goto doloop
pause 'for snapshot

B+

  • Guest
Re: Sierpinski Carpet
« Reply #1 on: February 13, 2016, 10:22:31 pm »
Here is more carpet like symmetry:
Code: [Select]
'Symmetric Sier Carpet v3.bas SmallBASIC 0.12.2 [B+=MGA] 2016-02-13

sq=512
s=2
stepper=2*s
start=1
lc=0
label doloop
  for x=start to sq step stepper
    for y=start to sq step stepper
      c=rgb(lc*15+128,0,0)
      rect x,y,x+s,y+s,c filled
      d=512-x
      dy=512-y
      rect 1024-d-s,y step s,s,c filled
      rect x,1024-dy-s step s,s,c filled
      rect 1024-d-s,1024-dy-s step s,s,c filled
    next
  next
  start=start+s
  s=2*s
  stepper=2*stepper
  lc=lc+1
if stepper<=sq then goto doloop
pause 'for snapshot

ScriptBasic

  • Guest
Re: Sierpinski Carpet
« Reply #2 on: February 13, 2016, 11:27:07 pm »
Hi Mark,

It looks like step can be used to increment a variable as well as the traditional FOR keyword in SmallBASIC.


B+

  • Guest
Re: Sierpinski Carpet
« Reply #3 on: February 14, 2016, 12:01:51 am »
Hi John,

Imaginative idea, but STEP is used in SmallBASIC for LINE or RECT as relative position to first x,y pair given as opposed to absolute screen coordinates.
absolute: RECT x1,y1,x2,y2
or relative: RECT x1,y1 STEP width, height

ScriptBasic

  • Guest
Re: Sierpinski Carpet
« Reply #4 on: February 14, 2016, 12:41:06 am »
Has a BBC plot smell to it.  :)

B+

  • Guest
Re: Sierpinski Carpet
« Reply #5 on: February 14, 2016, 01:26:32 am »
Also might sense old QB as well.