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


#define PI 3.14159265358979323
#define SCALE 50
#define SIZE 320
#define zoff 0.5773502691896257645091487805019574556
#define cylr 1.6329931618554520654648560498039275946
screenres SIZE, SIZE, 4
 
dim as double theta = 0.0, dtheta = 1.5, x(0 to 5), lasttime, dt = 1./30
 
dim as double cylphi(0 to 5) = {PI/6, 5*PI/6, 3*PI/2, 11*PI/6, PI/2, 7*PI/6}
 
sub drawcube( x() as double, colour as uinteger )
    for i as uinteger = 0 to 2
        line (SIZE/2, SIZE/2-SCALE/zoff) - (x(i), SIZE/2-SCALE*zoff), colour
        line (SIZE/2, SIZE/2+SCALE/zoff) - (x(5-i), SIZE/2+SCALE*zoff), colour
        line ( x(i), SIZE/2-SCALE*zoff ) - ( x(i mod 3 + 3), SIZE/2+SCALE*zoff ), colour
        line ( x(i), SIZE/2-SCALE*zoff ) - ( x((i+1) mod 3 + 3), SIZE/2+SCALE*zoff ), colour
    next i
end sub
 
while inkey=""
    lasttime = timer
    for i as uinteger = 0 to 5
        x(i) = SIZE/2 + SCALE*cylr*cos(cylphi(i)+theta)
    next i
    drawcube x(), 15
 
    while timer < lasttime + dt
    wend
    theta += dtheta*(timer-lasttime)
    drawcube x(),0
wend
end