Spin v1

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

Spin v1

Post by DrChip »

REM Spin v1
REM i didnt finish the tilt and touch, yet.
REM iPhone 6 Plud / iOS 8.2 b4
REM enjoy...



'Screen Area
scw = Screen_Width()
sch = Screen_Height()
csw = scw/2
csh = sch/2
graphics

GOSUB initialize

Loop:
refresh off
graphics clear 0,0,0
GOSUB Controlls
GOSUB background
IF c=0 THEN
mm=mm+.05
END IF
size=10+19*SIN(mm/2)
r=100
b=0
g=0
GOSUB rotate
GOSUB object
draw COLOR 0,0,0
refresh on
GOTO loop
END


Controlls:
IF AccelY <1 THEN
yr=yr-5
END IF
IF AccelY >1 THEN
yr=yr+5
END IF
IF AccelX >1 THEN
xr=xr+5
END IF
IF AccelX <1 THEN
xr=xr-5
END IF
IF AccelZ <1 THEN
zr=zr-5
END IF
IF AccelZ >1 THEN
zr=zr+5
END IF
IF Touch = 0 THEN
mm=mm+.1
END IF
IF Touch = 1 THEN
mm=mm-.1
END IF


IF xr<1 THEN
xr=xr+720
END IF
IF yr<1 THEN
yr=yr+720
END IF
IF zr<1 THEN
zr=zr+720
END IF

IF xr>720 THEN
xr=xr-720
END IF
IF yr>720 THEN
yr=yr-720
END IF
IF zr>720 THEN
zr=zr-720
END IF
RETURN


background:
ang=ang+1
lm=lm+.03
rd=40+40*SIN(lm)
gn=40+40*SIN(lm/4)
bl=40+40*SIN(lm/7)

IF ang>360 THEN
ang=ang-360
END IF
FOR a=0 TO 360 STEP 30
cv=20*SIN(a+ang*PI/180)

x1=(560*(SIN((ang+a)*PI/180)))
y1=(560*(COS((ang+a)*PI/180)))
x2=(560*(SIN((30+ang+a)*PI/180)))
y2=(560*(COS((30+ang+a)*PI/180)))

fill COLOR (cv+rd)/255,(cv+gn)/255,(cv+bl)/255
'TRIANGLE csw,csh, x1+csw,y1+csh, x2+csw,y2+csh
trix(0)=csw
triy(0)=csh
trix(1)=x1+csw
triy(1)=y1+csh
trix(2)=x2+csw
triy(2)=y2+csh
fill poly trix,triy count 3
'COLOR 0,0,0
'TRIANGLE x1+csw,y2+csh, x1+csw,y1+csh, x2+csw,y2+csh
trix(0)=x1+csw
triy(0)=y2+csh
trix(1)=x1+csw
triy(1)=y1+csh
trix(2)=x2+csw
triy(2)=y2+csh
fill poly trix,triy count 3
NEXT a

RETURN

object:
'insides
r=0
g=0
b=100
f1=1
f2=2
f3=3
f4=4
GOSUB quadb

f1=8
f2=7
f3=6
f4=5
GOSUB quadb
f1=8
f2=9
f3=4
f4=12
GOSUB quadb
f1=7
f2=12
f3=3
f4=11
GOSUB quadb
f1=6
f2=11
f3=2
f4=10
GOSUB quadb
f1=9
f2=5
f3=10
f4=1
GOSUB quadb
f1=1
f2=4
f3=9
GOSUB trib
f1=4
f2=3
f3=12
GOSUB trib
f1=9
f2=8
f3=5
GOSUB trib
f1=8
f2=12
f3=7
GOSUB trib
f1=3
f2=2
f3=11
GOSUB trib
f1=6
f2=7
f3=11
GOSUB trib
f1=2
f2=1
f3=10
GOSUB trib
f1=6
f2=10
f3=5
GOSUB trib
r=100
g=0
b=0
'Fronts
'f1=1
f2=2
f3=3
f4=4
'gosub quad
f1=8
f2=7
f3=6
f4=5
GOSUB quad
f1=8
f2=9
f3=4
f4=12
GOSUB quad
f1=7
f2=12
f3=3
f4=11
GOSUB quad
f1=6
f2=11
f3=2
f4=10
GOSUB quad
f1=9
f2=5
f3=10
f4=1
GOSUB quad
f1=1
f2=4
f3=9
GOSUB tri
f1=4
f2=3
f3=12
GOSUB tri
f1=9
f2=8
f3=5
GOSUB tri
f1=8
f2=12
f3=7
GOSUB tri
f1=3
f2=2
f3=11
GOSUB tri
f1=6
f2=7
f3=11
GOSUB tri
f1=2
f2=1
f3=10
GOSUB tri
f1=6
f2=10
f3=5
GOSUB tri
RETURN


tri:

'Draw Triangle Face (1 Triangle)

vx1= tx(f1)-tx(f2)
vy1= ty(f1)-ty(f2)
vx2= tx(f3)-tx(f2)
vy2= ty(f3)-ty(f2)
IF (vx1*vy2-vx2*vy1)<0 THEN
light=-(tz(f1)+tz(f2)+tz(f3))*10
fill COLOR r+light/255,g+light/255,b+light/255
'TRIANGLE tx(f1),ty(f1), tx(f2),ty(f2), tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix,triy count 3
draw COLOR 0,0,0
draw LINE tx(f1),ty(f1) to tx(f2),ty(f2)
draw LINE tx(f2),ty(f2) to tx(f3),ty(f3)
draw LINE tx(f3),ty(f3) to tx(f1),ty(f1)
END IF
RETURN
quad:

' Draw Quad Face (2 Triangles)
vx1= tx(f1)-tx(f2)
vy1= ty(f1)-ty(f2)
vx2= tx(f3)-tx(f2)
vy2= ty(f3)-ty(f2)
IF (vx1*vy2-vx2*vy1)<0 THEN
light=-(tz(f1)+tz(f2)+tz(f3))*10
fill COLOR r+light/255,g+light/255,b+light/255
'TRIANGLE tx(f1),ty(f1), tx(f2),ty(f2), tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix,triy count 3
'TRIANGLE tx(f1),ty(f1), tx(f4),ty(f4), tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f4)
triy(1)=ty(f4)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix,triy count 3
draw COLOR 0,0,0
draw LINE tx(f1),ty(f1) to tx(f2),ty(f2)
draw LINE tx(f2),ty(f2) to tx(f3),ty(f3)
draw LINE tx(f3),ty(f3) to tx(f4),ty(f4)
draw LINE tx(f4),ty(f4) to tx(f1),ty(f1)

END IF
RETURN

trib:

'Draw Triangle Face (1 Triangle)

vx1= tx(f1)-tx(f2)
vy1= ty(f1)-ty(f2)
vx2= tx(f3)-tx(f2)
vy2= ty(f3)-ty(f2)
IF (vx1*vy2-vx2*vy1)>0 THEN
light=-(tz(f1)+tz(f2)+tz(f3))*4
fill COLOR r+light/255,g+light/255,b+light/255
'TRIANGLE tx(f1),ty(f1), tx(f2),ty(f2), tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix,triy count 3
END IF
RETURN

quadb:

' Draw Quad Face (2 Triangles)
vx1= tx(f1)-tx(f2)
vy1= ty(f1)-ty(f2)
vx2= tx(f3)-tx(f2)
vy2= ty(f3)-ty(f2)
IF (vx1*vy2-vx2*vy1)>0 THEN
light=-(tz(f1)+tz(f2)+tz(f3))*4
fill COLOR r+light/255,g+light/255,b+light/255
'TRIANGLE tx(f1),ty(f1), tx(f2),ty(f2), tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f2)
triy(1)=ty(f2)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix,triy count 3
'TRIANGLE tx(f1),ty(f1), tx(f4),ty(f4), tx(f3),ty(f3)
trix(0)=tx(f1)
triy(0)=ty(f1)
trix(1)=tx(f4)
triy(1)=ty(f4)
trix(2)=tx(f3)
triy(2)=ty(f3)
fill poly trix,triy count 3
END IF
RETURN


rotate:

' Rotate And Scale Each Point Store Result

FOR a=1 TO polys
x1=x(a)
y1=y(a)
z1=z(a)

'X,Y,Z rotations!
xx=x1
yy=y1*cs(xr)+z1*sn(xr)
zz=z1*cs(xr)-y1*sn(xr)
y1=yy
x1=xx*cs(yr)-zz*sn(yr)
z1=xx*sn(yr)+zz*cs(yr)
zz=z1
xx=x1*cs(zr)-y1*sn(zr)
yy=x1*sn(zr)+y1*cs(zr)

' Apply Perspective!

xx=size*(xx/((zz/100)+1))+csw
yy=size*(yy/((zz/100)+1))+csh
tx(a)=xx
ty(a)=yy
tz(a)=zz
NEXT a
IF Touch=1 THEN
xr=xr+1
yr=yr+2
zr=zr+3
IF xr>720 THEN
xr=xr-720
END IF
IF yr>720 THEN
yr=yr-720
END IF
IF zr>720 THEN
zr=zr-720
END IF
END IF
RETURN

initialize:

' This Sub-Routine Initializes The Program.
pi=3.1415
'Define the necessary variables!
size=15 ' how big do you want it?
polys=12 ' The amount of polygons in the object
DIM x(polys+1) ' Original X co-ordinate store
DIM y(polys+1) ' Original Y co-ordinate store
DIM z(polys+1) ' Original Z co-ordinate store
DIM tx(polys+1) ' Transformed X co-ordinate store
DIM ty(polys+1) ' Transformed Y co-ordinate store
DIM tz(polys+1) ' Transformed Z co-ordinate store
p=0
scx=0


'Define Sine Tables!!

DIM cs(721)
DIM sn(721)
FOR ang=1 TO 720
cs(ang)=COS(ang*(PI/360))
sn(ang)=SIN(ang*(PI/360))
NEXT ang

' Read in the object!

FOR a=1 TO polys
READ x(a),y(a),z(a)
NEXT a
'The Object Description As Data!
'The Data Below Describes A Cube.
DATA 0,5,5,5,0,5,0,-5,5,-5,0,5
DATA 0,5,-5,5,0,-5,0,-5,-5,-5,0,-5
DATA -5,5,0,5,5,0,5,-5,0,-5,-5,0
RETURN
Attachments
image.jpg
image.jpg (109.52 KiB) Viewed 2030 times
image.jpg
image.jpg (119.41 KiB) Viewed 2030 times
image.jpg
image.jpg (107.19 KiB) Viewed 2030 times
image.jpg
image.jpg (148.3 KiB) Viewed 2030 times

Post Reply