'By Parabellum. (Please Upload).
'
' This is the 2nd submission for the 300 lines comp.
' The scroll text is not the same as the one in the 
' submission because I updated it before posting the demo.
' The code is the same, though :)
'
' The code is not clean, since it has been written in a
' hurry. There is still some tests code inside, and it is
' not completely optimized.
'---------------------------------------------------------

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

  YSh=36+3 : XSh=74

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

' XMIN=158 : XMAX=591

s$="   PARABELLUM PRESENTS A VARIATION OF THE .STATIC. DE"
s$=s$+"MO. IT STILL 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),M2(4,7.1*len(s$)),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)
      M2(x,y+stop2) = F(c,x,y)
  next : next
  stop = stop+5+skip(c)
  stop2 = stop2+7+skip(1)
next
s$=""

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

dim wave(2880*2), col(2880*2), S(2880*2), C(2880*2)
for i=0 to 2880*2
  S(i) = sin(i/360 * PI)         REM - Step is 0.25 degree
  C(i) = cos(i/360 * PI)         REM - Step is 0.25 degree
  wave(i) = XS*1.3 * sin(i*PI/180)
  col(i) = 150*cos(i*0.5*PI/180)
next

dim R(500), B(500)
for i=0 to 240
  R(i+245) = 50 * i/240
  B(i+245) = 55 * (1 - abs(120-i)/120)
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
dim fcol(6)
for i=1 to 6  read fcol(i) : fcol(i)=0.8*fcol(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
'R=1.3 : G=0.95 : B=0.95

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
'--- clear fill rect 155,245, 595,485

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

XC=(600+150)/2 : YC=(490+240)/2

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

  setdrawbuf db : db=1-db
  setdispbuf db

  bg=mod(bg+4,360*4)
  c = 24+35*C(bg)     : setrgb 1,0.7*c,c,0.7*c
  c = 24+35*C(bg+150) : setrgb 2,c,0.7*c,0.7*c
  c = 24+35*C(bg+300) : setrgb 3,c,0.7*c,0.7*c
  gtriangle 155,245 to 155,485 to 595,485
  c = 24+35*C(bg+450) : setrgb 2,0.7*c,c,0.7*c
  gtriangle 155,245 to 595,245 to 595,485

'  scrx=scrx-10
  scrx=scrx-8
  scry=mod(scry+9,720)
  if scrx<=-XSh then
    I=I+1
    scrx=scrx+XSh
    if stop<I then
      I=1
      scrx=440
    fi
  fi
  Y= 249+6*(YSh)
  X= scrx + 158

XS2=XSh/2
  y=Y
  for IY=1 to 6
    IX = I
    x  = X
    y2 = y
    y  = y-YSh
r2=R(y2) : b2=B(y2) : g2=50-r2
r1=R(y)  : b1=B(y)  : g1=50-r1
setrgb 2,r1,g1,b1
setrgb 3,r2,g2,b2
    repeat
      n=M(IX,IY)
      if n<>0 then
        L=XSh*n
        if n<0 then x=x+XS2 : L=-L : IX=IX+1 fi
  xm = max(158,x) : xM = min(591,x+L)
  if xm<xM then
    setrgb 1,r1,g1,b1
    gtriangle xm,y  to xM,y to xm,y2
    setrgb 1,r2,g2,b2
    gtriangle xM,y2 to xM,y to xm,y2
  fi
        if n<0 then n=-n : x=x+XS2 fi
        n = int(n+0.5)
        x = x + XSh*n
        IX = IX+n
      else
        x=x+XSh  REM SPACE
        IX=IX+1
      fi
    until (x>=591)
  next


  os=mod(os+5,2880)

  scry2=scry2-4
'  scry2=scry2-6
  if scry2<=-YS then
    I2=I2+1
    scry2=scry2+YS
    if stop2<I2 then
      I2=1
      scry2=230
    fi
  fi

  ki=mod(ki+2,720)
  Y=484-scry2 : y=Y
  XS2=XS/2 : XSD=XS*1.25
'  setrgb 1,64,64,128
'  setrgb 1,64,64,64

  IY=I2
  repeat
    IX=1
    x=XC-2*XS
    y = y-YS
    repeat
      n=M2(IX,IY)
      if n<>0 then
        L=XS*n
        if n<0 then 
          x=x+XS2
          L=-L
          IX=IX+1
        fi
        for k=y to y+YS step 2
          if k>482 goto break1
          if k>244 then
'            xd = x + XSD*C(3*(k+ki))*S(k+2*ki)
'            xd = x + XSD*S(k+2*ki)
'            xd = x*(k/246) + S(k)
            xd = x + wave(k+os)
            setrgb 1,col(k+os),60,40
            line xd,k,xd+L,k
k=k+2
            xd = x + wave(k+os)
'            setrgb 1,col(k+os),60,40
            line xd,k,xd+L,k
'            line x,k,x+L,k
'            m=k/340 : line xd*m,k,(xd+L)*m,k
          fi
        next
LABEL break1
        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 (IX>=5)
    IY = IY+1
  until  (y<=240)


c=fcol(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

  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 
      c=fcol(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
  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
'setrgb 1,255,255,255
    line x2-0.5,t to x3+0.5,t
   fi
   x2=x2+m2
   x3=x3+m3
  next  
end sub












