FadeScreen-Func

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Stormy
Posts: 198
Joined: May 28, 2005 17:57
Location: Germany
Contact:

FadeScreen-Func

Post by Stormy »

Code: Select all

DECLARE SUB FadeScreen (Amount, X, Y, X2, Y2)
DIM T(2) AS SINGLE ' TIMER
SCREEN 14,16,2,&H1 ' 320x200 16bit, 2pages, fullscreen
SCREENSET 0,1
RANDOMIZE TIMER

' Fill screen with some stuff

Circles = 50
FOR i = 1 TO Circles
 X = INT(RND * 320) + 1
 Y = INT(RND * 240) + 1
 Size = INT(RND * 50) + 1
 r = INT(RND * 256) + 1
 g = INT(RND * 256) + 1
 b = INT(RND * 256) + 1
 CIRCLE (X, Y), Size, RGB(r,g,b), , , , F
NEXT i

 LOCATE 1: PRINT "Press any key..."

SCREENCOPY: SLEEP

T(1) = TIMER

FOR i = 1 TO 16
 FadeScreen (-16, 0, 0, 320, 240)
 WAIT &h3DA, 8
 SCREENCOPY 
NEXT i

T(2) = TIMER

LOCATE 1: PRINT "Finished in "; (T(2) - T(1)); " Seconds..."

SCREENCOPY: SLEEP

SUB FadeScreen (Amount, X, Y, X2, Y2)
DIM col AS LONG, c(3) AS INTEGER
FOR e = X TO X2
 FOR i = Y TO Y2
   col = POINT(e,i)
   c(1) = (col SHR 16) AND &hFF 
   c(2) = (col SHR 8) AND &hFF 
   c(3) = col AND &hFF
    FOR t = 1 TO 3
     c(t) +=  Amount
     IF c(t) < 0 THEN c(t) = 0
     IF c(t) > 255 THEN c(t) = 255
    NEXT t
   PSET(e,i), RGB(c(1),c(2),c(3))
 NEXT i
NEXT e
END SUB
Feel free and use this function ;) But there is still a little bug in it, i cant figure out. If u alter the code in:

Code: Select all

FOR i = 1 TO 256
 FadeScreen (-1, 0, 0, 320, 240)
 WAIT &h3DA, 8
 SCREENCOPY 
NEXT i
The screen wont get really black... suggestions are welcome ! =)
Adigun A. Polack
Posts: 234
Joined: May 27, 2005 15:14
Contact:

Very nice start, Stormy!

Post by Adigun A. Polack »

Stormy, your full-screen fader in 16-bit works actually well on the computer that I use, and I believe that it is truly a good start for you here, so well done on that! :D

And really good fortune to you in your FB programming, too! ;) !
Stormy
Posts: 198
Joined: May 28, 2005 17:57
Location: Germany
Contact:

Post by Stormy »

Thanks for the flowers ! :)
Post Reply