
 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
  glPushMatrix
  gltranslatef -.5,tb,0
  glRotatef -90,0,0,1
  glscalef ra,le,ra
  go cylinder
  glPopMatrix
  'LEFT
  glPushMatrix
  gltranslatef -.5,tb,0
  glRotatef -30,0,0,1
  glscalef ra,le,ra
  go cylinder
  glPopMatrix
  'RIGHT
  glPushMatrix
  gltranslatef .5,tb,0
  glRotatef 30,0,0,1
  glscalef ra,le,ra
  go cylinder
  glPopMatrix
  glEndlist
  '
  Sierpinski = CompileList
  ========================
  '
  glPushMatrix
  go TubularTriangle 'MAIN
  glPopMatrix
  '
  glPushMatrix
  glScalef .5,.5,.5 'CENTRE
  glRotatef 180,0,0,1
  go TubularTriangle
  glPopMatrix
  '
  glPushMatrix
  for i=1 to 3
  glPushMatrix
  glTranslatef 0,a,0 'CORNERS
  glScalef .25,.25,.25
  glRotatef 180,0,0,1
  go TubularTriangle
  glPopMatrix
  glRotatef 120,0,0,1
  next
  glPopMatrix
  glEndlist
  '
  '
  
  SierpinskiPyramid = CompileList
  ===============================
  glpushmatrix 'whole
  '
  'APEX CAP
  glPushMatrix
  gltranslatef 0,ta*cos(rad(sl4)),0 'TET sl3
  glscalef ra,ra,ra
  go sphere
  glPopMatrix
  '
  for i=1 to 4 'TET 3
    glPushMatrix
    glTranslatef 0,0, .33333 'TET -tb*.66667
    glRotatef sl4,1,0,0 'TET sl3
    gosub Sierpinski2 'EACH SIDE
    'BASE CAPS
    gltranslatef -.5,tb,0
    glscalef ra,ra,ra
    go sphere
    glPopMatrix
    glRotatef 90,0,1,0 'TET 120
  next
  glpopmatrix 'whole 3d form
  glEndlist
  '
  end if 'ti compiled lists
  '
  glscalef 2.5,2.5,2.5
  go SierpinskiPyramid
  '
  exit sub

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

  '
  end sub
