hum... hi all!
i m searching for examples/lib to do the Gimp Color Wheel type inside my allegro/OL app.
Sure im to much weak in maths, so any help will be vry appreciated !
Any idea on how to draw the circular color wheel and draw the triangle, with H S V values ?
{"name":"Triangulo_HSV.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/d\/3dea04cb277c3c5280a768e8b9cb7c23.png","w":347,"h":347,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/d\/3dea04cb277c3c5280a768e8b9cb7c23"}
Drawing the hue circle should be easy :
Draw the radius of the outer edge of the circle in a fully saturated, fully valued hue over 360 degrees. Draw a filled circle with a smaller radius over the top using the bitmap mask color. This one can easily be a pre-drawn overlay.
The saturation and value triangle will be more difficult and you will probably have to redraw it each time the hue changes unless you limit the different number of hues allowed. For example 360 different pre-drawn saturation value triangles might not be too much of a strain on memory, but it depends on how large they are.
The triangle itself is basically composed of a set of gradient line segments that get shorter and shorter as you move down and left in the triangle. I would write my own gradient line function for it. Pass the function the hue and the value of the current line and inside the function vary the saturation from 0.0 at one end gradually up to 1.0 at the other end of the line segment. Repeat this for each line the triangle is composed of, varying the color value as you move down and left.
Isn't there some Gouraud routines for drawing triangles in Allegro? You set the colour of each vertex of the triangle. Black, white, full saturated hue. Then let Allegro draw it.
[edit]
Apparently not. There's a non-rotated gouraud rectangle thing.
Drawing the hue circle should be easy
completely agriing Edgardo. But for the triangle I have NO idea about how to proceed. neither how to use a vector to print to screen the result of calculation in pixels.
does anybody knows where the libs that were on allegro once gone ? : altheme / http://www.allegro.cc/go.php?http://www.the-good-stuff.freeserve.co.uk/allegro/gui/mage/ ?
Gimp is open source, so you COULD take a look at the source code to see how they do it.::) I don't really have a clue off hand how to do the triangle...the circle would be relatively easy.
You set the colour of each vertex of the triangle.
For sure OpenGL can do it.
glBegin(GLTRIANGLES); glColor(somecolor); glVertex(coords); glColor(somecolor); glVertex(coords); glColor(somecolor); glVertex(coords); glEnd();
Well, or something like this.
Isn't there some Gouraud routines for drawing triangles in Allegro? You set the colour of each vertex of the triangle. Black, white, full saturated hue. Then let Allegro draw it.
[edit]
Apparently not. There's a non-rotated gouraud rectangle thing.
Yes there is.void triangle3d_f(BITMAP *bmp, int type, BITMAP *tex, V3D_f *v1, *v2, *v3);With POLYTYPE_GCOL as the type. You'll have to check for yourself if it can be used as-is for a WYSIWYG color picker though.
As for the rest of the implementation: I assume you're familiar with barycentric coordinates? If not, read up on them now...
I'd do the triangle like this:
1. Calculate the coordinates of the three vertices.
2. Think of the triangle as a set of horizontal lines.
2.1. Calculate start and end point of each line.
2.2. Calculate the colour of the start point and end point by interpolating between the two vertices in concern.
2.3. Draw each pixel of the horizontal line by interpolating between the start and end point.
Another way would be to draw the gouraud rectangle and mask it to a triangle and rotate_blit it.
thxs... i keep you in touch about this....
I'm a little confused why you are ignoring gnolam's suggestion... but I guess if you are willing to wait, I'll have a gouraud shaded triangle ready in a day or two for A5, and I can give it to you.
Yes, don't use my re-invented wheel. Do what Gnolam said. This I did in 4 minutes.
{"name":"596636","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/6\/767fbfead20af16f20e2dc1650870c7b.png","w":336,"h":331,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/6\/767fbfead20af16f20e2dc1650870c7b"}
The actual colour picking I would do with getpixel from that triangle. It won't contain all possible values in RGB space, at least the Gimp colour picker is so small that it skips over a lot of values stepping from one pixel to the next. But that can be adjusted with the sliders, if you have a slider for each channel.
Assuming you drew it correctly, that triangle is basically a wedge out the (V, S) plane, tilted at an odd angle.
Drawing the plane should be easy, so too is removing the wedge. I'm guessing that you have to remove the 45 degree edge. In the picture, the triangle is equilateral, which you can get by stretching one of the axes in the plane by sqrt(2). All you then have to do is rotate the triangle, which shouldn't cause you too much of a headache.
My code:
1 | set_color_depth(32); |
2 | if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)) { |
3 | allegro_message("Error setting 320x200x8 gfx mode:\n%s\n", allegro_error); |
4 | return -1; |
5 | } |
6 | V3D_f v1 = |
7 | { |
8 | 200., 50., 0, |
9 | 0., 0., |
10 | makecol(0, 0, 0) // black vertex |
11 | }; |
12 | V3D_f v2 = |
13 | { |
14 | 150., 350., 0, |
15 | 0., 0., |
16 | makecol(255, 255, 255) // white vertex |
17 | }; |
18 | V3D_f v3 = |
19 | { |
20 | 400., 150., 0, |
21 | 0., 0., |
22 | makecol(255, 0, 0) // red vertex |
23 | }; |
24 | |
25 | clear_to_color(screen, makecol(128, 128, 128)); |
26 | triangle3d_f(screen, POLYTYPE_GCOL, NULL, &v1, &v2, &v3); |
27 | |
28 | textout_centre_ex(screen, font, "Hello, world!", 160, 96, makecol(0, 0, 0), -1); |
So I just threw some coordinates there. For each vertex z is zero. It was by no means an equilateral triangle. It would have taken some more minutes to find out the coordinates for it. I would probably use a class I have for rotating coordinates.
woaw... quickly done ! thanks a lot for all your help.
this rocks... i was perparing myself for a painfull time trying to adapt barywhitecentric esoteric equations.... didnt now anything about this magnifical type of POLYTYPE GCOL.....
merci one thosuand times:):):)!
barywhitecentric: I am perhaps the only one to get that one as it should be, hilarious !
C'est quand même cool le forum allegro, il est rare de ne pas y trouver de l'aide ou une direction pour chercher !
OK, j'avoue, j'ai hâte de voir ton nouveau projet, stouf !