
 sub Sierpinski3d(sys cylinder,sphere)
 =====================================

  'TUBULAR TRIANGLE
  static int TubularTriangle,Sierpinski,SierpinskiPyramid, ti,i,j
  static float _
    ra=.04,                'radius of tubes
    le=1.0,                'length of tubes
    ap=sqr(.75),           'from base to apex
    tb=-tan(rad(30))*.5,   'from centre down to base
    ta=ap+tb,              'from centre to apex
    d=rad(30),             '
    a=.25/cos(d),          'from centre to y position of apex triangle
    b=a*sin(d),            '
    c=a*cos(d),            '
    sl3=-deg(asin(-tb/ap)),'slope angle for side of tetrahedron
    sl4=-deg(asin(.5/ap))  'slope angle for side of pyramid
  '
  if not ti
  ti=1
  TubularTriangle = CompileList
  =============================
  '
  'BASE
  PushMatrix
  Translatef -.5,tb,0
  Rotatef -90,0,0,1
  Scalef ra,le,ra
  go cylinder
  PopMatrix
  'LEFT
  PushMatrix
  Translatef -.5,tb,0
  Rotatef -30,0,0,1
  Scalef ra,le,ra
  go cylinder
  PopMatrix
  'RIGHT
  PushMatrix
  Translatef .5,tb,0
  Rotatef 30,0,0,1
  Scalef ra,le,ra
  go cylinder
  PopMatrix
  Endlist
  '
  Sierpinski = CompileList
  ========================
  '
  PushMatrix
  go TubularTriangle 'MAIN
  PopMatrix
  '
  PushMatrix
  Scalef .5,.5,.5 'CENTRE
  Rotatef 180,0,0,1
  go TubularTriangle
  PopMatrix
  '
  PushMatrix
  for i=1 to 3
  PushMatrix
  Translatef 0,a,0 'CORNERS
  Scalef .25,.25,.25
  Rotatef 180,0,0,1
  go TubularTriangle
  PopMatrix
  Rotatef 120,0,0,1
  next
  PopMatrix
  Endlist
  '
  '
  
  SierpinskiPyramid = CompileList
  ===============================
  Pushmatrix 'whole
  '
  'APEX CAP
  PushMatrix
  Translatef 0,ta*cos(rad(sl4)),0 'TET sl3
  Scalef ra,ra,ra
  go sphere
  PopMatrix
  '
  for i=1 to 4 'TET 3
    PushMatrix
    Translatef 0,0, .33333 'TET -tb*.66667
    Rotatef sl4,1,0,0 'TET sl3
    gosub Sierpinski2 'EACH SIDE
    'BASE CAPS
    Translatef -.5,tb,0
    Scalef ra,ra,ra
    go sphere
    PopMatrix
    Rotatef 90,0,1,0 'TET 120
  next
  Popmatrix 'whole 3d form
  glEndlist
  '
  end if 'ti compiled lists
  '
  Scalef 2.5,2.5,2.5
  go SierpinskiPyramid
  '
  exit sub

  .Sierpinski2 'subroutine
  '=======================
  '
  go Sierpinski 'MAIN
  '
  'NEXT LEVEL
  PushMatrix
  for j=1 to 3
  '
  PushMatrix
  Translatef -c*1.5,-b*1.5,0
  Scalef .125,.125,.125
  glRotatef 180,0,0,1
  'go Sierpinski 'INNER 1
  go TubularTriangle
  glPopMatrix
  '
  PushMatrix
  Translatef -c*.5,-b*1.5,0
  Scalef .125,.125,.125
  Rotatef 180,0,0,1
  'go Sierpinski 'INNER 2
  go TubularTriangle
  PopMatrix
  '
  PushMatrix
  Translatef c*.5,-b*1.5,0
  Scalef .125,.125,.125
  Rotatef 180,0,0,1
  'go Sierpinski 'INNER 3
  go TubularTriangle
  PopMatrix
  Rotatef 120,0,0,1
  '
  next 'j
  '
  PopMatrix
  ret

  '
  end sub
