'---- 3D EARTH WITH TEXT DEMO ----


'-- INITIALIZE 3D EARTH TEXT DEMO ----

SUB INIT_DEMO_3D_EARTH_TEXT

 LOCAL T,TL,TR

 T=0
 TXT$(T) = "                   ": T=T+1
 TXT$(T) = "Now let's make justice for the music composers! ": T=T+1
 TXT$(T) = "In order of listening: ": T=T+1
 TXT$(T) = "Neon Techno! by DROZERiX,  ": T=T+1
 TXT$(T) = "Econmy17 by xtd / mystic * trsi,  ": T=T+1
 TXT$(T) = "Excelatte by Probe (FLT / VD) from demo Psychedelic,  ": T=T+1
 TXT$(T) = "Flow1 (Floating in the ocean of sound) by mortimer t ... ": T=T+1
 TXT$(T) = "Great tunes, guys!  ...  And thank YOU for watching this demo!! ": T=T+1
 TXT$(T) = "                                                                 "+chr$(27): T=T+1
 MAXTXT=T-1

 FOR T=0 TO 25
  RESET_STAR_SIDE(T,1)
 NEXT T
 FOR T=0 TO 100
  STARFIELD_SIDE(25,2)
 NEXT T

 MAXX=MM.HRES: MAXY=MM.VRES

 EX=MAXX/2-125: EY=MAXY/2-125

 'PAGE 3 - ONLY "CLEANING THE ROOM"
 PAGE WRITE 3: BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

 'PAGE 4 - CLEAR PAGE 4 (FOR TEXT)
 PAGE WRITE 4: BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

 'PAGE 2 - EARTH 
 PAGE WRITE 2: BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)
 LOAD PNG "./ASSETS/EARTH.PNG"

 'PAGE 3 - "SHADOW MASK"
 PAGE WRITE 3: BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)
 'DRAW INTERLACED "SHADOW MASK"
 FOR T=0 TO 250 STEP 2
  LINE 0,T,250,T,1,RGB(30,30,30)
 NEXT T
 'CLEAR INSIDE EARTH
 CIRCLE 125,125,118,0,1,,RGB(0,0,0)

 'SET PAGE 1 BUFFER
 PAGE WRITE 1: BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

 PLAY STOP
 PLAY MODFILE "./ASSETS/flow1.mod",22050

END SUB


'-- RUN 3D EARTH TEXT DEMO --

SUB RUN_DEMO_3D_EARTH_TEXT

 LOCAL T,ER,TR
 LOCAL COTXT,ROTXT,OTXT$
 LOCAL CTXT,RTXT,LTXT,MTXT$,CR,CG,CB
 LOCAL CCTXT,RRTXT,LLTXT,XF,YF

 XF=MAXX:YF=MAXY/2
 
 CTXT=0: RTXT=0

 COTXT=45: ROTXT=MAXTXT: STXT=0

 PAUSETIMER=0: TIMENOW=0: Timer=0

 DO WHILE SEC<=128

  SEC=Timer/1000

  'CLEAR BUFFER PAGE
  BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

  '"ROTATE" EARTH
  ER=ER+4: IF ER>MAXX-8 THEN ER=ER-(MAXX-8)  

  T=0:TT=0
  DO WHILE T<255
   I= ABS(TAN(RAD(107+T/1.7)    )*15)
   II=ABS(TAN(RAD(107+(T+5)/1.7))*15)
   IF I<5 THEN I=5
   IF I>120 THEN I=120
   IF II<5 THEN II=5
   IF II>120 THEN II=120
   C=TAN(RAD(90+(T-5)/1.42))*4
   IF C<5 THEN C=5
   IF C>15 THEN C=15
   'IF C>10 THEN C=10
   IMAGE WARP_H TT,0,C,250,  T+EX,I+70,260-I*2,  T+EX+5,II+70,260-II*2, 2,0
   T=T+5
   TT=TT+C
  LOOP
  PAGE SCROLL 2,-4,0

  'INSERT "SHADOW MASK"
  'BLIT 0,0,EX,EY,251,251,3,4

  'CLEAR OUTSIDE EARTH
  T=RGB(0,0,0)
  CIRCLE EX+125,EY+125,125+15,15,1,T
  TRIANGLE EX-4,EY,       EX+68,EY,      EX-4,EY+68,    T,T
  TRIANGLE EX-4,EY+250,   EX+68,EY+250,  EX-4,EY+182,   T,T
  TRIANGLE EX+254,EY,     EX+182,EY,     EX+254,EY+68,  T,T
  TRIANGLE EX+254,EY+250, EX+182,EY+250, EX+254,EY+182, T,T

  'ROLLING TEXT
  PAGE WRITE 4: BOX 0,YF,MAXX,YF+60,0,,RGB(0,0,0)
 
  'TEXT CONTROL
  STXT=STXT+10'-(1-SWT)*5
  IF STXT>34 THEN
 
   STXT=STXT-34

   'SEEK FOREGROUND TEXT
   CTXT=CTXT+1
   IF CTXT>LEN(TXT$(RTXT)) THEN CTXT=1: RTXT=RTXT+1
   IF RTXT>MAXTXT THEN RTXT=0

   'BUILD STRING FOR FOREGROUND TEXT
   RRTXT=RTXT:CCTXT=CTXT:MTXT$=""
   FOR T=1 TO 19
    MTXT$=MTXT$+CHR$(PEEK(VAR TXT$(RRTXT),CCTXT))
    IF PEEK(VAR TXT$(RRTXT),CCTXT) = 27 THEN SEC=300 'END DEMO
    CCTXT=CCTXT+1
    IF CCTXT>LEN(TXT$(RRTXT)) THEN CCTXT=1: RRTXT=RRTXT+1
    IF RRTXT>MAXTXT THEN RRTXT=0
   NEXT T

   'SEEK BACKGROUND TEXT
   COTXT=COTXT+1
   IF COTXT>LEN(TXT$(ROTXT)) THEN COTXT=1: ROTXT=ROTXT+1
   IF ROTXT>MAXTXT THEN ROTXT=0

   'BUILD STRING FOR BACKGROUND TEXT
   RRTXT=ROTXT:CCTXT=COTXT:OTXT$=""
   FOR T=1 TO 19
    OTXT$=OTXT$+CHR$(PEEK(VAR TXT$(RRTXT),CCTXT))
    CCTXT=CCTXT+1
    IF CCTXT>LEN(TXT$(RRTXT)) THEN CCTXT=1: RRTXT=RRTXT+1
    IF RRTXT>MAXTXT THEN RRTXT=0
   NEXT T

  ENDIF

  IF Timer MOD 550 < 100 THEN CR=255:CG=255:CB=255
  CG=CG-50:CB=CB-50
  IF CR<200 THEN CR=200
  IF CG< 50 THEN CG= 50
  IF CB< 50 THEN CB= 50

  'INSERT BACKGROUND TEXT ON THE TEMPORARY BUFFER
  TEXT -STXT/2+XE+50,0,OTXT$,LT,7,3,RGB((CR-50)/2,(CG-50)/2,(CB-50)/2),0

  'INSERT FRONT TEXT ON THE TEMPORARY BUFFER WITH COLOR DEPTH CHANGE
  TEXT -STXT,YF,MTXT$,LT,7,6,RGB(CR,CG,CB),0
  TEXT -STXT,YF,LEFT$(MTXT$,4),LT,7,6,RGB(CR-50,CG-50,CB-50),0
  TEXT -STXT,YF,LEFT$(MTXT$,3),LT,7,6,RGB(CR-50,CG-50,CB-50),0

  'SET MAIN BUFFER PAGE
  PAGE WRITE 1

  'WRITE BACKGROUND TEXT IN THE MAIN BUFFER
  BLIT 60,0,XE+447,MAXY/2-8,200,22,4,1

  'WRITE FRONT TEXT IN THE MAIN BUFFER PAGE
  BLIT 200,YF,200,YF,MAXX-200,43,4,4

  'DISTORT TEXT TO CHANGE THE SIZE
  TT=11:I=4.85:II=-23.1:TSPDA=0.14:TSPDB=-0.84
  FOR T=144 TO 73 STEP -1
   I=I+TSPDA: TSPDA=TSPDA-0.002
   II=II+TSPDB: TSPDB=TSPDB-0.015
   TT=TT-0.07
   FOR TTT=0 TO 3
    BLIT T,YF+11*TTT,T-II,YF-I+TT*TTT,1,11,4,4
   NEXT TTT
  NEXT T

  'ROTATE TEXT FROM FRONT TO BACKSIDE OF THE EARTH
  I=1:II=0: TSPDA=0: TSPDB=0
  FOR T=200 TO 145 STEP -1
   I=I+TSPDA: TSPDA=TSPDA+0.0025: IF TSPDA>0.2 THEN TSPDA=0.2
   II=II+TSPDB: TSPDB=TSPDB-0.015
   BLIT T,YF,T-II,YF-I,1,43,4,4
  NEXT T

  'RENDER STARFIELD
  STARFIELD_SIDE(25,2)

  'FPS CAP
  FPS(15)

  'COPY TO MAIN PAGE
  PAGE COPY 1 TO 0,I
 
 LOOP
 
END SUB



