'                   **LAB STUDIO**
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@    Coded By Christopher Rankine (C) in 2002     @
'@-===============================================-@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

REM Lab Studio
REM Coded by Christopher Rankine
REM A 2002 Lab Production
REM Completed on 10/6/02
REM Number of lines: 500
REM Check out yabasic.co.uk , yabasic.150m.com and
REM ps2-yabasic.co.uk for further yabasic code
REM Hi and thanks to Nick Simpson and Marc Gale

gosub setup
gosub main_loop
exit

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Set up title screen          >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label main_loop
repeat
c=peek("port1")
gosub tex
if and(c,8192)>0 gosub loop
until (and(c,1)>0)
return

label tex
gosub intro_text
repeat
c=peek("port1")
if and(c,8192)>0 then
pause .5
close window
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label intro_text
open window 640,512
repeat
setdrawbuf d
d=1-d
setdispbuf d
c=peek("port1")
mm=mm+.02
red=100*sin(mm)
grn=100*sin(mm/2)
blu=100*sin(mm/3)
setrgb 1,red,0,0
setrgb 2,0,grn,0
setrgb 3,0,0,blu
gtriangle 0,0 to 640,512 to 0,512
gtriangle 0,0 to 640,512 to 640,0
rem setrgb 1,red*2,grn*3,blu*2
setrgb 1,255,255,255    
    text 250-5+ran(5),200-2+ran(4),"L-A-B S-T-U-D-I-O"
    text 225-5,220-2+ran(4),"======================"
    text 195-5,250-2+ran(4),"Coded by Christopher Rankine"
    text 255-5,290-2+ran(4),"PRESS O TO START"
    text 255-5,310-2+ran(4),"================"
until (and(c,8192)>0)
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> SETUP VARIABLES AND ARRAYS   >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label setup
nstar=80 :rem      Number of stars to draw.
sncnt=5 :rem        Changes shape of snake. 
bobs=70 :rem        Number of bits in snake.
dim a(nstar):rem    Star X co-ordinate storage.
dim b(nstar):rem    Star Y Co-ordinate storage.
dim c(nstar):rem    Star Z Co-ordinate storage.
mm=0.0 : rem        This variable is used throughout.
for a=1 to nstar
  a(a)=-25+ran(50) : rem Make X star positions.
  b(a)=-25+ran(50) : rem Make Y star positions.
  c(a)=mm          : rem Make Z position.
mm=mm+100/nstar : rem    Space stars evenly.
next a
size=8 :rem size of cube
polys=8 
dim x(polys)
dim y(polys)
dim z(polys)
dim tx(polys)
dim ty(polys)
dim tz(polys)

REM SIN/COS LOOK UP 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

for a = 1 to polys
read x(a),y(a),z(a)
next a

REM DATA FOR 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

dem=1 :rem start with demo 1
timer=350 :rem When timer = 0 demos change 
REM SCROLL TEXT
s$="                                                                 "
s$=s$+"Welcome to my first demo!!! Being a games " 
s$=s$+"programmer, I haven't attempted a demo before....."
s$=s$+"......The demo consists of a 3D starfield, a "
s$=s$+"zooming logo, two snake effects and a nice "
s$=s$+"3D cube. Special thanks to my good friend Nick "
s$=s$+"Simpson whose help has been "
s$=s$+"invaluable in the making of this demo and other "
s$=s$+"projects. Ta mate............"
s$=s$+"........Hello to all the members of the forums at "
s$=s$+"yabasic.co.uk. Special handshakes to: Marc Gale "
s$=s$+"(aka Xalthorn) for his great site - "
s$=s$+"www.ps2-yabasic.co.uk and for all the help this "
s$=s$+"great programmer has given me.........Fryer "
s$=s$+"whose code amazes me......Jimshaw, thanks for the "
s$=s$+"emulator and all the brilliant demos......Hi also "
s$=s$+"to Jo, Snakedogg and Demoneye - keep up the "
s$=s$+"great work in the forums and at coding............"
s$=s$+"Hi to Zingy and everyone at gamevine.net.........."
s$=s$+"Jinx and        , it is great to see you both "
s$=s$+"back. I Look forward to seeing your future "
s$=s$+"programs......I had better shut up now as this is "
s$=s$+"getting rather long now....Till the next time "
s$=s$+"enjoy the demo and happy programming!!!..........."
p=0
sxc=0 
ox=365 : rem           The X offset for the logo    
oy=256 : rem           The Y offset for the logo 
poly=21 : rem         Amount of triangles in the logo
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Define storage for logo data >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
dim lx(poly*3),ly(poly*3)
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Define Storage for transformed logo data >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
dim lxt(poly*3),lyt(poly*3)
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Read logo in from data statements >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for a=1 to poly*3
read lx(a),ly(a)
next a
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> MAIN DEMO LOOP               >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label loop
open window 640,512
repeat
c=peek("port1")
setdrawbuf d
d=1-d
setdispbuf d
clear window
gosub n
gosub dispstars
gosub bk
gosub select
gosub scroller
until (and(c,1)>0)
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> SWITCH BETWEEN DEMOS         >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label select 
timer=timer-1
if timer=0 then
timer=350
dem=dem+1
fi
if timer=1 then
if dem=4 then
sncnt=sncnt+5
fi
fi
if dem>4 dem=1
if dem=1 then
gosub drawlogo
fi
if dem=2 then
gosub snake1
fi
if dem=3 then
gosub rotate
gosub set
fi
if dem=4 then
gosub snake2
fi
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>       EFFECTS IN EVERY DEMO       >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

REM BACKGROUND COLOURS
label n
ran_num=ran(1000)
if ran_num<10 then
rad=250
gad=250
bad=250
fi
if rad>0 then
rad=rad-10
gad=gad-10
bad=bad-10
fi
if rad<0 rad=0
if gad<0 gad=0
if bad<0 bad=0
red=100*sin(mm)
grn=100*sin(mm/2)
blu=100*sin(mm/3)
setrgb 1,red+rad,0,0
setrgb 2,0,grn+gad,0
setrgb 3,0,0,blu+bad
gtriangle 0,0 to 640,512 to 0,512
gtriangle 0,0 to 640,512 to 640,0
return

REM FLASH FOR BETWEEN DEMOS
label bk
lad=lad-10
if lad<0 lad=0
if timer=1 then
lad=100 
fi
if lad=100 then 
nx=1+ran(640)
nx2=1+ran(640)
fi
x=nx
x2=nx2
if lad>60 then
setrgb 1,255,255,255
for y=-40 to 512 step 20
fill rect 0,0 to 640,512
x=x2
x2=x2-40+ran(80)
next y
fi
return

REM STARFIELD
label dispstars
'#########################
'## Draws the starfield ##
'#########################
for a=1 to nstar
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Perspective calculation and centre screen position >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     xx=((a(a)*25)/c(a)*25)+320
     yy=((b(a)*25)/c(a)*25)+250
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Colour and draw the star >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     setrgb 1,0,0,120-c(a)
     fill rectangle xx-2,yy-2 to xx+6,yy+6
     setrgb 1,0,110-c(a),130-c(a)
     fill rectangle xx,yy to xx+4,yy+4
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Move Star Reset And generate new point if needed >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     c(a)=c(a)-1
     if c(a)<0 then
       a(a)=-25+ran(50)
       b(a)=-25+ran(50)
       c(a)=c(a)+100 
     fi
next a
return

REM SET UP SCROLL TEXT
label scroller
mm=mm+0.1
setrgb 1,255,255,0
text scx,scy, mid$(s$,p,67)
if dem=3 then
scx=scx-0.5
scy=480+(25*sin(mm/2))
else
scx=scx-2
scy=480+(25*sin(mm))
fi
if scx<-10 then
scx=scx+10
p=p+1
if p>len(s$) p=0
fi
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>         EFFECTS IN DEMO 1         >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
label drawlogo
'###########################
'## Draw the Zooming logo ##
'###########################
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Set colour of logo according to size >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  siz=(6*sin(mm/2))+6
  setrgb 1,10,10,(10*siz)+100
  Setrgb 2,0,0,0
  Setrgb 3,0,0,0
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>> Scale the logo according to size and centralise it >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for a=1 to poly*3
   lxt(a)=(lx(a)*(siz/1.5))+ox
   lyt(a)=(ly(a)*(siz/1.5))+oy
next a
'>>>>>>>>>>>>>>>>>>>
'>> Draw the logo >>
'>>>>>>>>>>>>>>>>>>>
for a=1 to poly*3 step 3
 Gtriangle lxt(a),lyt(a) to lxt(a+1),lyt(a+1) to lxt(a+2),lyt(a+2)
next a
return

REM L 
data -18,0,-25,0,-25,-20
data -25,-2,-25,5,-10,-4

REM A
data -10,-2,-8,-1,-5,-20
data -7,-20,1,-4,-3,-2
data -12,-7,1,-9,-1,-11

REM B
data 5,-10,5,-20,20,-15
data 5,0,5,-10,20,-5

REM S
data -45,10,-30,5,-30,10
data -45,10,-30,20,-28,25
data -28,20,-28,25,-45,30

REM T
data -30,11,-18,5,-23,9
data -24,4,-24,23,-20,17

REM U
data -15,5,-10,5,-10,20
data -10,20,0,5,-5,5

REM D
data -1,18,5,20,5,0
data -1,18,1,24,13,10
data 13,12,1,0,-1,2

REM I
data 15,5,20,5,15,30

REM O
data 20,18,22,19,25,0
data 23,0,29,16,27,18
data 18,18,31,16,29,14

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>         EFFECTS IN DEMO 2         >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

REM SNAKE EFFECT
label snake1
if sncnt>15 sncnt=5
l=200*sin(b/8)
m=200*cos(b/7)
for a = 1 to bobs
s=320+l*sin((b+a)/sncnt)
t=250+m*sin((b+a)/20)
setrgb 1,0,0,55
fill rect s,t to s+40,t+40
setrgb 1,75,55,255
fill rect s+4,t+4 to s+36,t+36
setrgb 1,0,0,0
fill rect s+8,t+8 to s+32,t+32
next a
b=b+.5
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>         EFFECTS IN DEMO 3         >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

REM SET UP FACES AND COLOURS
label set
r=0 : g=0 : b=200*sin(mm/6)
f1=1 : f2=2 : f3=3 : f4=4
gosub draw

r=0 : g=200*sin(mm/4) : b=0
f1=5 : f2=8 : f3=7 : f4=6
gosub draw

r=200*sin(mm/2) : g=0 : b=0
f1=6 : f2=2 : f3=1 : f4=5
gosub draw

r=0 : g=200*sin(mm/4) : b=200*sin(mm/6)
f1=8 : f2=4 : f3=3 : f4=7
gosub draw

r=200*sin(mm/2) : g=200*sin(mm/4) : b=0
f1=2 : f2=6 : f3=7 : f4=3
gosub draw

r=200*sin(mm/2) : g=200*sin(mm/4) : b=200*sin(mm/6)
f1=8 : f2=5 : f3=1 : f4=4
gosub draw
return

REM DRAW FACES
label draw
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
setrgb 1,r+rad,g+gad,b+bad
gtriangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
gtriangle tx(f1),ty(f1) to tx(f4),ty(f4) to tx(f3),ty(f3)
fi
return

REM ROTATE CUBE
label rotate
for a = 1 to polys
x1=x(a)
y1=y(a)
z1=z(a)

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)

xx=size*(xx/((zz/50)+1))+340
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+5
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720
return

'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>         EFFECTS IN DEMO 4         >>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

label snake2
if sncnt>15 sncnt=5
l=200*sin(b/8)
m=200*cos(b/7)
for a = 1 to bobs
s=320+l*sin((b+a)/20)
t=250+m*sin((b+a)/sncnt)
setrgb 1,0,0,55
fill rect s,t to s+40,t+40
setrgb 1,75,55,255
fill rect s+4,t+4 to s+36,t+36
setrgb 1,ran(200),ran(200),ran(200)
fill rect s+8,t+8 to s+32,t+32
next a
b=b+.5
return







