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 & HelpPrograms › Colour triads with HSB mode.
Page Index Toggle Pages: 1
Colour triads with HSB mode. (Read 915 times)
Colour triads with HSB mode.
Oct 13th, 2009, 7:53pm
 
I'm wracking my brains about why this doesn't work. I just want to pick a random colour and then calculate the two colours 120 degrees apart on the colour wheel if we represent it as 360 degrees. In other words, if the first colour is red, you should get blue and green. Purple/orange/blue green...etc. I set the colour mode to (HSB, 360), choose the first colour randomly, add or subtract 120 degrees for the second two colours' hues, taking the modulus in case it goes over 360. But it doesn't work, so my reasoning must be wrong somewhere. Any ideas gratefully received.
Code:
color basecolour = color(random(255), random(255), random(255));
size(600, 600);
background(0);
colorMode(HSB, 360);
noStroke();
fill(basecolour);
rect(0,0, width/3, height);
fill(color((basecolour+120)%360,saturation(basecolour), brightness(basecolour)));
rect(width/3,0,width/3,height);
fill(color((basecolour-120)%360,saturation(basecolour), brightness(basecolour)));
rect(2*width/3, 0, width/2, height);
Re: Colour triads with HSB mode.
Reply #1 - Oct 13th, 2009, 8:17pm
 
I missed out a bunch of stuff....after editing it when playing around with it...even the "hue" that needed to be in the brackets wasn't there. The actual original problem was getting the brackets in the wrong places. This now works:
Code:
color basecolour = color(random(255), random(255), random(255));
size(600, 600);
background(0);
colorMode(HSB, 360, 100, 100);
noStroke();
fill(basecolour);
rect(0,0, width/3, height);
fill(color ((hue(basecolour)+120)%360,saturation(basecolour), brightness(basecolour)));
rect(width/3,0,width/3,height);
fill(color ((hue(basecolour)-120)%360,saturation(basecolour), brightness(basecolour)));
rect(2*width/3, 0, width/2, height);
Page Index Toggle Pages: 1