'#
'# Sine-Scroll demo by Parabellum (2002)
'#
'# Entry #1 for the 40 lines demo competition
'# Indented version (same code as the squeezed entry)
'#
'# Use LEFT and RIGHT to adjust the scroller speed.
'#

data 477477,566354,600340,304420,140434, 35141,414545,149578,599133,674066,692804,599186,152136,313490,153682,594505,672930,299304,599210,283204,332945,346404,381512, 76068,150085,600401,299300,337041,599204,599108,599186,168516,205970,168516,566418,603428,300324,673938,660040,461395,149794,599177,149794,365129,140434,296009,300914,150162,599113,280840,149800,861317,168517,435345,169106,594505,673058,233800,598313,299380,591946,337026,299594,83236,151817, 84581,285961,594570,337570,599208,599188,299588,337041,149793,337041,641316,272676,242834,488009,320658,149842,599913,149572,674085,68050,296249,304962,300257,299586,903457,234057,160937,323109,384137,342306,604690,934544,824228,148521,166473,599113,149796,599177,149780,299593,74898,282185,599186,148708,585

S$="]]]]]SURPRISE\\\\\\aaaPARABELLUMaATaTHEaKEYBOARD]]]aIaAMaPROUDaTOaPRESENTaTHISaNICEaEFFECTaCALLEDa^SINEaLEDSaSCROLL^]]]aITaISaDEDICATEDaTOaMYaBABYa[[SOPHIE[[aaaGREETINGSaFLYaTOaEVERYaYABaFANATICaATaTHEaBOARD]aTHEaTEXTaISaABOUTaTOaRESTARTaNOWaBUTaYOUaCANaCHANGEaITSaSPEEDaUSINGaTHEa^LEFT^aANDa^RIGHT^aKEYSaOFaYOURaGAMEPAD]]]aENJOYaTHEaSHOW\\]]]]]]"

dim F(32,3,5)        REM --- ( nbf, X-1, Y-1 )
dim FS(32)           REM --- ( fonts spacing )

for ig=0 to 29
  gosub pop : FS(ig)=AND(g,1)
  for x=0 to 3 for y=0 to 5
    g=0 : gosub pop : gosub pop : gosub pop
    if g=1 then g=0 elsif g=2 then g=12 else g=8-g fi
    F(ig,x,y)=g
    next next
next
FS(32)=-1

if crc<>427620  then print "Error in data line!" : end fi

XS=14
dim M(5,5*len(S$))
for ig=1 to len(S$)
  g=asc(mid$(S$,ig,1))-65
  for y=0 to 5 : for x=0 to 3
      M(y,x+stop)=F(g,x,5-y)
  next : next
  stop=stop+4+FS(g)
next
S$=""

rem INITIALISATIONS --------------------------------------

dim S(1440) : dim C(1440) : for ic=0 to 1440
S(ic)=40*sin(ic*PI/720): C(ic)=90*cos(ic*PI/720): next

DY=0.002:dy=1
xs=640
m=39

open window 640,512
window origin "lb"

label LOOP rem -------------------------------------------

  setdrawbuf 1-D

  setrgb 1,100,0,0
  fill rect 0,0 to 640,512

  setrgb 1,200,200,200

  if (xs<-1.8*m)  then
    IB=mod(IB+1,stop-16)
    xs=xs+m
  fi
  xs=xs-XS

rem ======================================================
rem   1440/640 = 2.25
rem   1440/512 = 2.8125

  i=IB
  y2=375
  f=S(mod(ds+2.8125*y2,1440))
  for yy=0 to 5
    x2=xs
    d=C(mod(dc+2.25*(dy*xs+640),1440))
    y1=y2 : y2=y2-m : e=f
    f=S(mod(ds+2.8125*y2,1440))
    ii=i-1
    while( x2<640+1.8*m)
      ii=ii+1 : x1=x2 : x2=x2+m : c=d
        d=C(mod(dc+2.25*(dy*x2+640),1440))
        k = M(yy,ii)
if k=12 then
   fill triangle x1+e,y1+c to x2+f,y2+d to x1+f,y2+c
   fill triangle x1+e,y1+c to x2+f,y2+d to x2+e,y1+d
elsif k>3 then if k<5 then 
   fill triangle x1+e,y1+c to x2+f,y2+d to x1+f,y2+c
else 
   fill triangle x1+e,y1+c to x2+f,y2+d to x2+e,y1+d
fi elsif k>0 then if k>1 then
   fill triangle x1+e,y1+c to x1+f,y2+c to x2+e,y1+d
else
   fill triangle x2+f,y2+d to x1+f,y2+c to x2+e,y1+d
fi fi

    wend
    ds=ds+1.05
  next yy
  dc=mod(dc+10,1440)
  ds=mod(ds,1440)
  dy=dy+DY
  if (dy>1.15 or dy<0.25) DY=-DY

  for a=4 to 640 step 10
    clear fill rect a-4,0 to a,512
    clear fill rect 0,a-4 to 640,a
  next

  D=1-D
  setdispbuf D

  a=peek("port1")
  if a<>0 XS=min(m,max(0,XS+AND(a,128)/128-AND(a,32)/32))

GOTO LOOP

LABEL pop
  if bit=0 then read z : crc=xor(crc,z)+19996 : bit=20 fi
  bit=bit-1 :  g=g*2+AND(z,1) :  z=z/2
RETURN



