Re: 100 Different Colors



You are dividing first and getting an int 0 * G_MAXUINT16

in the line

 c.green = i/99 * G_MAXUINT16;

Multiply first and then divide. you might need a long int tmp to hold the 
value prior to assigning to c.green. By dividing first you basically are 
doing a multiply by 0 and that is why it is 0 until i = 99 which when divided 
by 99 will give you 1. Then multiple 1 x G_MAXUINT16 will give G_MAXUINT16 or 
65535. 

So the next line might be better.

 c.green = (i * G_MAXUINT16) / 99;

Kevin

On Tuesday 21 June 2005 01:33 pm, Lola Smith wrote:
Before your call to gdk_set_rgb_fg_color, do a
g_print on the values of
c.red, c.blue, c.green, and i.  You may be surprised
at what you see.

You're right. They're all the same thoughout the loop.
red = 65535, blue = 0, green = 0, except at the very
end green = 65535 (hence the yellow color). I figured
this is because they are integers, not doubles.

So, how is it possible to change the colors inside the
loop?

Sorry, I'm pretty clueless right now... :-(
Any help is appreciated!

-----Original Message-----
From: gtk-app-devel-list-bounces gnome org

[mailto:gtk-app-devel-list-

bounces gnome org] On Behalf Of Lola Smith
Sent: Tuesday, June 21, 2005 11:10 AM
To: gtk-app-devel-list gnome org
Subject: Re: 100 Different Colors

Jan-Marek, thanks for your response.

I tried this:
for (i=0; i<100; i++) {
  c.pixel = 0;
  c.red   = G_MAXUINT16;
  c.blue  = (i % 33 / 99) * G_MAXUINT16;
  c.green = i/99 * G_MAXUINT16;
  gdk_gc_set_rgb_fg_color( gc, &c );
  gdk_draw_rectangle (widget->window, gc, TRUE,

i*15,

    0, 11, 11);
}

But all the squares are red now, with the

exception of

the last one (100th), which is yellow.
Do I have to change the value of c.red inside the

for

loop as well? Maybe something related to i?

Btw, I am using gtk version 2.2, which didn't have
G_MAXUINT16, so I defined it like:

#define G_MAXUINT16 ((guint16) 0xffff)

Can someone help? Thaaank you!

--- Jan-Marek Glogowski <glogow fbihome de> wrote:
Hi

I need to create 100 little squares and each

of

them

has to be a different color. They can't just

be a

random color: they have to follow the colors

of

the

standard color spectrum/palette. For example,

the

first one is dark blue, then lighter blue, ...

,

green, ... , red.

Std. color spectrum? Maybe like the circle in

the

GtkColorSelectionDialog?

Algo:
r = max, g = 0, b = 0
r = max , g = max, b = 0
r = 0, g = max, b = 0
r = 0, g = max, b = max
r = 0, g = 0, b = max
r = max, g = 0, b = max
back to step 1

See GtkColorSelection source

From the GDK Manual:

gdk_gc_set_rgb_fg_color () - set the foreground
color of a GC using an
unallocated color.

GdkColor - red, green, blue ... is a value

between 0

and 65535, with 65535
indicating full intensitiy.

GdkGC *gc;
GdkColor c;

gc = gdk_gc_new (widget->window);

for (i=0; i<100; i++) {
  c.pixel = 0;
  c.red   = G_MAXUINT16;
  c.blue  = (i % 33 / 99) * G_MAXUINT16;
  c.green = i/99 * G_MAXUINT16;
  gdk_gc_set_rgb_fg_color( gc, &c );
  gdk_draw_rectangle (widget->window, gc, TRUE,
i*15,
    0, 11, 11);
}

HTH

Jan-Marek

____________________________________________________

Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy

Football

http://football.fantasysports.yahoo.com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]