'---- PSEUDO 3D FLOOR AND PLY ANIMATION DEMO ----


'---- INITIALIZE FLOOR_PLY DEMO ----

SUB INIT_DEMO_FLOOR_PLY

 PLY_DG=0: PLY_SC=10
 DG_SPD=5

 LOADPLY("CUBE.PLY",0,0,0,0)
 LOADPLY("OCTAHEDRON.PLY",1,0,0,0)

 PLY_RGB(0,2,2,0)
 PLY_ADJUST_COLOR(0,45)

 PLY_RGB(1,0,2,2)
 PLY_ADJUST_COLOR(1,45)

 PAGE WRITE 1
 PAUSETIMER=0: TIMENOW = 0: Timer=0

END SUB


'---- PLY RENDERER DEMO ----

SUB RUN_DEMO_FLOOR_PLY
 LOCAL T,TA,TB,TC,TS,XSCR,F,FLASHNOW,SEC,XSPD,FL

 XSCR=MAXX:XSPD=16:FL=255

 FLASHNOW=0

 'RUN DEMO UNTIL 27.8 SECONDS
 DO WHILE SEC<22.7

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

  FPS(30)
  SEC=(Timer-TIMENOW)/1000

  PLY_SC=PLY_SC+1

  'REVERSE ROTATION IN 14 SECONDS AND KEEP ACTION UNTIL 21 SECONDS
  IF SEC<21 THEN
   IF SEC>14 AND SEC<15 THEN DG_SPD=6
   IF SEC<14 THEN PLY_DG=PLY_DG+DG_SPD ELSE PLY_DG=PLY_DG-DG_SPD
   XSCR=XSCR-XSPD
   XSPD=XSPD-0.2
   IF XSPD<0 THEN XSPD=0
  ELSE
   'COOL DOWN AFTER 21 SECONDS   
   XSCR=XSCR+XSPD
   XSPD=XSPD+1.4
   DG_SPD=DG_SPD-0.1
   IF DG_SPD<0 THEN DG_SPD=0
   IF PLY_DG>1 THEN PLY_DG=PLY_DG-4
   IF PLY_DG<4 THEN PLY_DG=1
  ENDIF

  'DECREASE SLIGHT THE SPEED
  DG_SPD=DG_SPD-0.001
  
  IF SEC>=6.5 AND SEC<=7.2 THEN
   'CHANGE SCALE BETWEEN SECONDS 7 AND 8
   PLY_SC=60+RND(1)*50
  ELSE
   'KEEP SCALE
   IF PLY_SC>70 THEN PLY_SC=80+RND(1)*10
  ENDIF

  TA=COS(RAD(PLY_DG))
  TB=COS(RAD(PLY_DG+180))
  TC=COS(RAD(PLY_DG*2))
  TS=SIN(RAD(PLY_DG))
  TD=COS(RAD(PLY_DG*20))

  'MOVE ELEMENTS
  PLY_MOVE(1,MAXX/2+TA*150+XSCR,MAXY/2+TC*80,(PLY_SC+TS*30)/11)
  PLY_MOVE(0,MAXX/2+TB*150+XSCR,MAXY/2+TC*80,(PLY_SC-TS*25-25)/11)

  'RUN PSEUDO 3D FLOOR  
  FLOOR_3D(PLY_DG,0,MAXY/2+TC*100+XSCR/2+30,MAXY/2+TC*100-XSCR/2-30,1,FL-127,FL-127,FL)

  'FLASH FLOOR
  IF FL>127 THEN FL=FL-10  
  IF FL<127 THEN FL=127
  IF Timer>FLASHNOW then FL=255: FLASHNOW=Timer+1500

  'FLASH ELEMENTS
  T=(FL-50)/127
  I=(FL/255)
  PLY_RGB(0,I,1+T,I)
  PLY_RGB(1,I,1+T,1+T)

  'DEPTH BETWEEN ELEMENTS
  IF TS>0 THEN PLY_ROT(0,PLY_DG,PLY_DG*1.5)
  PLY_ROT(1,PLY_DG/1.5,-PLY_DG*1.8)
  IF TS<=0 THEN PLY_ROT(0,PLY_DG,PLY_DG*1.5)

  'FIX BORDERS
  BOX 0,0,MAXX,MAXY,1,RGB(0,0,0)
  PAGE COPY 1 TO 0,I

 LOOP

END SUB

