We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › or || for "Complementary colors value excercise"
Page Index Toggle Pages: 1
or || for "Complementary colors value excercise" (Read 324 times)
or || for "Complementary colors value excercise"
Feb 16th, 2010, 12:41am
 
In the following app, the user's goal is to manipulate brightness (vertical mouse movement) and saturation (horizontal mouse movement) to attempt to have the center rectangle equal in value to the background. The center rect is always the complementary hue of the background.

My first question is super simple. I want the user to be able to move the mouse off the screen and have the saturation and brightness default back to 100. I am new to coding and tried to use the or logic with || but I got errors so I commented it out (see towards the end).

It would also be amazing if there was a way to code this so that when the user got the value of the rect and the background equal, there was a clue-- or flag that came up to confirm. When I say value I am refering to color value-- if a black and white conversion were made, equal value would leave the rect and the background equal gray-- we'd no longer see the rectangle.

(when value matches up with color, serious luminosity happens for the eyes)

any suggestions appreciated.
**

void setup()
{
 size(800, 600);
 stroke(255);
 frameRate(40);
}

float a = 0;      
float b = 400;  

//elements for rectangle in middle
float rx1;
float rw2;
float ry1;
float rh2;

//initial values (these probably get overridden by mouse)
float sat = 100;
float brite = 100;

void draw()
{
 colorMode(HSB, 360, 100, 100);
 background(a*360/width,sat,brite);

//create rectangle of complementary color
 rx1 = (width/2)-(width*0.15);
 ry1 = (height/2)-(0.15*height);
 rw2 = (0.3*width);
 rh2 = (0.3*height);

 fill(b*360/width, (200-sat), (200-brite));
 noStroke ();
 rect (rx1, ry1, rw2, rh2);


 a = a + 0.5;
 b = b + 0.5;
 stroke(255);
 line(a, 0, a, 0.02*height);
 line(b, 0.98*height, b, height);
 
 if(a > width) {
   a = 0;
 }
 if(b > width) {
   b = 0;
 }
 
//  if ((mouseX = width) || (mouseX = 0)) {
//    sat=100;
//    brite=100;
//  }
 
 
 sat = (mouseX*200/width);
 brite = (mouseY*200/height);
}

Re: or || for "Complementary colors value excercise"
Reply #1 - Feb 16th, 2010, 12:51am
 
sticking this at the end of draw would be good:
if( mouseX >= 0 && mouseX < width ... etc ... ){
// reset the color's values.
}

&& is LOGICAL AND.

This block of code:
//create rectangle of complementary color
rx1 = (width/2)-(width*0.15);
ry1 = (height/2)-(0.15*height);
rw2 = (0.3*width);
rh2 = (0.3*height);
Doesn't need to be called every time draw() is called - the values here are only initialized once. This code would be better in setup().

As for comparing colors, just define a boolean, set it to false, and then check if the colors are equal every time draw() is called. Set the boolean to true if they match, and draw your indicator if the boolean is true.
Page Index Toggle Pages: 1