DIM Code% &10000

REM shape of the data:
REM .Vertices is a table of the vertices:
REM DCD x :DCD y :DCD z         (x left-right; y up-down; z in-out)
REM
REM .Faces is a table of faces:
REM = control := v0 := v1 := v2 :....
REM where v0,v1,v2,.... are the vertices to this face and
REM control is specifier:
REM top bit means always plot the next face after this one in the same colour
REM Next to top bits means 'be a bit darker'
REM bottom 6 bits mean number of edges to this face.
REM If control is 0, then that's the end of the table


FOR Shape = 34 TO 34

FOR Pass = 8 TO 10 STEP 2

P%=Code%
L%=Code%+&10000

 [ OPT Pass
 DCD Vertices-Code%
 DCD EndVertices-Vertices
 DCD Faces-Code%
 ]

CASE Shape OF
WHEN 34
  [ OPT Pass                            ; Acorn

  .Vertices
  ]
  RV%=144
  RH%=80
  RHL%=88
  BL%=96

  REM Top
  [ OPT Pass
    DCD 0 :DCD 0 :DCD RV%
  ]
  FOR Z%=15 TO 90 STEP 15
    RS=RH%*SIN RAD Z%
    RC=RV%*COS RAD Z%
    FOR X%=0 TO 360-30 STEP 30
      [ OPT Pass
        DCD RS*COS RAD X% :DCD RS*SIN RAD X% :DCD RC
      ]
    NEXT
  NEXT

  REM Lip to bottom
  FOR Z%=30 TO 90 STEP 30
    RS=RH%+(RHL%-RH%)*SIN RAD Z%
    RC=(RHL%-RH%)*COS RAD Z%-(RHL%-RH%)
    FOR X%=0 TO 360-30 STEP 30
      [ OPT Pass
        DCD RS*COS RAD X% :DCD RS*SIN RAD X% :DCD RC
      ]
    NEXT X%
  NEXT Z%

  REM Bottom
  FOR Z%=90+12 TO 90+84 STEP 12
    RS=RHL%*SIN RAD Z%
    RC=RHL%*COS RAD Z%-(RHL%-RH%)
    FOR X%=0 TO 360-30 STEP 30
      [ OPT Pass
        DCD RS*COS RAD X% :DCD RS*SIN RAD X% :DCD RC
      ]
    NEXT
  NEXT

  REM Stalk
    RC = RC-25
    FOR X%=0 TO 360-30 STEP 30
      [ OPT Pass
        DCD RS*COS RAD X% :DCD RS*SIN RAD X% :DCD RC
      ]
    NEXT

  REM Branch
    FOR X%=-3 TO 3
      X = X%*BL%/3
      Z = -(X/3+X*X/1600)
      FOR A%=60 TO 360 STEP 60
        [ OPT Pass
          DCD X :DCD (6+X%)*RS*COS RAD A%/6 :DCD RC + (6+X%)*RS*SIN RAD A%/6 + Z
        ]
      NEXT A%
    NEXT X%
  
  [ OPT Pass
  .EndVertices
  .Faces
  ]

  REM Top knot
  FOR X%=0 TO 11
    [ OPT Pass
      = &03  := 0         := X% + 1       := (X%+1) MOD 12 + 1
    ]
  NEXT X%

  REM Top (5 steps) + Lip (3 steps) + Bottom (7 steps) + Stalk (1 step)
  FOR X%=0 TO 4 + 3 + 7 + 1
    FOR Z%=0 TO 11
      [ OPT Pass
        = &04  := X%*12+(Z%+1)MOD12+1 := X%*12+Z%+1 := X%*12+Z%+13 := X%*12+(Z%+1)MOD12+13
      ]
    NEXT Z%
  NEXT X%

  REM Branch
    [ OPT Pass
      = &06 := 210 := 209 := 208 := 207 := 206 := 205
    ]
    FOR X%=-2 TO 3
      FOR A%=0 TO 5
        [ OPT Pass
          = &04 := (X%+2)*6+A%+205 := (X%+2)*6+(A%+1)MOD6+205 := (X%+3)*6+(A%+1)MOD6+205 := (X%+3)*6+A%+205
        ]
      NEXT A%
    NEXT X%
    [ OPT Pass
      = &06 := 241 := 242 := 243 := 244 := 245 := 246
    ]

  [ OPT Pass
    = 0
    ALIGN
  ]

ENDCASE

NEXT Pass

OSCLI("*Save ^.Shapes."+STR$(Shape)+" "+STR$~Code%+"+"+STR$~(P%-Code%))
OSCLI("*SetType ^.Shapes."+STR$(Shape)+" Data")
NEXT Shape
END
