The Random Code: Fading Routines

Announce and discuss the progress of your various programming-related projects...programs, games, websites, tutorials, libraries...anything!

Moderators: Pete, Mods

Post Reply
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

The Random Code: Fading Routines

Post by Mitth'raw'nuruodo »

Hey everybody!
Well for some reason I needed a break, and started programming randomly and this is what I came up with in 20 min.:

Code: Select all

DECLARE SUB getpic (fadetitle() AS ANY, title$)
DECLARE SUB fadein (fadetitle() AS ANY, X%, Y%, seconds%)
DECLARE SUB fadeout (fadetitle() AS ANY, X%, Y%, seconds%)

CLEAR
CLS

TYPE fadetitletype
  X AS INTEGER
  Y AS INTEGER
  index AS INTEGER
  col AS INTEGER
END TYPE
REDIM fadetitle(0) AS fadetitletype

SCREEN 13
RANDOMIZE TIMER

title$ = "This is the Title, Must be 1 line long"
getpic fadetitle(), title$

'----TEST OUTPUT----|
CLS
'(x, y) of title (They are centered below)
X% = 159 - (fadetitle(0).X + fadetitle(UBOUND(fadetitle)).X / 2)
Y% = 99 - (7 / 2)

LOCATE 1, 1: PRINT "Fading in: "
fadein fadetitle(), X%, Y%, 3
LOCATE 2, 1: PRINT "Press any key"

DO: LOOP WHILE INKEY$ = ""
LINE (0, 0)-(319, 16), 0, BF    'CLS for top output

LOCATE 1, 1: PRINT "Fading out: "
fadeout fadetitle(), X%, Y%, 3
LOCATE 2, 1: PRINT "Press any key to exit"

COLOR 0
END

SUB fadein (fadetitle() AS fadetitletype, X%, Y%, seconds%)

FOR i% = 0 TO UBOUND(fadetitle)
    fadetitle(i%).index = INT(RND * (10 * seconds% - 0 + 1) + 0)
NEXT i%

FOR k% = 0 TO 10 * seconds%
  FOR i% = 0 TO UBOUND(fadetitle)
   IF fadetitle(i%).index = k% THEN
      PSET (fadetitle(i%).X + X%, fadetitle(i%).Y + Y%), fadetitle(i%).col
   END IF
  NEXT i%
  timeri! = TIMER
  DO: LOOP UNTIL TIMER - timeri! > .01
NEXT k%
END SUB

SUB fadeout (fadetitle() AS fadetitletype, X%, Y%, seconds%)

FOR i% = 0 TO UBOUND(fadetitle)
    fadetitle(i%).index = INT(RND * (10 * seconds% - 0 + 1) + 0)
NEXT i%

FOR k% = 0 TO 10 * seconds%
  FOR i% = 0 TO UBOUND(fadetitle)
   IF fadetitle(i%).index = k% THEN
      PSET (fadetitle(i%).X + X%, fadetitle(i%).Y + Y%), 0
   END IF
  NEXT i%
  timeri! = TIMER
  DO: LOOP UNTIL TIMER - timeri! > .01
NEXT k%

END SUB

SUB getpic (fadetitle() AS fadetitletype, title$)

LOCATE 1, 1: PRINT title$

'|----GET SIZE----|
size% = -1
FOR i% = 0 TO 319
 FOR j% = 0 TO 7
    col% = POINT(i%, j%)
    IF col% <> 0 THEN
       size% = size% + 1
    END IF
 NEXT j%
NEXT i%

'|---GET ARRAY-----|
REDIM fadetitle(size%) AS fadetitletype

fadetitlei% = -1
FOR i% = 0 TO 319
  FOR j% = 0 TO 7
     col% = POINT(i%, j%)
     IF col% <> 0 THEN
       fadetitlei% = fadetitlei% + 1
       fadetitle(fadetitlei%).X = i%
       fadetitle(fadetitlei%).Y = j%
       fadetitle(fadetitlei%).col = col%
     END IF
  NEXT j%
NEXT i%

END SUB
It's a demo on some fading routines. Enjoy this random code! :D
"But...It was so beutifully done"
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

OK... but if you program randomly, wouldn't you just get a bunch of completly random statements that do absolutly nothing???
Image
Post Reply