'
'       Mirror Image Coded By Shockwave (C) 2002.
'       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' This Demo Combines Several Interesting Effects, All Of
' Which Are Reflected In The Bottom Portion Of The Screen.
' The Routines On Thier Own Are Standard Fayre, However
' When Combined Like This They Make For An Interesting
' Demonstration Of The Power Of PS2 Yabasic.
' Even if the demo is a bit standard and boring.
'
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

gosub initialise
gosub slapemin
bb=-5
setrgb 0,10,10,20
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Main Loop Begins;
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
repeat
   setdrawbuf bd
   bd=1-bd
   setdispbuf bd
   clear window
mm=mm+.1
setrgb 1,0,0,20
setrgb 2,0,0,40
setrgb 3,0,0,60
gtriangle 0,400 to 640,512 to 0,512
gtriangle 0,400 to 640,512 to 640,400
gosub rotate
gosub bouncers
gosub construct
gosub scroller
gosub logo
until (1=2)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Main Loop Has Ended OO;
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label bouncers
setrgb 1,50,10,120+40*sin(mm/2)
for a=1 to nd

fill triangle dx(a),dy(a)-10 to dx(a)-10,dy(a)+5 to dx(a)+10,dy(a)+5
fill triangle dx(a),dy(a)+10 to dx(a)-10,dy(a)-5 to dx(a)+10,dy(a)-5
next a
setrgb 1,25,25,60+20*sin(mm/2)
for a=1 to nd
fill triangle dx(a),(-dy(a)-10)+890 to dx(a)-10,(-dy(a)+5)+890 to dx(a)+10,(-dy(a)+5)+890
fill triangle dx(a),(-dy(a)+10)+890 to dx(a)-10,(-dy(a)-5)+890 to dx(a)+10,(-dy(a)-5)+890

 dy(a)=dy(a)+dg(a)
 dx(a)=dx(a)+dd(a)

 if dx(a)<0 or dx(a)>640 dd(a)=-dd(a)
 dg(a)=dg(a)+.5
if dy(a)+dg(a)>440 dg(a)=-dg(a)+.5
next a
return

label logo
setrgb 1,10,10,155+40*sin(mm)
    fill triangle 300,0 to 290,130 to 310,110
    fill triangle 290,70 to 350,20 to 330,50
    fill triangle 300,50 to 350,120 to 320,100
    fill triangle 360,20 to 370,120 to 390,90
    fill triangle 370,110 to 400,20 to 400,110
    fill triangle 420,20 to 380,120 to 410,100
    fill triangle 430,120 to 460,20 to 450,100
    fill triangle 440,70 to 490,60 to 480,80
    fill triangle 490,110 to 470,100 to 450,20
    fill triangle 500,20 to 520,30 to 530,120
    fill triangle 520,130 to 560,20 to 550,20
    fill triangle 550,80 to 630,50 to 635,60
    fill triangle 570,80 to 620,20 to 630,30
    fill triangle 575,65 to 635,120 to 630,100
    fill triangle 220,80 to 280,20 to 290,40
    fill triangle 225,60 to 280,110 to 260,120
    fill triangle 180,10 to 150,110 to 160,120
    fill triangle 170,10 to 200,110 to 210,130
    fill triangle 150,100 to 210,90 to 205,110
    fill triangle 89,20 to 80,120 to 99,110
    fill triangle 140,10 to 120,20 to 130,110
    fill triangle 80,70 to 140,60 to 145,70
    fill triangle 70,10 to 75,30 to 10,40
    fill triangle 10,35 to 70,80 to 75,120
    fill triangle 10,100 to 20,120 to 80,110
return

'---------------------------------------------------------
'                     Draw The Object;
'---------------------------------------------------------
label construct
  bb2=bb2+.1:rem                             THIS PART MAKES
  bn2=bn2+bb2:rem                             THE TEXT BOUNCE
  if bn2>5 bb2=-5:rem                        WITH GRAVITY

 xm=xm+xmf
 size=size+smf
if xm>640 or xm<0 xmf=-xmf
 if size>19 or size<12 smf=-smf
 f1=8:f2=4:f3=3
 gosub draw
  f1=12:f2=8:f3=3
  gosub draw
   f1=12:f2=13:f3=8
   gosub draw
    f1=13:f2=4:f3=8
    gosub draw
     f1=12:f2=3:f3=7
     gosub draw
      f1=3:f2=4:f3=5
      gosub draw
       f1=13:f2=9:f3=4
       gosub draw
      f1=4:f2=9:f3=1
      gosub draw
     f1=4:f2=1:f3=5
     gosub draw
    f1=3:f2=5:f3=2
    gosub draw
   f1=5:f2=1:f3=2
   gosub draw
  f1=7:f2=3:f3=2
  gosub draw
 f1=6:f2=2:f3=1
 gosub draw
f1=11:f2=7:f3=2
gosub draw
 f1=11:f2=2:f3=6
 gosub draw
  f1=10:f2=11:f3=6
  gosub draw
   f1=10:f2=6:f3=1
   gosub draw
    f1=9:f2=10:f3=1
    gosub draw
     f1=13:f2=10:f3=9
     gosub draw
     f1=12:f2=7:f3=11
     gosub draw
      f1=12:f2=11:f3=14
      gosub draw
       f1=13:f2=12:f3=14
       gosub draw
        f1=13:f2=14:f3=10
        gosub draw
          f1=14:f2=11:f3=10
          gosub draw
return

'---------------------------------------------------------
'         Calculate Cross product and draw face;
'---------------------------------------------------------

label draw
'##############################
'## Draw A Face Of The Ball! ##
'##############################
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)
  n=(vx1*vy2-vx2*vy1)
if n<0 then
light=abs(n/400)
setrgb 1,r+light,g+light,b+light
fill triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
setrgb 1,r,g,b+light
fill triangle tx(f1),(-ty(f1)/2)+600+(size*6) to tx(f2),(-ty(f2)/2)+600+(size*6) to tx(f3),(-ty(f3)/2)+600+(size*6)
setrgb 1,0,0,0
triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
triangle tx(f1),(-ty(f1)/2)+600+(size*6) to tx(f2),(-ty(f2)/2)+600+(size*6) to tx(f3),(-ty(f3)/2)+600+(size*6)
fi
return

'---------------------------------------------------------
'      Rotation and perspective transformations;
'---------------------------------------------------------
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/30)+1))+xm
  yy=size*(yy/((zz/30)+1))+ym+bn2
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
xr=xr+1
yr=yr+2
zr=zr+5
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720
return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Scrolling Message Subroutine;
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label scroller
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  bb=bb+.2:rem                             THIS PART MAKES
  bn=bn+bb:rem                             THE TEXT BOUNCE
  if bn>5 bb=-5:rem                        WITH GRAVITY
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   scrl=scrl-6:rem                  HERE, WE ARE ADDING AN
   if scrl<-164 then :rem           OFFSET TO THE TEMPLATE
    scrl=scrl+164:rem               TO MAKE THE TEXT MOVE
    p=p+10:rem                      SMOOTHLY IN STEPS OF
    if (p/10)>(length) p=0:rem   6 PIXELS.
   fi
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setrgb 1,155,155,255:rem         HERE WE DRAW THE STANDARD
 lf=0:rem                        RIGHT WAY UP SCROLL TEXT
 l=0:rem                         (ABOVE WATER)
for a=1 to 50 step 2
line txx(connects(p+a)+l)+scrl,tyy(connects(p+a)+l)+bn to txx(connects(p+a+1)+l)+scrl,tyy(connects(p+a+1)+l)+bn
lf=lf+1
if lf=5 then lf=0:l=l+9:fi
next a
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 setrgb 1,50,50,255-2*abs(bn+1):rem       NOW WE DRAW THE
 lf=0:rem                                 SQUASHED VERSION
 l=0:rem                                  (REFLECTION)
for a=1 to 50 step 2
line txx(connects(p+a)+l)+scrl,(-tyy(connects(p+a)+l)/2)+655-bn to txx(connects(p+a+1)+l)+scrl,-(tyy(connects(p+a+1)+l)/2)+655-bn
lf=lf+1
if lf=5 then lf=0:l=l+9:fi
next a
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Completely precalculate text into ASCII and Connections;
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label slapemin
setrgb 1,150,250,150
text 320,226,"CONVERTING SCROLL TO ASCII FORMAT","cc"
text 320,400,"MIRROR IMAGE (C) SHOCKWAVE 2002","cc"
'---------------------------------------------------------
'            Change string into ASCII format;
'--------------------------------------------------------
   mmm=0
target=len(s$)+1
   for a=1 to len(s$)
   letter=asc(mid$(s$,a,1))-48
   ostore(mmm)=(letter*10)
   if ostore(mmm)<0 ostore(mmm)=-1
   mmm=mmm+1
   width=(int((target-a)/len(s$)*100))*2
   rect 420,240 to 420-width,260
   next a
   p=p+1
   if p>len(s$)-5 p=0
clear window
'---------------------------------------------------------
'Take the offsets and build the connection data from them
'--------------------------------------------------------
setrgb 1,150,250,150
text 320,226,"CALCULATING SCROLL CONNECTIONS","cc"
text 320,400,"EMAIL: SHOCKWAVE@PS2-YABASIC.CO.UK","cc"

   os=1
   l=0
   for a=1 to len(s$) 
     for b=1 to 10
     connects(os)=fnt(ostore(a)+b)
     if ostore(a)<0 connects(os)=(1)
     os=os+1
     next b
 width=(int((target-a)/len(s$)*100))*2
 rect 420,240 to 420-width,260
   next a
flag=0
l=0
p=0
s$=""
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                FULLY INITIALISE PROGRAM;
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label initialise
open window 640,512
s$="      "
s$=s$+"WELCOME TO THE <MIRROR:IMAGE> DEMO     IT WAS "
s$=s$+"DESIGNED AND CODED BY <SHOCKWAVE> IN AUGUST 2002 "
s$=s$+"    IT IS FAIRLY STRAIGHT FORWARD BUT QUITE A "
s$=s$+"PRETTY DEMO NEVERTHLESS SO I HAVE DECIDED TO "
s$=s$+"RELEASE IT ; ; ; ANYWAY DUE TO THE NATURE OF THIS "
s$=s$+"SCROLL TEXT I CAN HAVE VIRTUALLY AS MUCH AS I LIKE"
s$=s$+" WITHOUT SLOWING THE PROGRAM DOWN SO YOU CAN "
s$=s$+"EXPECT THIS TO BE A LONG TEXT WITH LOADS OF "
s$=s$+"POINTLESS WAFFLE    IM IN THE MOOD TO TYPE AT THE "
s$=s$+"MOMENT YOU SEE      BUT WHAT TO TYPE???   OH DEAR "
s$=s$+"I DONT SEEM TO HAVE ANYTHING TO SAY NOW       BAH "
s$=s$+"    ILL JUST SAY THIS THEN    HELLO TO ALL WHO "
s$=s$+"KNOW ME      AND ERM    SEE YOU IN THE NEXT DEMO "
s$=s$+"  THERE THAT WILL HAVE TO DO     BYE        "

s$=s$+"      "
length=len(s$)-6
dim ostore(len(s$))
dim scx(45),scy(45),txx(45),tyy(45):rem   scroll template.
dim connects(10*len(s$)):Rem    This stores display lines.
dim fnt (430) :Rem   storage space for letter connections.

for a=1 to 45
read scx(a),scy(a)
next a
for a=1 to 45
  txx(a)=(55*scx(a))+540
  tyy(a)=(55*scy(a))+376
next a

for a=1 to 430
read fnt(a)
next a

polys=14 : Rem      The amount of points 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
 dim cs(720)
 dim sn(720)
 size=15
 xmf=5
 smf=.1
 xm=320
 ym=316
 for ang=0 to 720
  cs(ang)=cos(ang*(pi/360))
  sn(ang)=sin(ang*(pi/360))
 next ang
for a=1 to polys
 read x(a),y(a),z(a)
next a
r=0:g=5:b=20
nd=14
dim dx(nd),dy(nd),dg(nd),dd(nd)

for a=1 to nd
dx(a)=ran(640)
dy(a)=ran(300)
dd(a)=-5+ran(10)
if dd(a)=0 dd(a)=1
next a

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'The Scroling message template;
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data -10,-1,-9,-1,-8,-1,-10,0,-9,0,-8,0,-10,1,-9,1,-8,1
data  -7,-1,-6,-1,-5,-1,-7,0,-6,0,-5,0,-7,1,-6,1,-5,1
data -4,-1,-3,-1,-2,-1,-4,0,-3,0,-2,0,-4,1,-3,1,-2,1
data -1,-1,0,-1,1,-1,-1,0,0,0,1,0,-1,1,0,1,1,1
data 2,-1,3,-1,4,-1,2,0,3,0,4,0,2,1,3,1,4,1
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'The Font. (Each letter has five lines).
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'AscII map;
'48=0:49=1:50=2:51=3:52=4:53=5:54=6:55=7:56=8:57=9:58=:
'59=;:60=<:61==:62=>:63=?:64=@:65=A: to 90= Z:
'
'Font designed by shockwave. DO NOT RIP without credit!
'
'0 to 3
data 1,3,3,9,9,7,7,1,1,9
data 4,2,2,5,5,8,8,7,8,9
data 2,3,3,6,6,4,4,7,7,9
data 1,2,2,6,6,4,6,9,9,7
'4 to 7
data 1,4,4,5,5,2,5,8,5,6
data 2,1,1,4,4,6,6,9,9,7
data 3,1,1,7,7,9,9,6,6,4
data 1,3,3,6,6,4,6,8,8,6
'8 to 9,:,;
data 1,3,3,9,9,7,7,1,4,6
data 1,3,3,6,6,4,4,1,6,8
data 4,6,6,4,4,6,6,4,4,6 :rem colon gives -
data 2,8,4,6,1,9,3,7,4,6 :rem semicolon gives *
'< = > ? @
data 3,4,4,9,9,5,5,3,3,4
data 1,3,3,1,7,9,9,7,7,9
data 1,6,6,7,7,5,5,1,1,6
data 1,3,3,6,6,5,5,4,7,8
data 3,1,1,7,7,9,9,6,6,8
'A to D;
data 7,4,4,2,2,6,6,9,4,6
data 1,7,7,9,9,4,4,6,6,1
data 6,3,3,2,2,4,4,7,7,9
data 1,2,2,6,6,9,9,7,7,1
'E to H
data 3,2,2,4,4,6,4,7,7,9
data 3,2,2,4,4,6,4,7,4,7
data 3,4,4,7,7,9,9,6,6,5
data 1,7,4,6,3,9,4,6,4,6
'I to L
data 1,2,2,3,2,8,7,8,8,9
data 1,3,3,6,6,8,8,7,7,4
data 1,7,4,2,9,5,5,4,4,5
data 1,4,4,7,7,8,8,9,8,9
'M to P
data 1,3,3,9,1,7,2,5,5,2
data 7,4,4,1,1,5,5,9,9,3
data 1,3,3,9,9,7,7,1,1,3
data 7,4,4,1,1,3,3,6,6,4
'Q to T
data 1,3,3,9,9,7,7,1,9,5
data 1,2,2,6,6,4,4,9,1,7
data 3,1,1,4,4,6,6,9,9,7
data 1,3,3,1,2,5,5,8,8,2
'U to X
data 1,7,7,8,8,9,9,6,6,3
data 1,4,4,8,8,6,6,3,3,6
data 1,7,7,9,9,3,8,5,5,8
data 1,5,5,9,3,5,5,7,7,5
'Y to Z
data 1,4,4,6,6,3,6,9,9,7
data 1,2,2,3,3,7,7,8,8,9
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
data 5,-5,-5,5,5,-5,-5,5,-5,-5,-5,-5,0,0,-8,8,0,0,0,8,0,-8,0,0,0,-8,0,5,-5,5,5,5,5,-5,5,5,-5,-5,5,0,0,8

return



