Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » color picker ( continuing...): rotating triangle ? or interpolating X and y ?

Credits go to Johan Halmén for helping out!
This thread is locked; no one can reply to it. rss feed Print
color picker ( continuing...): rotating triangle ? or interpolating X and y ?
karistouf
Member #5,126
October 2004
avatar

hi everybody...

finally continuing this topic....

{"name":"596641","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/8\/c82856649779aed183b067e5e0f22817.jpg","w":271,"h":274,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/8\/c82856649779aed183b067e5e0f22817"}596641

sure it will be once again something very simple , but ....
How to obtain coordonnates of the Black side and the White Side of my triangle, knowing my r and hue sommit , as we move the hue with mouse ??

1float position_curseur_hue_x, position_curseur_hue_y;//mouse position on click= HUE
2float vx, vy;//
3float vxh,vyh;//triangle HUe position
4float vxd,vyd;//triangle Dark position
5flaot vxw,vyw;//triangle white position
6 
7int Interface_Trichromie(int xchroma, int ychroma, int rayon, int largeurchroma)
8{
9for(float angle = 0 ; angle < 360 ; angle++)
10{
11 
12 vx = cos(angle* 3.14116/180)*rayon;
13 vy = sin(angle* 3.14116/180)*rayon;
14 Line(Vec2D(xchroma+vx,ychroma+vy),Vec2D(xchroma+vx+1,ychroma+vy+1)).Draw( CouleurLigne );
15 
16 if(mouse_x>xchroma+vx-10 && mouse_x< xchroma+vx+10 && mouse_y>ychroma+vy-10 && mouse_y<ychroma+vy+10)
17 {
18 if (mouse_b&1)//setting hue summit
19 {
20 position_curseur_hue_x=xchroma+vx;
21 position_curseur_hue_y=ychroma+vy;
22 vxh = cos(angle* 3.14116/180)*(rayon-15); //hue triangle position
23 vyh = sin(angle* 3.14116/180)*(rayon-15);
24 }
25 }
26}
27 Circle monCurseurHue( Vec2D( position_curseur_hue_x,position_curseur_hue_y ), 12 );
28 monCurseurHue.SetLineWidth(epaisseur_ligne_fader*1.5);
29 monCurseurHue.DrawOutline( Rgba::BLACK );
30
31 //triangle
32 V3D_f v1 =
33 {
34 xchroma+vxd, ychroma+vyd, 0,
35 0., 0.,
36 makecol(0, 0, 0) // black vertex
37 };
38 V3D_f v2 =
39 {
40 150., 350., 0,
41 0., 0.,
42 makecol(255, 255, 255) // white vertex
43 };
44 V3D_f v3 =
45 {
46 xchroma+vxh, ychroma+vyh, 0,
47 0., 0.,
48 makecol(255, 0, 0) // color vertex
49 };
50
51 triangle3d_f(screen, POLYTYPE_GCOL, NULL, &v1, &v2, &v3);
52
53return(0);
54}

Johan Halmén
Member #1,550
September 2001

You got the red vertex angle, right? Add pi*2/3 to it and you get one of them. Add pi*4/3 to get the other one. That's adding 120° and 240°. That's how far the vertices are from each other along the circle, right?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Matt Smith
Member #783
November 2000

Here's a complete working example as an Allegro GUI widget. Not tested since the file date >:)

karistouf
Member #5,126
October 2004
avatar

thanks ! this was pi*4/3 i was missing (and the fact once upon a time i learned that a triangle sum of angle should b 360°)! cheers ! and thxs mat for this nice bit of code, I would look at it closely and carefully ! ;-)

Johan Halmén
Member #1,550
September 2001

Matt, you probably spoiled the fun! Help is supposed to be given bit by bit (or byte by byte :P), so that the person still feels he did it all by himself.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

karistouf
Member #5,126
October 2004
avatar

hum... do not worry about the fun ;-)

Go to: