space Voyage v3 fixed

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

space Voyage v3 fixed

Post by DrChip »

Code: Select all

REM
REM Space Voyage v3
REM It's not a big program but looks nice!
REM v2 - ported from my misoft code
REM v3 - fixed lighting and colors
REM please share. 
REM iPhone 6 plus / 8.3 b2
REM
REM Enjoy!

sw=SCREEN_WIDTH()
sh=SCREEN_HEIGHT()
csw=sw/2
csh=sh/2

GOSUB init

loop:
refresh off
graphics clear 0,0,0
draw COLOR 1,1,1
GOSUB rotate
FOR a=7 TO polys
    siz=6-(tz(a)/20)
    fill COLOR 0,0,(siz*30)/255
    fill RECT tx(a)-siz,ty(a)-siz to tx(a)+siz,ty(a)+siz
    fill COLOR 170/255,170/255,(siz*30)/255
    siz=siz-4
    fill RECT tx(a)-siz,ty(a)-siz to tx(a)+siz,ty(a)+siz
    y(a)=y(a)-2
    IF y(a)<-40 THEN
        y(a)=y(a)+80
    END IF 
NEXT a

burn=0
r=90
g=90
b=90
f1=1
f2=3
f3=5
GOSUB draw
f1=2
f2=1
f3=5
GOSUB draw
r=50
g=80
b=50
f1=1
f2=4
f3=3
GOSUB draw
f1=2
f2=4
f3=1
GOSUB draw
r=40
g=40
b=100
f1=4
f2=3
f3=6
GOSUB draw
f1=2
f2=4
f3=6
GOSUB draw
burn=1
fill COLOR (155+lol)/255,lol/255,lol/255
f1=3
f2=4
f3=5
GOSUB draw
fill COLOR (155+lol)/255,lol/255,lol/255
f1=4
f2=2
f3=5
GOSUB draw
lol=100*SIN(mm/4)
mm=mm+.5
draw COLOR 1,1,1
DRAW TEXT "Space Voyage " at 11,sh-19

draw COLOR 0,0,0
DRAW TEXT "Space Voyage " at 10,sh-20
refresh on 
GOTO loop

draw:
'Draw A Face Of The Cube!

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))*5
    
    IF burn=0 THEN
        fill COLOR (r+light)/255,(g+light)/255,(b+light)/255
    END IF 
    
    '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
    
    '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)
    draw 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!
    dv=(zz/50)+1
    xx=size*(xx/dv)+csw
    yy=size*(yy/dv)+csh
    tx(a)=xx
    ty(a)=yy
    tz(a)=zz
NEXT a
xr=xr+1
yr=yr+2
zr=zr+1
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

init:

'This Routine sets the program up.
'Open Gfx Screen
graphics
graphics clear 0,0,0

'Define the necessary variables!
str=41
size=15 ' how big do you want it?
polys=6+str 'The amount of polygons in the object
pi=3.1416 ' Pi
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
DIM trix(4), triy(4)
xr=1 ' x rotation
yr=2 ' y rotation
zr=3 ' z rotation 

'Define Sine Tables!! 
DIM cs(722)
DIM sn(722)
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
    x(a)=-30+RND(60)
    y(a)=-40+RND(80)
    z(a)=-30+RND(60)
NEXT a
FOR a=1 TO polys-str
    READ x(a),y(a),z(a)
NEXT a

'The Object Description As Data!
'The Data Below Describes A Cube.

DATA 0,10,0,10,-10,0,-10,-10,0
DATA 0,-12,5,0,-14,-5
DATA 0,0,2.3
RETURN
Attachments
image.jpg
image.jpg (91.67 KiB) Viewed 2806 times
image.jpg
image.jpg (109.15 KiB) Viewed 2806 times
image.jpg
image.jpg (103.09 KiB) Viewed 2806 times
image.jpg
image.jpg (99.6 KiB) Viewed 2806 times
image.jpg
image.jpg (97.81 KiB) Viewed 2806 times
image.jpg
image.jpg (95.91 KiB) Viewed 2806 times

Post Reply