Re: iterating through colors

Search this archive.

From: Sergio Masci (sergio@titan.demon.co.uk)
Date: Fri 14 Jul 2000 - 19:53:40 IDT


OK, well first off I made a mistake in the 0x2f part of my post. This
should have read 0x3f (binary 111111) not 0x2f (binary 101111). This
affects both my example and the subsequent file you [Patrick] posted.

Secondly to be able to do a smooth transition between any two colours
that have three colour components you need to be able to plot a straight
line between the two colours in 3D space. Think of each of your colour
components as a dimension. This is where the RGB colour cube that you
may have seen references to comes from. It is not possible to map every
colour in this cube onto a flat 2D surface without having breaks in
continuity.

Thirdly, while trying to get svgalib working on a new test machine that
has suse 6.4 on it (Patrick has a lot to answer for) I came across
vgatest (a program I haven't used in years and had forgotten even
existed). This program gives a very interesting test pattern in mode 18
and 24. Maybe this could be used as the basis for your colour selection
(I think each of the six squares is actually a surface of the colour
cube) Useing these squares you should be able to access about 31*31*6
colours (you will still be missing the other 31*31*57 so you will need
to add sliders or something to move into the cube, but the blending
looks good for the colours used).

Lastly, having tried your [Patrick's] code I am inclined to change the
1.5 constant to 1 (having corrected the 0x2f problem). To get rid of the
moir (spelling?) pattern you will need to generate the lines either
vertically or horizontally

Regards
Sergio


> 
> Thanks for the example, but it wasn't quite _exactly_ what I was looking
> for.  I've attached a file with what I was trying to do (well, for the
> most part).  I haven't quite got a smooth transition to and from
> green:  it uses 6 bits while red and blue use 5, so I increment and
> decrement green by 1.5, since its max value is 0x2f, (~1.5 * 0x1f)...but
> is' not smooth...
> 
> 
> On Tue, 11 Jul 2000, Sergio Masci wrote:
> 
> > > This is another generic graphics programming question, but hopefully
> > > someone will know the answer.
> > > 
> > > How do I iteratate through the colors?  It seems like it should be simple,
> > > but it's not behaving as expected.  I'm writing a little something that
> > > draws a color wheel on the screen at 800x600x64K.  Just for kicks, suppose
> > > that it's just drawing vertical lines, so the code looks like this:
> > > 
> > > ...
> > > color = 0;
> > > for (xnow = 0; xnow < xmax; xnow++)
> > >   gl_line(xnow,0,xnow,ymax,color++);
> > > ...
> > > 
> > > I come up with about 13 identical sections of color fading.
> > > the same happens if I do 
> > > 
> > > vga_setcolor(color++);
> > > vga_drawline(xnow,0,xnow,ymax);
> > > 
> > > 
> > > Is there a way that I can do what I am trying simply?
> > > 
> > > Regards,
> > > 
> > > -patrick
> > 
> > 
> > I don't use the gl libraries or the vga_setcolor or vga_drawline
> > functions so I cannot give a concrete answer BUT it looks to me as
> > though the colour is a direct copy of the hardware pixel used in the
> > 800x600x64K mode. In this mode the colours are packed into a 16 bit word
> > something like 6:5:5 or 6:6:4 I cannot remember exactly.
> > 
> > Try experimenting with the following:
> > 
> > float	fx, fy, fz;
> > int	x, y
> > 	red, green, blue, pixel;
> > 
> > for (x=0; x<800; x++)
> > {
> > 	for (y=0; y<600; y++)
> > 	{
> > 		fx = (float)x / 799;
> > 		fy = (float)y / 599;
> > 		fz = sqrt(x * x + y * y) / sqrt(799*799 + 599*599);
> > 
> > 		red   = 0x2f * fx;
> > 		blue  = 0x1f * fy;
> > 		green = 0x1f * fz;
> > 
> > 		pixel = (red << 10) | (green << 5) | blue;
> > 
> > 		vga_setcolor(pixel);
> > 		vga_drawline(x,y,x,y);
> > 	}
> > }
> > 
> > You should end up with a box, one corner of which should be black,
> > diagnally opposit will be white, one other corner should be blue and the
> > last should be red (no pure green since this component is generated from
> > blue and red and so does not exist in this square without them).
> > 
> > Regards
> > Sergio
> > 
> 


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST