'Double Trouble By Shockwave.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'Grid idea from parabellum's 40 line sine scroll demo.
'Thanks for the inspiration, here's the result.
'
'Greets to all who know me!
'
'#########################################################

gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
setrgb 0,10,20,10
repeat
setdrawbuf dw
dw=1-dw
setdispbuf dw
setrgb 1,10,40,10
setrgb 2,10,40,10
setrgb 3,5,5,40
wsv=wsv+3
x1=(560*sin(wsv*pi/180))+320
y1=(560*cos(wsv*pi/180))+256
x2=(560*sin((wsv+90)*pi/180))+320
y2=(560*cos((wsv+90)*pi/180))+256
x3=(560*sin((wsv+180)*pi/180))+320
y3=(560*cos((wsv+180)*pi/180))+256
x4=(560*sin((wsv+270)*pi/180))+320
y4=(560*cos((wsv+270)*pi/180))+256


gtriangle x1,y1 to x3,y3 to x4,y4
gtriangle x1,y1 to x3,y3 to x2,y2
setrgb 1,130,255,130
for a=1 to str
 tx=(sx(a)/sz(a))+320
 ty=(sy(a)/sz(a))+256
 siz=6-sz(a)
sz(a)=sz(a)-.04
 fill rect tx,ty to tx+siz,ty+siz
if (tx<0) or (tx>640) or (ty<0) or (ty>512) then
 sx(a)=-1500+ran(3000)
 sy(a)=-1500+ran(3000)
 sz(a)=5
fi
next a

    mm=mm+1

zo1=18*sin((mm*pi/180))
zo2=18*sin(((mm+180)*pi/180))
if zo1>=zo2 then gosub 1:gosub 2:fi
if zo2>zo1 then gosub 2:gosub 1:fi

size=5+4*sin(mm/52)

xr=xr+2
yr=yr+4
zr=zr+1
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720

gosub grid

text 321,257,"DOUBLE TROUBLE BY SHOCKWAVE","cc"
setrgb 1,255,255,255
text 320,256,"DOUBLE TROUBLE BY SHOCKWAVE","cc"

until (and(peek("port1"),16384)<>0)
exit

label grid
for a=0 to 640 step 8
fill rect a,0 to a+3,512
next a
for a=0 to 512 step 8
fill rect 0,a to 640,a+3
next a
return

label 1
xo=24*sin(mm*pi/180)
yo=24*sin(mm*pi/180)
zo=28*sin(mm*pi/180)

    r=0:g=0:b=50
    gosub rotate
    f1=1 : f2=2 : f3=3 : f4=4
    gosub draw
    f1=5 : f2=8 : f3=7 : f4=6
    gosub draw
    f1=6 : f2=2 : f3=1 : f4=5
    gosub draw
    f1=8 : f2=4 : f3=3 : f4=7
    gosub draw
    f1=2 : f2=6 : f3=7 : f4=3
    gosub draw
    f1=8 : f2=5 : f3=1 : f4=4
    gosub draw
return
label 2
xo=24*cos(mm*pi/180)
yo=24*cos(mm*pi/180)
zo=28*sin((mm+180)*pi/180)


    r=50:g=0:b=0
    gosub rotate
    f1=1 : f2=2 : f3=3 : f4=4
    gosub draw
    f1=5 : f2=8 : f3=7 : f4=6
    gosub draw
    f1=6 : f2=2 : f3=1 : f4=5
    gosub draw
    f1=8 : f2=4 : f3=3 : f4=7
    gosub draw
    f1=2 : f2=6 : f3=7 : f4=3
    gosub draw
    f1=8 : f2=5 : f3=1 : f4=4
    gosub draw
return
label 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)
  normal=(vx1*vy2-vx2*vy1)
  if  normal<0 then
normal=normal/200
'light=((abs(normal))/100)+100
light=abs(normal)
xc=(tx(f1)+tx(f2)+tx(f3)+tx(f4))/4
yc=(ty(f1)+ty(f2)+ty(f3)+ty(f4))/4
setrgb 1,r+light,g+light,b+light
fill triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
fill triangle tx(f1),ty(f1) to tx(f4),ty(f4) to tx(f3),ty(f3)
setrgb 1,0,0,0
line tx(f1),ty(f1) to tx(f2),ty(f2)
line tx(f2),ty(f2) to tx(f3),ty(f3)
line tx(f3),ty(f3) to tx(f4),ty(f4)
line tx(f4),ty(f4) to tx(f1),ty(f1)

fi
return


label 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=xx+xo
yy=yy+yo
zz=zz+zo
  xx=size*(xx/((zz/50)+1))+320
  yy=size*(yy/((zz/50)+1))+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a

return
label initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' This Sub-Routine Initialises The Program.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'######################
'## Open Gfx Screen! ##
'######################
open window 640,512
'#####################################
'## Define the necessary variables! ##
'#####################################
size=4: rem how big do you want it?
dw=1 : Rem            Double buffering Variable
polys=8 : Rem        The amount of polygons in the object
dim x(polys) : Rem  Original X co-ordinate store
dim y(polys) : Rem  Original Y co-ordinate store
dim z(polys) : Rem  Original Z co-ordinate store
dim tx(polys) : Rem Transformed  X co-ordinate store
dim ty(polys) : Rem Transformed Y co-ordinate store
dim tz(polys) : Rem Transformed Z co-ordinate store
'##########################
'## Define Sine Tables!! ##
'##########################
 dim cs(720)
 dim sn(720)
 for ang=0 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
str=45
dim sx(str),sy(str),sz(str)

for a=1 to str
 sx(a)=-1000+ran(2000)
 sy(a)=-1000+ran(2000)
 sz(a)=ran(5)
next a

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   The Object Description As Data!
'   The Data Below Describes A Cube.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data -10,10,10,10,10,10,10,-10,10,-10,-10,10
data -10,10,-10,10,10,-10,10,-10,-10,-10,-10,-10
return













