'
'                 @@@@@@@@@@@@@@@@@@@@@@@
'                 @ -= STARCUBE DEMO =- @
'                 @   By Mr.Shockwave   @
'                 @@@@@@@@@@@@@@@@@@@@@@@
'
'#########################################################
setrgb 2,0,0,0
setrgb 3,0,0,0
gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'#######################################################
'## The Main Loop. These Calls Are Repeated Until (X) ##
'#######################################################
repeat
'####################################
'## Double buffer, draw background ##
'####################################
setdrawbuf dw
dw=1-dw
setdispbuf dw
setrgb 1,10,10,size*5
setrgb 2,10,size*5,10
setrgb 3,size*7,10,10
gtriangle 0,0 to 640,512 to 0,512
gtriangle 0,0 to 640,512 to 640,0

gosub rotate
gosub draw

'##############################
'## Display Text.. Do Scroll ##
'##############################
setrgb 1,70,50,70
fill rectangle 100,50 to 540,72
setrgb 1,0,0,0
text scx+2,492,mid$(s$,p,67)
text 103,66,"-= SHOCKWAVE PRESENTS: THE STARCUBE DEMO =-"
setrgb 1,255,155,255
text 101,64,"-= SHOCKWAVE PRESENTS: THE STARCUBE DEMO =-"
text scx,490,mid$(s$,p,67)
scx=scx-2
if scx<-10 then
scx=scx+10
p=p+1
if p>len(s$) p=0
fi

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

label draw
'########################
'## Draw The object!!! ##
'########################
b=1
mm=mm+.1
size=5+(3*sin(mm/10))
for a=1 to 42
z(a)=z(a)+4
if z(a)>50 z(a)=z(a)-100
sz=((80-tz(a))/10)+(size-5)
setrgb 1,30,sz*5,sz*10
fill rectangle tx(a),ty(a) to tx(a)+sz,ty(a)+sz
next a
setrgb 1,155,255,255
line tx(polys-7),ty(polys-7) to tx(polys-6),ty(polys-6)
line tx(polys-6),ty(polys-6) to tx(polys-5),ty(polys-5)
line tx(polys-5),ty(polys-5) to tx(polys-4),ty(polys-4)
line tx(polys-4),ty(polys-4) to tx(polys-7),ty(polys-7)

line tx(polys-3),ty(polys-3) to tx(polys-2),ty(polys-2)
line tx(polys-2),ty(polys-2) to tx(polys-1),ty(polys-1)
line tx(polys-1),ty(polys-1) to tx(polys),ty(polys)
line tx(polys),ty(polys) to tx(polys-3),ty(polys-3)

line tx(polys-7),ty(polys-7) to tx(polys-3),ty(polys-3)
line tx(polys-6),ty(polys-6) to tx(polys-2),ty(polys-2)
line tx(polys-5),ty(polys-5) to tx(polys-1),ty(polys-1)
line tx(polys-4),ty(polys-4) to tx(polys),ty(polys)

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/155)+1))+320
  yy=size*(yy/((zz/155)+1))+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
'##################################################
'## Rotation Incriments. Have a Play with these! ##
'##################################################
xr=xr+1 : rem X rotation per frame
yr=yr+1 : rem Y rotation per frame
zr=zr+2 : rem Z rotation per frame

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! ##
'#####################################
s$="                                                                   "
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
s$=s$+"Welcome to the   -= STARCUBE DEMO =-   Shockwave's"
s$=s$+" newest sample of graphical insanity made in "
s$=s$+"the YABASIC programming language.. I hope that "
s$=s$+"you enjoy it...   This is a different idea for a "
s$=s$+"starfield and it is very similar to an Amiga demo "
s$=s$+"I did a long time ago :o)    Not much to say this "
s$=s$+"time except that it's all real time (no cheating!)"
s$=s$+" and I want to say a quick hello to these people: "
s$=s$+" Adam lay.. Xalthorn.. Doctor.. Fryer.. Master "
s$=s$+"Tonberry.. Jinx.. Jacob Busby.. And all the "
s$=s$+"other forum users and website contributors at "
s$=s$+"WWW.YABASIC.CO.UK (The best Yabasic site around) "
s$=s$+"  If you are a coder then you can email: "
s$=s$+"Nicksimpson007@aol.com     That's all folks!!  "
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
p=0 :rem              Text pointer
scx=0 :rem            Scroll text scroll offset variable
dw=1 : Rem            Double buffering Variable
polys=58 : 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
'#####################################################
'## Generate star positions and Read in the object! ##
'#####################################################
for a=1 to polys
x(a)=-50+ran(100)
y(a)=-50+ran(100)
z(a)=-50+ran(100)
if a>50 then 
  read x(a),y(a),z(a)
end if
next a
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'Cube:(8 Points!)
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data -50,-50,-50,50,-50,-50,50,50,-50,-50,50,-50
data -50,-50,50,50,-50,50,50,50,50,-50,50,50
return


