Retrogamecoding(.org) > Examples

Rotating Cube

(1/1)

Rick3137:
Since Pulsar seems to lack a 3D system like opengl, I have become interested in pre-windows methods for faking 3D.
What I have so far is just simple Isometric drawing. I might not make it all the way to real 3d, but at least it is interesting.
The rotating cube idea would give me something to build a Rubik's Cubic on . I hope it is not too big a problem to solve.

--- Code: ---
-- Written by Rick3137.   Tested on Windows10
win = openwindow ("Start",-1,-1,1200,700)
setactivewindow (win)
backcolor (0,0,0,255)
cls()

sync()
x=0 ; y=0 ; f= 0 ; x1=0 ; y1 = 0 ; Ang = 0 ; r = 500
Pi = math.pi ; AngleS = Pi / 180 -- Angle Segment equal to 1.0 degrees
px = {0,0,0,0,0,0,0,0,0,0}    --  Point X
py = {0,0,0,0,0,0,0,0,0,0}    --  Point Y
Ang = { 0,0,0,0 }             -- Holds the 4 bottom cube angles
color (255,225,255,100)

--Ang1 moves from 0 to 200
local Angle = 0 ; a1 = Pi / 180 ; x2=0 ; y2=0 ; x3=400 ; y3 = 400
Ang[1] = Ang1
for a=0,360 do
Angle = a * AngleS
x2 = cos(Angle) * radius + cx
y2 = -.3 * sin(Angle) * radius + cy
--dot(x2,y2)
Ang[2] = Ang1 + 90 ; Ang[3] = Ang1 + 180 ; Ang[4] = Ang1 + 270
for b=1,4 do
if (Ang[b] > 360 ) then
Ang[b] = Ang[b] - 360
end
if (a == Ang[b] ) then      -- start at 45
px[b] =  x2  ; py[b] = y2
end
end

end
end

line( px[1], py[1], px[2], py[2] ) ;line( px[2], py[2], px[3], py[3] ) ;line( px[3], py[3], px[4], py[4] )
line( px[1], py[1], px[4], py[4] )
line( px[1], py[1], px[1], py[1] - radius ) ; line( px[2], py[2], px[2], py[2] - radius )
line( px[3], py[3], px[3], py[3] - radius ) ; line( px[4], py[4], px[4], py[4] - radius )

drawtext ( Ang1,0,30)
sync()
--wait( 100)
end

color (100,100,0,255)

a = 45 ; cnt = 0 ; key = 200
while key > 100 do
color (0,0,0,255)
--cls()
fillrectangle( 0,40,1000,700 )
color (255,255,255,255)
wait(5)
sync()
a = a + 1 ; cnt = cnt + 1
if (a>360) then
a = a - 360
end
key = getkey()
drawtext ("Press any key to exit ..",0,0)
sync()
end
sync()
closewindow(win)
closeapplication()

--- End code ---