old gradient trick

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

old gradient trick

Postby bluatigro » Jul 24, 2018 12:55

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: 2839
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: old gradient trick

Postby marcov » Jul 25, 2018 19:03

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: 6180
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: old gradient trick

Postby counting_pine » Jul 25, 2018 19:31

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: 647
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: old gradient trick

Postby bluatigro » Jul 27, 2018 4:41

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

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests