'---- ROTATIVE BANG BALLS DEMO ----


'---- INITIALIZE BANG BALLS ----

SUB INIT_DEMO_BANG_BALLS

 LOCAL T
 QTD=3
 FOR T=200 TO 200+QTD
  SZ(T)=80 'SIZE OF BALLS
  SP(T)=1
 NEXT T

 DG=0      'DEGREE
 SIZEB=0   'DEPTH / SIZE OF BALLS
 PAGE WRITE 1

 PLAY STOP
 
 'PLAY PARTIAL MUSIC WHEN RUNNING A DEMO SECTION
 IF DEMOSEC=1 THEN
  PLAY MODFILE "./ASSETS/excellate_pt1.mod",22050
 ELSE
  PLAY MODFILE "./ASSETS/excellate.mod",22050
 ENDIF

 TIMENOW = Timer 

END SUB


'---- DEMO BANG BALLS ----

SUB RUN_DEMO_BANG_BALLS

 LOCAL T,I,SW,R,G,B,COT,FIRSTR

 'FOR INIT REVERSED STARTS ONE TIME ONLY
 FIRSTR=0

 'RUN UNTIL DEPTH SIZE < APROX 2
 DO WHILE SIZEB < 2

  BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

  'GENERAL DEGREE
  DG=DG+5
  IF DG>360 THEN DG=DG-360
  IF DG<0 THEN DG=DG+360

  SIZEB=SIZEB+0.01
  IF Timer<TIMENOW+9000 THEN
   IF SIZEB>1 THEN 'KEEP DEPTH=1 UNTIL 9 SEC
    SIZEB=1
    'START REVERSED STARS ONLY ONE TIME
    IF FIRSTR=0 THEN FIRSTR=1: INIT_REVERSED_STARS(80-SEC*5)
   ELSE
    'KEEP NORMAL STARFIELD FOR A WHILE
    STARFIELD(80)
   ENDIF
  ELSE
   'ROTATE FASTER AFTER STARFIELD VANISHED
   DG=DG+3.05
  ENDIF
  'KEEP FAST REVERSED STARFIELD
  IF SIZEB>=1 THEN REVERSED_STARFIELD(80-SEC*5):REVERSED_STARFIELD(80-SEC*5)

  'ROTATE THE BALLS
  XT=0:YT=0
  FOR T=200 TO 200+QTD
   SZ(T)=(COS(RAD(DG+(T-200)*90))*30+50)*SIZEB
   X(T)=(SIN(RAD(DG+(T-200)*90))*(MAXX/4))*SIZEB+MAXX/2-Y(T)*COS(RAD(DG))*(1-SIZEB)
   X(T)=X(T)+SIN(RAD(DG/2+(T-200)*90))*(MAXY/6)*COS(RAD(DG/2))
   Y(T)=(COS(RAD(DG+(T-200)*90))*(MAXY/10))*SIZEB+MAXY/2+X(T)*SIN(RAD(DG))*(1-SIZEB)
   Y(T)=Y(T)+COS(RAD(DG/2+(T-200)*90))*(MAXX/6)*SIN(RAD(DG/2))
   XT=XT+X(T)
   YT=YT+Y(T)
  NEXT T

  'CENTROID OF THE BALLS
  XT=XT/4
  YT=YT/4

  'TEMPORARY DEPTH
  FOR T=1 TO 4
   SLINE(T)=0
  NEXT T

  'DEPTH OF BALLS
  TT=200
  FOR T=1 TO 4
   MINSZ=999
   FOR I=200 TO 200+QTD
    IF MINSZ>SZ(I) AND SLINE(I-199)=0 THEN MINSZ=SZ(I): TT=I
   NEXT I
   SLINE(TT-199)=1

   'COLOR OF THE BALLS
   I=50+SZ(TT)*2
   IF I>200 THEN I=200
   R=20:G=20:B=20
   SELECT CASE TT
    CASE 200: R=I
    CASE 201: R=I: G=I
    CASE 202: B=I
    CASE 203: G=I
   END SELECT

   'MAIN CORE
   COT=(127+COS(RAD(DG*(TT-198)))*125)*SIZEB
   IF COT>255 THEN COT=255
   CIRCLE XT,YT,SZ(TT)/1.5,COT/100,1,RGB(COT,COT,COT)

   'COLOR BALLS
   CIRCLE X(TT),Y(TT),SZ(TT),SZ(TT)/10,SP(TT),RGB(R/1.5,G/1.5,B/1.5),RGB(R,G,B)
   CIRCLE X(TT)-SZ(TT)/2.2,Y(TT)-SZ(TT)/2.2,SZ(TT)/5,SZ(TT)/18,SP(TT),RGB(R*1.13,G*1.13,B*1.13),RGB(R*1.21,G*1.21,B*1.21)

  NEXT T

  'KEEP 25 FPS AND GET SECONDS
  FPS(25)
  SEC=INT(Timer-TIMENOW)\1000

  'FIX SCREEN BORDERS
  BOX 0,0,MAXX,MAXY,1,RGB(0,0,0)

  'COPY TO MAIN PAGE
  PAGE COPY 1 TO 0,B

 LOOP

END SUB

