Task
Draw a rotating cube.

It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional.




Related tasks
 Draw a cuboid
 write language name in 3D ASCII


node[][] = [ [ -1 -1 -1 ] [ -1 -1 1 ] [ -1 1 -1 ] [ -1 1 1 ] [ 1 -1 -1 ] [ 1 -1 1 ] [ 1 1 -1 ] [ 1 1 1 ] ]
edge[][] = [ [ 0 1 ] [ 1 3 ] [ 3 2 ] [ 2 0 ] [ 4 5 ] [ 5 7 ] [ 7 6 ] [ 6 4 ] [ 0 4 ] [ 1 5 ] [ 2 6 ] [ 3 7 ] ]
# 
func scale f . .
  for i range len node[][]
    for d range 3
      node[i][d] *= f
    .
  .
.
func rotate angx angy . .
  sinx = sin angx
  cosx = cos angx
  siny = sin angy
  cosy = cos angy
  for i range len node[][]
    x = node[i][0]
    z = node[i][2]
    node[i][0] = x * cosx - z * sinx
    y = node[i][1]
    z = z * cosx + x * sinx
    node[i][1] = y * cosy - z * siny
    node[i][2] = z * cosy + y * siny
  .
.
len nd[] 3
func draw . .
  clear
  m = 999
  mi = -1
  for i range len node[][]
    if node[i][2] < m
      m = node[i][2]
      mi = i
    .
  .
  ix = 0
  for i range len edge[][]
    if edge[i][0] = mi
      nd[ix] = edge[i][1]
      ix += 1
    elif edge[i][1] = mi
      nd[ix] = edge[i][0]
      ix += 1
    .
  .
  for ni range len nd[]
    for i range len edge[][]
      if edge[i][0] = nd[ni] or edge[i][1] = nd[ni]
        x1 = node[edge[i][0]][0]
        y1 = node[edge[i][0]][1]
        x2 = node[edge[i][1]][0]
        y2 = node[edge[i][1]][1]
        move x1 + 50 y1 + 50
        line x2 + 50 y2 + 50
      .
    .
  .
.
call scale 25
call rotate 45 atan sqrt 2
call draw
on animate
  call rotate 1 0
  call draw
.