Cube Octahedron

- 3D wire frame and balls

By pushing out the cube faces and rotating each by 45 degrees a Cube Octagon is created. Opposite faces are the same color. This shows how to develop a simple shape into a more complex one.

The procedure Square3D draws each square. If RepCount is even, a ball is added to the vertex.

To New
  # set default screen, pen and turtle values
  ResetAll SetScreenSize [400 400] HideTurtle
  SetSC Black SetPC Green SetPS 1 PenUp

To Cube :Side
  Repeat 3 [
    SetPC RepCount Repeat 2 [
      Forward :Side/1.4 Down 90
      Left 45 Square3D :Side Right 45
      Up 90 Back :Side/1.4
      Up 180]
    Up 90 Left 90]

To Square3D :Side
  # square (side x side) drawn from centre (tp)
  Back :Side/2 Right 90 Back :Side/2 PenDown
  Repeat 4 [
    SetPW 1 LineStart Forward :Side LineEnd Left 90 Wait 12
    If Even? RepCount [SetPW 24 PointStart Forward 0 PointEnd] ]
  PenUp Forward :Side/2 Left 90 Forward :Side/2     # r2c

To Even? :Num
  # return 'true' if Num even, else return 'false'
  If (Mod :Num 2)=0 [Output "True] [Output "False]

To Go
  New Perspective CS PenUp
  HideTurtle SetSC Black
  Cube 250 Wait 30
  Message [View3D?] View3D

Cube Oct
Cube Oct

Procedures blue
Variables pink
Comments green
Library gray