'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Clever Dotcube Demo coded by Shockwave (C) Aug 2001
'  ---------------------------------------------------
'You'll NEVER figure out how this was done without looking
'at the source code!! HeHeHe!!
'and it's not pre-calculated.. but heres a clue, I'm only
'rotating 8 of the 98 points in the object?!?!? hahaha!
'
'Ok, I'll tell ya! a cube has eight corners... each face
'has four corners.. Look at the diagram:
'
'  <1>  f  (A)  g  <2>   the * represent dots on the
'   *   *   *   *   *    face of this 5*5 dotcube face.
'   h   i   j   k   l    <N> numbers in these brackets
'   *   *   *   *   *    correspond to the points being
'  (D)  m  (B)  n  (E)   rotated (vertices), (A) letters
'   *   *   *   *   *    in these brackets correspond to
'   o   p   q   r   s    points genetated by adding 2
'   *   *   *   *   *    vertices together and dividing
'  <4>  t  (C)  u  <3>   by 2 to get a middle point, The 
'   *   *   *   *   *    location of these is therefore
' not calculated by the 3d routine, but they are stored
' to help generate some of the other points f for example 
' is a result of <1> / (A), these points are not stored. 
' the program passes 4 corners of a cube to the routine, 
' and the routine calculates the face like that!
' good eh?!?! This means that ONLY the corners are 
' actually being rotated.. (it would be impossible to do
' 98 points scaled and rotated as quick as this does).
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

open window 400,400

'>>> Scroll text:

t$="                                                                   "
t$=t$+"This doesn't look possible, and it's not!! Ho Ho! "
t$=t$+"Granted, this isn't the best designed demo I've "
t$=t$+"ever done, but for the sheer amount of effects in "
t$=t$+"full frame rate, this is special.. Here's what you"
t$=t$+" are looking at: A dotcube scaled and rotated with"
t$=t$+" 98 dots in realtime, a realtime zoomed logo, "
t$=t$+"plasma, a scroll and a 35 point starfield all "
t$=t$+"happening at once and with no precalculation at "
t$=t$+"full frame rate!!! TOP THAT!!  If you want to "
t$=t$+"know how it was done, go to www.yabasic.co.uk "
t$=t$+"or e-mail me at Nicksimpson007@aol.com...  "
t$=t$+"greetings to all who know me... bye bye!!!"

ds=5
pn=0
lxo=340
lyo=100
poll=18
   dim logx(poll*3)
   dim logy(poll*3)
for a=1 to poll*3
   read logx(a),logy(a)
logx(a)=logx(a)*2
next a

'## Number of faces in object:
polys=8
'## X and Y screen offset positions to centre object:
xff=325
yff=255

' ## X+Y rotation values!

rotx=0.012
roty=0.023
rtx=0
rty=0

' ## How big do you want it???
size=15

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'      Permanent and temporary storage definition!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'## Define arrays to store data:

dim x(polys)
dim y(polys)
dim z(polys)

'## Define arrays to hold transformed data:

dim tx(polys)
dim ty(polys)
dim tz(polys)
dim tc(polys)

'define arrays for calculated points:

dim cx(9)
dim cy(9)

numstar=34
  dim starx(numstar)
  dim stary(numstar)
  dim stars(numstar)
for a=1 to numstar
   starx(a)=1+ran(640)
   stary(a)=1+ran(640)
   stars(a)=1+ran(8)
next a
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Read in the object data and place into storage arrays:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=1
for a=1 to polys

   read x(b),y(b),z(b)
   b=b+1

next a

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                       Main Loop!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dw=0
label mloop
str=str+1
size=5*sin(str/65)
size=size+10
   setdrawbuf dw
   clear window
     gosub stars
     gosub transform
     gosub rotate
     gosub scroll

'>>> Give draw routine 4 corners! 
     cx(1)=tx(1)
     cy(1)=ty(1)
     cx(2)=tx(2)
     cy(2)=ty(2)
     cx(3)=tx(3)
     cy(3)=ty(3)
     cx(4)=tx(4)
     cy(4)=ty(4)
     gosub draw2

'>>> And the next 4:
     cx(1)=tx(5)
     cy(1)=ty(5)
     cx(2)=tx(6)
     cy(2)=ty(6)
     cx(3)=tx(7)
     cy(3)=ty(7)
     cx(4)=tx(8)
     cy(4)=ty(8)
     gosub draw2

'>>> And the next 4
     cx(1)=tx(1)
     cy(1)=ty(1)
     cx(2)=tx(2)
     cy(2)=ty(2)
     cx(3)=tx(6)
     cy(3)=ty(6)
     cx(4)=tx(5)
     cy(4)=ty(5)
     gosub draw2

'>>> And the next four    
     cx(1)=tx(3)
     cy(1)=ty(3)
     cx(2)=tx(4)
     cy(2)=ty(4)
     cx(3)=tx(8)
     cy(3)=ty(8)
     cx(4)=tx(7)
     cy(4)=ty(7)
     gosub draw2

'>>> and another four   
     cx(1)=tx(1)
     cy(1)=ty(1)
     cx(2)=tx(4)
     cy(2)=ty(4)
     cx(3)=tx(8)
     cy(3)=ty(8)
     cx(4)=tx(5)
     cy(4)=ty(5)
     gosub draw2

'>>> And the last four (phew!)
     cx(1)=tx(2)
     cy(1)=ty(2)
     cx(2)=tx(3)
     cy(2)=ty(3)
     cx(3)=tx(7)
     cy(3)=ty(7)
     cx(4)=tx(6)
     cy(4)=ty(6)
     gosub draw2
     gosub logo

   setdispbuf dw
   dw= 1-dw


goto mloop


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                     Main Loop Ends!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label logo

ainc=ainc+6
setrgb 1,30,30,130
zzz=5+.4*cos(ainc/100)
a=1

'>>> Draw logo

for b=1 to 18
 fill triangle zzz*logx(a)+lxo,zzz*logy(a)+lyo to zzz*logx(a+1)+lxo,zzz*logy(a+1)+lyo to zzz*logx(a+2)+lxo,zzz*logy(a+2)+lyo
 a=a+3
next b

return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                        Starfield
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label stars

 for a=1 to numstar
   setrgb 1,stars(a)*10,stars(a)*10,stars(a)*10
   fill rectangle starx(a),stary(a) to starx(a)+stars(a),stary(a)+stars(a)
 starx(a)=starx(a)-stars(a)
 if starx(a)<0 starx(a)=starx(a)+640
 next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                       Scroller!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label scroll
setrgb 1,155,155,255
scx=scx-1
if scx<0 pn=pn+1
if scx<0 scx=scx+10
if pn>len(t$) pn=0
text scx,445,mid$(t$,pn,64)

return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'           Rotate Object and apply perspective:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label rotate
'## New angles:

rtx=rtx+rotx
rty=rty+roty
'## For tidyness
crx=cos(rtx)
srx=sin(rtx)
cry=cos(rty)
sry=sin(rty)
'## spin `em!!
b=1
for p=1 to polys

 nwy= crx*ty(b) + srx*tz(b)
 nwz= crx*tz(b) - srx*ty(b)

 nwx= cry*tx(b) + sry*nwz
 nwz= cry*nwz - sry*tx(b)

'##  Perspective+offset
 nwz=nwz+700
 tx(b)=xff+nwx*1300 /nwz
 ty(b)=yff+nwy*1300 /nwz
 tz(b)=nwz

 b=b+1

next p

return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Pull Object into temporary storage for manipulation!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label transform
b=1
for a=1 to polys

 tx(b)=x(b)*size
 ty(b)=y(b)*size
 tz(b)=z(b)*size
 b=b+1

next a
 
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Draw the object held in the temporary array!!!!!!!!!!!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label draw2
setrgb 1,155,255,255

cx(5)=(cx(1)+cx(2))/2
cy(5)=(cy(1)+cy(2))/2
cx(6)=(cx(1)+cx(4))/2
cy(6)=(cy(1)+cy(4))/2
cx(7)=(cx(2)+cx(3))/2
cy(7)=(cy(2)+cy(3))/2
cx(8)=(cx(3)+cx(4))/2
cy(8)=(cy(3)+cy(4))/2
cx(9)=(cx(5)+cx(8))/2
cy(9)=(cy(5)+cy(8))/2

for a=1 to 9
   fill rectangle cx(a),cy(a) to cx(a)+ds,cy(a)+ds
next a
   fill rectangle (cx(1)+cx(5))/2,(cy(1)+cy(5))/2 to ds+(cx(1)+cx(5))/2,ds+(cy(1)+cy(5))/2
   fill rectangle (cx(5)+cx(2))/2,(cy(5)+cy(2))/2 to ds+(cx(5)+cx(2))/2,ds+(cy(5)+cy(2))/2
   fill rectangle (cx(1)+cx(6))/2,(cy(1)+cy(6))/2 to ds+(cx(1)+cx(6))/2,ds+(cy(1)+cy(6))/2
   fill rectangle (cx(1)+cx(9))/2,(cy(1)+cy(9))/2 to ds+(cx(1)+cx(9))/2,ds+(cy(1)+cy(9))/2
   fill rectangle (cx(2)+cx(9))/2,(cy(2)+cy(9))/2 to ds+(cx(2)+cx(9))/2,ds+(cy(2)+cy(9))/2
   fill rectangle (cx(5)+cx(9))/2,(cy(5)+cy(9))/2 to ds+(cx(5)+cx(9))/2,ds+(cy(5)+cy(9))/2
   fill rectangle (cx(2)+cx(7))/2,(cy(2)+cy(7))/2 to ds+(cx(2)+cx(7))/2,ds+(cy(2)+cy(7))/2
   fill rectangle (cx(6)+cx(9))/2,(cy(6)+cy(9))/2 to ds+(cx(6)+cx(9))/2,ds+(cy(6)+cy(9))/2
   fill rectangle (cx(9)+cx(7))/2,(cy(9)+cy(7))/2 to ds+(cx(9)+cx(7))/2,ds+(cy(9)+cy(7))/2
   fill rectangle (cx(6)+cx(4))/2,(cy(6)+cy(4))/2 to ds+(cx(6)+cx(4))/2,ds+(cy(6)+cy(4))/2
   fill rectangle (cx(9)+cx(4))/2,(cy(9)+cy(4))/2 to ds+(cx(9)+cx(4))/2,ds+(cy(9)+cy(4))/2
   fill rectangle (cx(9)+cx(8))/2,(cy(9)+cy(8))/2 to ds+(cx(9)+cx(8))/2,ds+(cy(9)+cy(8))/2
   fill rectangle (cx(9)+cx(3))/2,(cy(9)+cy(3))/2 to ds+(cx(9)+cx(3))/2,ds+(cy(9)+cy(3))/2
   fill rectangle (cx(7)+cx(3))/2,(cy(7)+cy(3))/2 to ds+(cx(7)+cx(3))/2,ds+(cy(7)+cy(3))/2
   fill rectangle (cx(4)+cx(8))/2,(cy(4)+cy(8))/2 to ds+(cx(4)+cx(8))/2,ds+(cy(4)+cy(8))/2
   fill rectangle (cx(8)+cx(3))/2,(cy(8)+cy(3))/2 to ds+(cx(8)+cx(3))/2,ds+(cy(8)+cy(3))/2

return



'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' 3D Object Description As Numerical Data...
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' Fanatix Logo... Designed By Nick!!

data -39,-9,-25,-15,-24,-8
data -31,-15,-35,15,-28,15
data -38,0,-27,-4,-26,5
data -25,15,-20,-15,-21,18
data -21,-15,-15,15,-18,15
data -25,3,-18,-4,-16,4
data -15,14,-13,-14,-13,17
data -16,-14,-9,15,-5,18
data -11,-7,-8,-10,-6,19
data -3,-12,-5,15,-3,18
data -6,-13,5,15,2,16
data -6,3,-5,-2,4,4
data -2,-10,0,-6,15,-12
data 6,17,10,15,3,-13
data 12,15,20,15,15,-4
data 15,-4,17,-7,10,-8
data 15,-11,35,15,27,13
data 35,-15,29,-13,21,19


label object
' data structure: x,y,z
' define the eight corners of a cube.

data -5,-5,-5,5,-5,-5,5,5,-5,-5,5,-5
data -5,-5,5,5,-5,5,5,5,5,-5,5,5
 
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                    End of routine!!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



