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);