old gradient trick

General FreeBASIC programming questions.
Post Reply
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

old gradient trick

Post by bluatigro »

this is from the time that colors had les shades
and i had to inprovise gradient's
the amiga had 16 shades
it can be useful if you have a screen whit les bitdepth
or if you think you need more than 255 shades

Code: Select all

screen 20 , 32
dim as integer winx , winy
screeninfo winx , winy
dim as double x , y
for x = 0 to winx
  for y = 0 to winy
    if rnd + x / winx > 1 then
      pset ( x , y ) , &hffffff
    end if
  next y
next x
sleep 
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: old gradient trick

Post by marcov »

Most rnds use mods, and it seems the tricks only avoids a division. So the benefit seems a bit dubious to me.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: old gradient trick

Post by counting_pine »

I quite like that monochrome gradient effect. It would be interesting to see how it might scale to three or more colours.
There is room for some optimisation. You loop over x in the outer loop, which means you could cache the ‘x / winx’ value every column.
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: old gradient trick

Post by bluatigro »

Code: Select all

screen 20 , 32
dim as ulong kl( 4 ) , i
for i = 0 to 3
  read kl( i )
next i
data 0 , &h3333 , &h7777 , &hffff 
dim as integer winx , winy
screeninfo winx , winy
dim as double x , y , q
for x = 0 to winx
  q = x / winx * 3
  for y = 0 to winy
    pset ( x , y ) , kl( int( rnd + q ) )
  next y
next x
sleep 
Post Reply