'Customisable letter program.
'Use this if you want but leave my name in the credits.
'I developed this so I could use it as an alternative to
'having a readme file on the card when I posted it around.
'(C) Shockwave. 2002
'#########################################################

gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
repeat
setdrawbuf dw
dw=1-dw
setdispbuf dw
   setrgb 1,6,3,3
   setrgb 2,3,3,7
   setrgb 3,3,8,3
    gtriangle 0,0 to 640,512 to 0,512
    gtriangle 0,0 to 640,512 to 640,0
    setrgb 2,10,10,30
    setrgb 3,10,10,40

setrgb 1,150,250,200

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)=-1000+ran(2000)
 sy(a)=-1000+ran(2000)
 sz(a)=5
fi
next a



'gosub 
f1=9:f2=6:f3=2
gosub draw
f1=6:f2=10:f3=2
gosub draw
f1=10:f2=4:f3=2
gosub draw
f1=4:f2=7:f3=2
gosub draw
f1=7:f2=5:f3=2
gosub draw
f1=5:f2=8:f3=2
gosub draw
f1=8:f2=3:f3=2
gosub draw
f1=3:f2=9:f3=2
gosub draw
f3=9:f2=6:f1=1
gosub draw
f3=6:f2=10:f1=1
gosub draw
f3=10:f2=4:f1=1
gosub draw
f3=4:f2=7:f1=1
gosub draw
f3=7:f2=5:f1=1
gosub draw
f3=5:f2=8:f1=1
gosub draw
f3=8:f2=3:f1=1
gosub draw
f3=3:f2=9:f1=1
gosub draw
setrgb 1,50,50,120
f1=9:f2=6:f3=2
gosub draw2
f1=6:f2=10:f3=2
gosub draw2
f1=10:f2=4:f3=2
gosub draw2
f1=4:f2=7:f3=2
gosub draw2
f1=7:f2=5:f3=2
gosub draw2
f1=5:f2=8:f3=2
gosub draw2
f1=8:f2=3:f3=2
gosub draw2
f1=3:f2=9:f3=2
gosub draw2
f3=9:f2=6:f1=1
gosub draw2
f3=6:f2=10:f1=1
gosub draw2
f3=10:f2=4:f1=1
gosub draw2
f3=4:f2=7:f1=1
gosub draw2
f3=7:f2=5:f1=1
gosub draw2
f3=5:f2=8:f1=1
gosub draw2
f3=8:f2=3:f1=1
gosub draw2
f3=3:f2=9:f1=1
gosub draw2

    gosub rotate
setrgb 1,255,255,255
rect 100,100 to 540,440
text 320,30,title$,"cc"

text 320,500,"THIS PROGRAM IS (C) SHOCKWAVE 2002","cc"
gosub message 
if delay=0 gosub dpad
if delay>0 delay=delay-1
until (and(peek("port1"),16384)<>0)
exit

label dpad
c=peek("port1")
if c<>0 delay=20
if and (c,32)<>0 p=p+10
if and (c,128)<>0 p=p-10
if p>lines-9 p=lines-9
if p<1 p=1

return

label message
y=130

for a=p to p+9
text 320,y,m$(a),"cc"
y=y+32
next a

return

label draw
'##############################
'## Draw A Face Of The Cube! ##
'##############################
l=l+1
if l>5 l=4
  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))*l
setrgb 1,r+light,g+light,b+light
gtriangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
setrgb 1,r+30+light,g+30+light,b+30+light
triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
fi
return

label draw2
'##############################
'## 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
triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
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=size*(xx/((zz/50)+1))+320
  yy=size*(yy/((zz/50)+1))+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
xr=xr+3
yr=yr+2
zr=zr+1
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720
return
label initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' This Sub-Routine Initialises The Program.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'######################
'## Open Gfx Screen! ##
'######################
open window 640,512
'#####################################
'## Define the necessary variables! ##
'#####################################
size=26: rem how big do you want it?
dw=1 : Rem            Double buffering Variable
polys=10 : 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
str=17
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

r=10
g=10
b=40
'##########################
'## 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
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
title$="LETTER TO ??? DATED ?? OF ???"
p=1
lines =40
dim m$(lines)
 for a=1 to lines
  read m$(a)
 next a

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   The Object Description As Data!
'   The Data Below Describes A Cube.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data 0,0,10,0,0,-10
data -10,0,3,10,0,3,0,10,3,0,-10,3
data 7.5,7.5,3,-7.5,7.5,3
data -7.5,-7.5,3,7.5,-7.5,3
'Page 1
data "Page 1:"
data "Type your text in"
data "these data lines"
data "blah"
data "blah"
data "blah"
data "rhubarb"
data "rhubarb"
data "rhubarb"
data "Use Dpad to turn page.~>"
'Page 2
data "Page 2:"
data "Type your text in"
data "these data lines"
data "blah"
data "blah"
data "blah"
data "rhubarb"
data "rhubarb"
data "rhubarb"
data "<~Use Dpad to turn page.~>"
'Page 3
data "Page 3:"
data "Type your text in"
data "these data lines"
data "blah"
data "blah"
data "blah"
data "rhubarb"
data "rhubarb"
data "rhubarb"
data "<~Use Dpad to turn page.~>"
'Page 4
data "Page 4:"
data "Type your text in"
data "these data lines"
data "blah"
data "blah"
data "blah"
data "rhubarb"
data "rhubarb"
data "rhubarb"
data "<~Use Dpad to turn page."

return












