' The Funky Scroll Demo Coded By Shockwave (C) 2002 (C).
' It gets kind of cute so make sure that you watch the
' demo through as several effects get added as the demo 
' progresses. 
'
' If you pilfer my code or steal my ideas, credit please,
' all I ask is that you acknowledge where you got the code
' or the idea.
'
' Kyata, don't you DARE tell your friends that you coded
' this demo. Grrr....
'
' Many thanks, contact me at: Shockwave@ps2-yabasic.co.uk
'
'#########################################################
gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                    Main Loop Begins;
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
repeat
'---------------------------------------------------------
'                 Buffers and background
'---------------------------------------------------------
setdrawbuf dw
dw=1-dw
setdispbuf dw
clear window
sv=sv+.1
f=100*sin(sv)
'---------------------------------------------------------
'                       Sub Calls
'---------------------------------------------------------
if scroll=-5 gosub event
if flag=1 gosub slapemin
    gosub rotate
    gosub scroll
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@Remove rem statements (')to see debug mode;@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'setrgb 1,50,90,50
' text 40,20,"POSITION IN TEXT:"+str$(p)
' text 40,40,"   X ORIENTATION:"+str$(xr/2)
' text 40,60,"   Y ORIENTATION:"+str$(yr/2)
' text 40,80,"   Z ORIENTATION:"+str$(zr/2)
' text 40,100,"  X ROT ADDITION:"+str$(xrot/2)
' text 40,120,"  Y ROT ADDITION:"+str$(yrot/2)
' text 40,140,"  Z ROT ADDITION:"+str$(zrot/2)
'
'setrgb 1,90,20,20
'
' for a=1 to 45
' rect tx(a)-3,ty(a)-3 to tx(a)+3,ty(a)+3
' next a
'@@@@@@@@@@@@@@@@@@@@
'@@@End Debug Code@@@
'@@@@@@@@@@@@@@@@@@@@

until (peek("port1")<>0)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                      Main Loop Ends.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

exit

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'This Sub Looks At The Text Pointer And Triggers Scroll
'Events By Changing The Settings.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label event
  if p=1 then
  xr=0:yr=0:zr=0:xrot=0:yrot=0:zrot=0
  fi
if p=69 zrot=5
   if p=75 then
   xr=50:yr=140:zr=80:xrot=0:yrot=0:zrot=0
   fi
if p=89 zrot=2
if p=120 zrot=9
    if p=127 then
    xrot=1:yrot=0:zrot=2
    fi
     if p=191 then
     xrot=2:yrot=3:zrot=3
     fi

      if p=334 then
      xr=110:yr=0:zr=40
      xrot=0:yrot=2:zrot=0
      fi
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'The sub below gets five letters, converts them into ascii
'then links this to the link data and then places the new
'link data into the scrolltext template to be drawn in
'between the template dots.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label slapemin
'---------------------------------------------------------
'  Grab 5 letters from s$ and convert them to offsets;
'---------------------------------------------------------
   mm=0
   for a=p to p+5
   letter=asc(mid$(s$,a,1))-48
   ostore(mm)=(letter*10)
   if ostore(mm)<0 ostore(mm)=-1
   mm=mm+1
   next a
   p=p+1
   if p>len(s$)-5 p=0
'---------------------------------------------------------
'Take the offsets and build the connection data from them
'---------------------------------------------------------
   os=1
   l=0
   for a=1 to 5 
   for b=1 to 10
   connects(os)=fnt(ostore(a)+b)+l
   if ostore(a)<0 connects(os)=(1)
   os=os+1
   next b
   l=l+9
   next a
flag=0
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Scroll the text, reset if done, draw scroll flag letters.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label scroll
   scroll=scroll-.5
   if scroll<-11.5 then
   scroll=0
   flag=1
   fi

setrgb 1,155+f,155+f,255
for a=1 to 50 step 2
line tx(connects(a)),ty(connects(a)) to tx(connects(a+1)),ty(connects(a+1))
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'         Rotate Scrolltext template vertices.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label rotate
'###############################################
'## Rotate And Scale Each Point! Store Result ##
'###############################################
 for a=1 to polys
  x1=x(a)+scroll
  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)+320
  yy=size*(yy/dv)+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
xr=xr+xrot
yr=yr+yrot
zr=zr+zrot
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720
return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' This Sub-Routine Initialises The Program.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
label initialise
'Allowed Characters; (MUST BE IN UPPER CASE (CAPS ON ))
'"space" 0,1,2,3,4,5,6,7,8,9,:,;,<,=,>,?,@,A,B,C,D,E,F,G
',H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
'USING COLON GIVES YOU -
'USING SEMI COLON GIVES YOU *

s$="     ;;SHOCKWAVE IS BACK;;     "
s$=s$+"BUT WHAT IS THIS THING? DOESNT LOOK 2 GOOD      "
s$=s$+"OH SORRY ::: DIDNT I MENTION THAT IT DID TRICKS? "
s$=s$+"    ONCE AGAIN SHOCKWAVE IS THE PIONEER OF A ;NEW;"
s$=s$+" YABASIC IDEA      "
s$=s$+"ITS A LITTLE HARD TO READ THOUGH SO LETS EASE OFF"
s$=s$+" A LITLE BIT SO I CAN GREET SOME OF MY FRIENDS "
s$=s$+"AND ACQUAINTANCES FROM THE YABASIC SCENE      "
s$=s$+"THATS BETTER     SO IN RANDOM ORDER HANDSHAKES "
s$=s$+"GO OUT TO THESE FINE PEOPLE ::: :XALTHORN:DOCTOR:"
s$=s$+"DREW001001:JACOB BUSBY:JINX:JIM SHAW:SNAKEDOGG:"
s$=s$+"DEMONEYE:JOMORROW:KYATAVL:ASIV:LIQUID:PS2YABASIC:"
s$=s$+":GOTHI:MASTER TONBERRY:ZINGSTER:YALOOPY:FRYER:"
s$=s$+"AND EVERYONE ELSE WHO I HAVE TEMPORARILY FORGOTTEN"
s$=s$+":  IF YOU ARE MISSING FROM MY LIST THEN YOU SHOULD"
s$=s$+" TRY POSTING MORE:: YOU CAN MAIL ME ON   "
s$=s$+"SHOCKWAVE@PS2:YABASIC;CO;UK  <THE STARS ARE DOTS> "
s$=s$+"  ANYWAY, THATS QUITE ENOUGH WAFFLE FOR ONE DAY "
s$=s$+"SEE YOU IN THE NEXT ONE <C>SHOCKWAVE<C> 2002 "
s$=s$+"     "

'######################
'## Open Gfx Screen! ##
'######################
?   :?    :?   "LAMERS LEAVE THIS ALONE (C) Shockwave 2002":polys=45:rem         maximum amount of template points.
open window 640,512
'#####################################
'## Define the necessary variables! ##
'#####################################
dim ostore(5)

size=15: rem how big do you want it?
dw=1 : Rem            Double buffering Variable
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 connects(50):Rem This stores the scroll display lines.
dim fnt (430) :Rem  storage space for letter connections.
'##########################
'## 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)
 x(a)=x(a)
 z(a)=0
 y(a)=y(a)*6
 x(a)=(x(a)+3)*4
next a
for a=1 to 430
read fnt(a)
next a
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'Scrolltext Template Design; (x and y data).
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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:
'
'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
return


