This week is all about color and how to use color in P5js.
- lowest visible frequency ⟸ red ⟹ longest wave length
- highest visible frequency ⟸ violet ⟹ shortest wave length
- White is even (uniform) distribution of color
- Black is absence of Light
- Subtractive color ⟶ mixing color pigments ⟶ dark brown/Black
- Additive color ⟶ mixing colored light ⟶ approaches white
color(red,green,blue);
- color takes 3 parameters ⟶ red channel, green channel, blue channel
//color can also be specified in the following ways
// numbers
var c = color(255,0,0);
// strings
var c = color("rgb(100%,0%,0%)");
// hexadecimal
var c = color("#ff0000");
fill(255,0,0); ⟶ RED fill color
fill(0,255,0); ⟶ GREEN fill color
fill(0,0,255); ⟶ BLUE fill color
- In p5js we can specify color representation mode to be HSB by calling color mode.
colorMode(HSB,Hue,Saturation,Brightness);
Note
In practice, the default maximum values of H,S, and B are as follows
- Hue = 360
- Saturation = 100
- Brightness = 100
Brightness is also frequently referred to as "Luminance".
This a representation of color in a graphical format
- 1666 ⟶ Science Boi Issac Newton ⟶ Dispersion ⟶ Color deconstruction with prism
- Color Wheel
- 7 asymmetrical segments.
- Arranged complementary colors opposite to each other in a circle.
- Each side enhanced the other through optical contrast.
- FunFact: He did this with musical notes as well to suggest that like music colors could harmonize with each other (I don't get either!)
- Hue is the representation of the angle along the color wheel
- Numerically Analogous colors are less than 30 degrees
Function keyPressed() in p5js constantly listens for a key press. If a key is pressed, then the code in the functions is executed.
More on this at keyPressed
/* This function is constantly listening for key press
If the pressed key is SPACEBAR (code ==> 32) new hue is computed and draw is called again.
*/
function keyPressed() {
if (keyCode == 32) {
// Code here is executed upon key press.
}
}
Interpolation is a way creating a gradient between different values. It is transitioning from one color to another.
- One way of doing this is using the lerpColor() function in p5js.
- lerpColor() -bBlends two colors to find a third color somewhere between them.
- More on this at lerpColor
lerpColor(colorFrom, colorTo, lerpAmount);
// 0 > lerpAmount > 1.0
- Map function maps a value of a variable from one range to another.
var mappedValue = map(variable,inputMin,inputMax,outputMin,outputMax);