Rotating Box

Post Reply
DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Rotating Box

Post by DrChip »

REM 3d rotating box
REM
REM iPhone 6 plus / 8.2 b5
pi=3.1415
graphics
DIM c(361), s(361)
DIM x(9), y(9), Z(9), x2(9), y2(9), Z2(9), x3(9), y3(9)

FOR i = 1 TO 360
c(i) = COS(i * PI/ 180)
s(i) = SIN(i * PI/ 180)
NEXT i
FOR i = 1 TO 8
READ x(i)
READ y(i)
READ Z(i)
NEXT i

phi = 1
theta = 1
xcenter = Screen_Width()/2
ycenter = Screen_Height()/2
zcenter = 256


main:
refresh off
graphics clear 0,0,0
GOSUB drawbox
refresh on
GOTO main

drawbox:

FOR i = 1 TO 8
x2(i) = -x(i) * s(theta) + y(i) * c(theta)
y2(i) = -x(i) * c(theta) * s(phi) - y(i) * s(theta) * s(phi) - Z(i) * c(phi) + p
Z2(i) = -x(i) * c(theta) * c(phi) - y(i) * s(theta) * c(phi) + Z(i) * s(phi)

x3(i) = 256 * (x2(i) / (Z2(i) + zcenter)) + xcenter
y3(i) = 256 * (y2(i) / (Z2(i) + zcenter)) + ycenter

fill CIRCLE x3(i), y3(i) size 10
NEXT i

draw line x3(1), y3(1) to x3(3), y3(3)
draw LINE x3(1), y3(1) to x3(4), y3(4)
draw line x3(1), y3(1) to x3(5), y3(5)

draw line x3(2), y3(2) to x3(3), y3(3)
draw line x3(2), y3(2) to x3(4), y3(4)
draw line x3(2), y3(2) to x3(6), y3(6)

draw line x3(7), y3(7) to x3(6), y3(6)
draw line x3(7), y3(7) to x3(3), y3(3)
draw line x3(7), y3(7) to x3(5), y3(5)

draw line x3(8), y3(8) to x3(5), y3(5)
draw line x3(8), y3(8) to x3(4), y3(4)
draw line x3(8), y3(8) to x3(6), y3(6)

phi = phi + 1
theta = theta + 1
IF phi > 360 THEN
phi = phi - 360
END IF
IF theta > 360 THEN
theta = theta - 360
END IF

'pause .1

RETURN
'GOTO loop

DATA 50,50,-50
DATA -50,-50,-50
DATA -50,50,-50
DATA 50,-50,-50

DATA 50,50,50
DATA -50,-50,50
DATA -50,50,50
DATA 50,-50,50
Attachments
image.jpg
image.jpg (93.58 KiB) Viewed 1953 times
image.jpg
image.jpg (96.17 KiB) Viewed 1953 times

Post Reply