## My spiffy screen 13 palette fader...

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

Moderators: Pete, Mods

Nemesis
Coder
Posts: 36
Joined: Mon Aug 16, 2004 12:54 pm

### My spiffy screen 13 palette fader...

Hi, just got back into doing some programming in QB. It's been almost 2 yrs. since I last coded. Anyways, what I was wanting to do first was to improve the quality of my palette fade in/out routines.
What I did was instead of decreasing a colors rgb intensity every cycle,
like most other fading routines, I decreased the colors rgb intensity more

Code: Select all

``````'
DEFINT A-Z
'
TYPE PALdata
Red AS INTEGER
Grn AS INTEGER
Blu AS INTEGER
END TYPE
'
DIM SHARED PAL(255) AS PALdata
'
SCREEN 13
'
OUT &H3C7, 0
'
FOR x = 0 TO 255
PAL(x).Red = INP(&H3C9)
PAL(x).Grn = INP(&H3C9)
PAL(x).Blu = INP(&H3C9)
NEXT
'
FOR y = 0 TO 199
FOR x = 0 TO 319
PSET (x, y), INT(RND(1) * 254 + 1)
NEXT
NEXT
'
COLOR 15: LOCATE 13, 12: PRINT "...Press a key..."
'
DO: LOOP UNTIL INKEY\$ <> INKEY\$
'
OUT &H3C8, 0
'
FOR y = 1 TO 64
FOR x = 0 TO 255
r = PAL(x).Red - (y * (PAL(x).Red / 64))
g = PAL(x).Grn - (y * (PAL(x).Grn / 64))
b = PAL(x).Blu - (y * (PAL(x).Blu / 64))
OUT &H3C9, r
OUT &H3C9, g
OUT &H3C9, b
NEXT
WAIT &H3DA, 8
NEXT
'
FOR y = 1 TO 64
FOR x = 0 TO 255
r = y * (PAL(x).Red / 64)
g = y * (PAL(x).Grn / 64)
b = y * (PAL(x).Blu / 64)
OUT &H3C9, r
OUT &H3C9, g
OUT &H3C9, b
NEXT
WAIT &H3DA, 8
NEXT
'
SYSTEM
'
``````
Cya, Nemesis.

p.s..I was thinking maybe writing a tutorial or something to explain the code in detail, step by step. What do you guys think?

BDZ
Coder
Posts: 49
Joined: Sun Nov 20, 2005 5:41 pm
Location: Wisconsin
Contact:
That's funny. I have one that I wrote that's very similar to that. I was disatisfied with the ones I found in tutorials that looked very fakey.

Mine also pregenerates each inner loop (x in your case) to a temporary array, then puts that out to the video card in a separate inner loop. The result: a flickerless fade. (Your code would probably cause some flicker in the top quarter of the screen on my PIII 500mhz.)

Nemesis
Coder
Posts: 36
Joined: Mon Aug 16, 2004 12:54 pm
So pretty much, with just a couple more lines of code, this routine
could be used for palette to palette fades also.
Anyways, here's the final fading routine that I'll be using in my gfx lib...

Code: Select all

``````'
DEFINT A-Z
'
TYPE PALdata
Red AS INTEGER
Grn AS INTEGER
Blu AS INTEGER
END TYPE
'
DIM SHARED PAL(255) AS PALdata
'
SCREEN 13
'
OUT &H3C7, 0
'
FOR x = 0 TO 255
PAL(x).Red = INP(&H3C9)
PAL(x).Grn = INP(&H3C9)
PAL(x).Blu = INP(&H3C9)
NEXT
'
FOR y = 0 TO 199
FOR x = 0 TO 319
PSET (x, y), INT(RND(1) * 254 + 1)
NEXT
NEXT
'
COLOR 15: LOCATE 13, 12: PRINT "...Press a key..."
'
DO: LOOP UNTIL INKEY\$ <> INKEY\$
'
c = 1 'Color of fade.
'
OUT &H3C8, 0
'
FOR y = 1 TO 64
FOR x = 0 TO 255
r = PAL(x).Red - (y * ((PAL(x).Red - PAL(c).Red) / 64))
g = PAL(x).Grn - (y * ((PAL(x).Grn - PAL(c).Grn) / 64))
b = PAL(x).Blu - (y * ((PAL(x).Blu - PAL(c).Blu) / 64))
OUT &H3C9, r
OUT &H3C9, g
OUT &H3C9, b
NEXT
t! = TIMER: DO: LOOP UNTIL TIMER <> t!
NEXT
'
DO: LOOP UNTIL INKEY\$ <> INKEY\$
'
FOR y = 1 TO 64
FOR x = 0 TO 255
r = PAL(c).Red + (y * ((PAL(x).Red - PAL(c).Red) / 64))
g = PAL(c).Grn + (y * ((PAL(x).Grn - PAL(c).Grn) / 64))
b = PAL(c).Blu + (y * ((PAL(x).Blu - PAL(c).Blu) / 64))
OUT &H3C9, r
OUT &H3C9, g
OUT &H3C9, b
NEXT
t! = TIMER: DO: LOOP UNTIL TIMER <> t!
NEXT
'
SYSTEM
'
``````
(Change the variable c for different colors of fade.)

Cya, Nemesis