'Please Upload.

' This is the first entry for the 300 lines demo comp.
' Believe me, I had a hard time squeezing this one.
' The code is the same than the submitted entry though,
' so it will save you some typing ;)
'
' I wanted to play with colours in this demo, and I did it
' indeed. Still, I'm not sure whether the result looks 
' good or not. I mean, the colour scheme is quite special
' I must admit. Some will hate it for sure. 
' I hope you don't :o)
' Anyway, the background pattern colors are random, so it
' should be different at each run. This is not visible in
' the emulator, since it always returns the same random
' numbers sequence :(
'
' Enjoy at 50FPS -----------------------------------------

open window 640,512
text 320,256,"  L O A D I N G  \n\n...Please Wait...","cc"

' YS=36 : XS=74
  YS=18 : XS=42
' YS=10 : XS=27
' YS=6  : XS=22

' XMIN=158 : XMAX=591

s$="   PARABELLUM PRESENTS HIS LATEST DEMO CALLED .STATIC"
s$=s$+".   SORRY IT HAS ONLY ONE EFFECT BECAUSE THERE IS "
s$=s$+"NO MORE ROOM... MORE TO COME IN STATIC II... GREET"
s$=s$+"INGS TO .SHOCKWAVE. .XALTHORN. .JIM SHAW. .RAFRYER"
s$=s$+". .JINX. .JOMORROW .DOCTOR. .KYATA. .DEMONEYE. .SN"
s$=s$+"AKEDOGG. AND ALL THE OTHERS... SCROLL RESTARTS...."

'====================== Load fonts definition info F array

dim  M(5*len(s$),6),  F(27,4,6),  skip(27)

read x             REM -- Line horizontal offset
for c=1 to 27      REM -- Nbr of chars = 27
  y=1
  while (y<7)
    if x<>0 then
      read w       REM -- Line width
      repeat 
        F(c,x,y) = w/2
        x = x+1
        if (w<0) then w=-w-1 else w=w-2 fi
      until (w<=0)
    fi
    read x
    if (x<=0) then y=y+1 : x=-x fi
  wend
next

'------ A .. C
data  1,-6, -1,2,4,2, -1,8, -1,2,4,2, -1,2,4,2, -1,2,4,2
data -1,7, -1,2,4,2, -1,7, -1,2,4,2, -1,2,4,2, -1,7
data -1,-7, -1,2, -1,2, -1,2, -1,2, -1,-7
'------ D .. F
data -1,7, -1,2,4,2,-1,2,4,2, -1,2,4,2, -1,2,4,2, -1,7
data -1,-7, -1,2, -1,6, -1,2, -1,2, -1,-7
data -1,-7, -1,2, -1,6, -1,2, -1,2, -1,2
'------ G .. I
data -1,-6, -1,2,4,2, -1,2, -1,2,3,-3, -1,2,4,2, -1,-7
data -1,2,4,2,-1,2,4,2,-1,8,-1,2,4,2,-1,2,4,2,-1,2,4,2
data -1,6, -2,2, -2,2, -2,2, -2,2, -1,6
'------ J .. L
data -2,-5, -4,2, -4,2, -4,2, -1,2,4,2, -1,-6
data -1,2,4,2,-1,2,3,-2, -1,6, -1,2,3,-2,-1,2,4,2,-1,2,4,2
data -1,2, -1,2, -1,2, -1,2, -1,2, -1,7
'------ M .. O
data -1,3,3,-3, -1,8, -1,2,2,-2,4,2, -1,2,4,2, -1,2,4,2, -1,2,4,2
data -1,3,4,2, -1,5,4,2, -1,2,2,-5, -1,2,3,-3, -1,2,4,2, -1,2,4,2
data -1,-6, -1,2,4,2,-1,2,4,2,-1,2,4,2,-1,2,4,2, -1,-6
'------ P .. R
data -1,7, -1,2,4,2, -1,7, -1,2, -1,2, -1,2
data -1,-6, -1,2,4,2,-1,2,4,2, -1,2,2,-2,4,2, -1,2,3,3, -1,-4,4,2
data -1,7, -1,2,4,2, -1,7, -1,2,4,2, -1,2,4,2, -1,2,4,2
'------ S .. U
data -1,8, -1,2, -1,8, -4,2, -4,2, -1,8
data -1,8, -2,-2, -2,-2, -2,-2, -2,-2, -2,-2
data -1,2,4,2,-1,2,4,2,-1,2,4,2,-1,2,4,2,-1,2,4,2,-1,-7
'------ V .. X
data -1,2,4,2, -1,2,4,2, -1,2,4,2, -1,-2,3,-2, -2,4, -2,-2
data -1,2,4,2, -1,2,4,2, -1,2,4,2, -1,2,2,-2,4,2, -1,8, -1,3,3,-3
data -1,3,3,-3, -2,4, -2,-2, -2,-2, -2,4, -1,3,3,-3
'------ Y,Z,.
data -1,2,4,2, -1,2,4,2, -1,-7, -4,2, -4,2, -1,7
data -1,8, -3,3, -2,-3, -2,3, -1,-3, -1,8
data 0,0,0,0,0, -1,2
'------ end
data -1

'==================== Load fonts spacing into skip() array

data -2,-1,-3
read skip(0), skip(9), skip(27)

'============== Break down the text, put it into M() array

for i=1 to len(s$)
  c = asc(mid$(s$,i,1))-64
  if c=-32 then c=0 elsif c=-18 then c=27 fi
  for y=1 to 6 : for x=1 to 4
      M(x+stop,y) = F(c,x,y)
  next : next
  stop = stop+5+skip(c)
next
s$=""

'============================== Fill sin/cos lookup tables

dim S(2880), C(2880)
for i=0 to 2880
  S(i) = sin(i/360 * PI)         REM - Step is 0.25 degree
  C(i) = cos(i/360 * PI)         REM - Step is 0.25 degree
next

'============= Load fonts gradient colors into grd() array

REM  Ypos    R   G   B
data 18,     0,  0,  0
data 50,   134, 90,  0
data 110,   80,160, 40
data 210,    0,  0,128
data 380,  128,  0,  0
data 501,    0,  0,  0

dim grd(6*4)
for i=1 to 6*4  read grd(i)  next

'========== Load cube faces (gray) colors into col() array

data 150,120,90,120,90,150,  90,160,230,160,230,90
dim col(12)
for i=1 to 12  read col(i)  next

'=========== Load cube vertices/faces into px,py,pz and o1

dim o1(6,4), px(8),py(8),pz(8), tX(8),tY(8)

data 1,1, 1,  1,-1, 1,  -1,-1, 1,  -1,1, 1
data 1,1,-1,  1,-1,-1,  -1,-1,-1,  -1,1,-1
for i=1 to 8 read   px(i),py(i),pz(i)   next

data 1,2,3,4, 2,1,5,6, 1,4,8,5, 4,3,7,8, 3,2,6,7, 8,7,6,5
for f=1 to 6 for i=1 to 4   read o1(f,i)   next next

'======== Init xy array (right tiles gray color component)

dim XY(23,58), xy(21,56)  REM -- XY = temporary work array

for i=0 to 22
  n=0
  for j=0 to 57
    if (n<=0) then
      n =  4 + ran(9)
      c = 10 + ran(140)
      if (j+n>53) n=58-j
    fi
    XY(i+1,j+1) = c
    n = n-1
  next
next

for i=0 to 23  XY(i,0)=XY(i,1) : XY(i,58)=XY(i,57)  next
for i=0 to 58  XY(0,i)=XY(1,i) : XY(23,i)=XY(22,i)  next

for i=0 to 21 for j=0 to 56
  c = 3 * XY(i+1,j+1)
  c = c+ XY(i,j+1) + XY(i+2,j+1) + XY(i+1,j) + XY(i+1,j+2)
  xy(i,j) = c / 7
next next

'======== Init the ln() array (left line colors/positions)

dim ln(512,4)
ln(0,1)=40 : ln(0,2)=50
ln(0,3)=30 : ln(0,0)=200

for i=1 to 512
  ln(i,0) = min( 400, max( 40, ln(i-1,0)+20-ran(40)))
  for j=1 to 3
    ln(i,j) = min( 100, max( 20, ln(i-1,j)+10-ran(20)))
  next
next

'===================== Draw static graphics in each buffer
FOR db=0 to 1

setdispbuf db : setdrawbuf 1-db

window origin "lb"

R=1.2 : G=0.90 : B=0.90  REM -------------- The left lines

for i=0 to 512
  m=1 : if mod(i,4)=1 m=0.35
  x = ln(i,0) : c = m*ln(i,1)
  setrgb 1,R*c,G*c,B*c : c = m*ln(i,2)
  setrgb 2,R*c,G*c,B*c : setrgb 3,R*c,G*c,B*c
  gtriangle 0,i to x,i to x,i+200  :  c = m*ln(i,3)
  setrgb 1,R*c,G*c,B*c
  gtriangle 444,i to x,i to x,i+200
next

clear line 442,0 to 442,512  REM --------- The right tiles

window origin "rb"
R=0.95 : G=1.15 : B=0.95

for i=0 to 21
  for j=0 to 56
    c = xy(i,j) : setrgb 1,R*c,G*c,B*c
    fill rect 9*i,9*j, 9*i+8,9*j+8
    if (j>0) then
      c = (xy(i,j-1)+c)/3
      setrgb 1,R*c,G*c,B*c
      line 9*i,9*j, 9*i+9,9*j
    fi
    if (i>0) then
      c = (xy(i-1,j)+c)/3
      setrgb 1,R*c,G*c,B*c
      line 9*i,9*j, 9*i,9*j+9
    fi
    n = n-1
  next
next

window origin "lb"  REM ----------------- The effect frame

setrgb 1,200,200,200
setrgb 2,100,100,100
setrgb 3,100,100,100
clear fill rect 149,239, 601,491
gtriangle 600,240 to 600,490 to 150,240
setrgb 1,60,60,60
gtriangle 150,490 to 600,490 to 150,240

gosub logo  REM --------------------- The transparent logo

Label cubes : restore cubes   REM ------- The static cubes
data 700, 400, 300,   2, 15, 538, 108
data 240, 372, 466,   2, 20, 533,  90
data  90, 338,  22, 1.5, 30, 540,  40
data 442,  74, 234, 1.5, 40, 590, 102
data 514, 600, 342, 1.5, 49, 469,  70
data 184, 450, 242, 1.5, 60, 510, 210
for i=1 to 6 
  read rX,rY,rZ,dz,mult,xc,yc : gosub cube 
next

NEXT REM ====================== End of static drawing loop

mult=80 : dcol=1
XC=(600+150)/2 : YC=(490+240)/2

'======================================= MAIN PROGRAM LOOP
db=1
LABEL MAIN_LOOP

  setdrawbuf db : db=1-db
  setdispbuf db

  clear fill rect 155,245, 595,485
  bg=mod(bg+4,360*4)
  c = 45+45*C(bg) : setrgb 1,c,c,c
  c = 45+45*C(bg+150) : setrgb 2,c,c,c
  c = 45+45*C(bg+300) : setrgb 3,c,c,c
  gtriangle 155,245 to 155,485 to 595,485
  c = 45+45*C(bg+450) : setrgb 2,c,c,c
  gtriangle 155,245 to 595,245 to 595,485

  rX = mod( rX+3.84, 720)
  rY = mod( rY+5.27, 720)
  rZ = mod( rZ+2.40, 720)
  gosub cube

  for y=245 to 485 step 2
    clear line 155,y to 595,y
  next

  scrx=scrx-10
  scry=mod(scry+9,720)
  if scrx<=-XS then
    I=I+1
    scrx=scrx+XS
    if stop<I then
      I=1
      scrx=440
    fi
  fi

  Y= 249+58+2*int(28*C(scry))+6*(YS+2)
  X= scrx + 158

  setrgb 1,128,64,64

  XS2=XS/2
  y=Y
  for IY=1 to 6
    IX=I
    x=X
    y = y-YS-2
    repeat
      n=M(IX,IY)
      if n<>0 then
        L=XS*n
        if n<0 then x=x+XS2 : L=-L : IX=IX+1 fi
'       xm = max(XMIN,x) : xM = min(XMAX,x+L)
        xm = max(158,x) : xM = min(591,x+L)
        if xm<xM then
          for t=y+YS to y step -2
            REM -- unroll 2 loops to speed up a bit
            line xm,t to xM,t : t=t-2
            line xm,t to xM,t
          next
        fi
        if n<0 then n=-n : x=x+XS2 fi
        n = int(n+0.5)
        x = x + XS*n
        IX = IX+n
      else
        x=x+XS  REM SPACE
        IX=IX+1
      fi
'   until (x>=XMAX)
    until (x>=591)
  next

  REM --- Redraw the foreground cube face
  c=0.8*col(2)
  setrgb 1,c,c,c
  fill triangle 503,279 to 572,239 to 465,235
  setrgb 1,60,60,60
  line 503,279 to 572,239
  line 503,279 to 465,235

GOTO MAIN_LOOP


LABEL cube
  CX=C(rX) : SX=S(rX)
  CY=C(rY) : SY=S(rY)
  CZ=C(rZ) : SZ=S(rZ)

  m00 = ( CY*CZ )
  m01 = ( -CY*SZ )
  m02 = ( SY * 0.25 )
  m10 = ( CX*SZ + SX*SY*CZ )
  m11 = ( CX*CZ - SX*SY*SZ )
  m12 = ( SX*CY * -0.25 )
  m20 = ( SX*SZ - CX*SY*CZ )
  m21 = ( SX*CZ + CX*SY*SZ )
  m22 = ( CX*CY * 0.25 )

  for p=1 to 8
    X=px(p) : Y=py(p) : Z=pz(p)
    z     = (m02*X + m12*Y + m22*Z + dz) / mult
    tX(p) = (m00*X + m10*Y + m20*Z) / z
    tY(p) = (m01*X + m11*Y + m21*Z) / z
  next

  if dcol=1 then
    xc = XC+120*C(pcx) : pcx=mod(pcx+5,720)
    yc = YC+24*C(pcy)  : pcy=mod(pcy+8,720)
  fi

  for f=1 to 6
    f1= o1(f,1) : f2= o1(f,2) : f3= o1(f,3) : f4= o1(f,4)
    x1 = tX(f1) : y1 = tY(f1)
    x2 = tX(f2) : y2 = tY(f2)
    x3 = tX(f3) : y3 = tY(f3)
    if (x1-x2) * (y3-y2) - (x3-x2) * (y1-y2) < 0 then 
     if dcol=1 then
      c=col(f+6) : setrgb 1,c,c,c
      fill triangle x1+xc,y1+yc to x2+xc,y2+yc to x3+xc,y3+yc
      fill triangle x1+xc,y1+yc to x3+xc,y3+yc to tX(f4)+xc,tY(f4)+yc
     else
      c=0.8*col(f) : setrgb 1,c,c,c
      fill triangle x1+xc,y1+yc to x2+xc,y2+yc to x3+xc,y3+yc
      fill triangle x1+xc,y1+yc to x3+xc,y3+yc to tX(f4)+xc,tY(f4)+yc
      setrgb 1,60,60,60
      new curve : 
      line to x1+xc,y1+yc : line to x2+xc,y2+yc
      line to x3+xc,y3+yc : line to tX(f4)+xc,tY(f4)+yc
      line to x1+xc,y1+yc
     fi
    fi
  next
return

label logo : restore logo
data 80,313,124,296,80,402,124,418,124,296,80,402,143
data 201,143,173,155,173,143,126,155,126,143,98,143,126
data 143,98,155,98,143,126,155,126,143,98,229,201,229,173
data 241,173,229,126,229,98,241,98,229,126,241,126,229,98
data 5,68,297,68,215,92,215,105,222,114,236,122,261,124
data 297,5,68,418,68,500,92,500,105,493,114,480,122,454
data 124,418,3,124,418,73,418,77,415,79,410,80,402,3,124
data 297,73,297,77,300,79,305,80,313,4,408,173,399,201,399
data 173,408,145,417,173,417,201,18,52,500,1,16,18,12,201
data 13,78,100,121,164,186,207,250,281,312,343,365,387,417
data 173,10,201,5,90,133,176,219,262,98,10,126,5,90,133
data 176,219,262,18,10,46,5,219,262,293,324,355,126,12,173
data 2,143,229,18,12,98,2,143,229

for i=1 to 9 
  read x,y,X,Y,x2,y2 : tr(x,y,X,Y,x2,y2) 
next

for j=1 to 5
  read i,x,y,x1,y1
  for i=i to 1 step -1 
    read x2,y2 : tr(x,y,x1,y1,x2,y2)
    x1=x2 : y1=y2 
  next
next

for j=1 to 7 
 read y,w,y1,i
 for i=i to 1 step -1
   read x: tr2(x,y,x,y1,x+w,y1) :tr2(x+w,y1,x,y,x+w,y) 
 next 
next
return

sub tr(x1,y1,x2,y2,x3,y3)
  if y1<y2 then
    T=y2 : y2=y1 : y1=T
    T=x2 : x2=x1 : x1=T
  fi
  if y2<y3 then
    T=y2 : y2=y3 : y3=T
    T=x2 : x2=x3 : x3=T
    if y1<y2 then
      T=y2 : y2=y1 : y1=T
      T=x2 : x2=x1 : x1=T
    fi
  fi
  if (y1=y2) then
    if (x1<x2) then tr2(x3,y3, x1,y1, x2,y2)
    else            tr2(x3,y3, x2,y2, x1,y1)  fi
  elsif (y2=y3) then
    if (x2<x3) then tr2(x1,y1, x2,y2, x3,y3)
    else            tr2(x1,y1, x3,y3, x2,y2)  fi
  else
    T = x1 - (y1-y2)*(x1-x3)/(y1-y3)
    if (x2<x) then
      tr2(x1,y1, x2,y2, T,y2)
      tr2(x3,y3, x2,y2, T,y2)
    else
      tr2(x1,y1, T,y2,  x2,y2)
      tr2(x3,y3, T,y2,  x2,y2)
    fi
  fi
end sub

sub tr2(x1,y1,x2,y2,x3,y3)
  m2 = (x1-x2)/(y1-y2)
  m3 = (x1-x3)/(y1-y3)
  if y1<y2 then
    x2=x1 : x3=x1
    y3=y1 : y1=y2
    y2=y3
  fi
  for t=y2 to y1
   if and(t,1)=1 then
    k=-3
    repeat
      k=k+4 : Y2=grd(k+4)
    until (t<Y2)
    Y1=grd(k)
    R=(grd(k+5)*abs(Y1-t) + grd(k+1)*abs(Y2-t)) / (Y2-1)
    G=(grd(k+6)*abs(Y1-t) + grd(k+2)*abs(Y2-t)) / (Y2-1)
    B=(grd(k+7)*abs(Y1-t) + grd(k+3)*abs(Y2-t)) / (Y2-1)
    setrgb 1,R,G,B
    line x2-0.5,t to x3+0.5,t
   fi
   x2=x2+m2
   x3=x3+m3
  next  
end sub



