Skip to content

Instantly share code, notes, and snippets.

@bmoren
Created September 6, 2015 20:33
Show Gist options
  • Save bmoren/cee361e4d1f37643914b to your computer and use it in GitHub Desktop.
Save bmoren/cee361e4d1f37643914b to your computer and use it in GitHub Desktop.
p5 Color Examples
//Vary the red based on the hour
var h;
function setup() {
createCanvas(600, 600);
}
function draw() {
h = hour();
print(h);
//take 24 hour time and convert it to between 0 & 255 for the color slot
hColor = map(h,0,24,0,255);
fill(hColor,0,0);
rect(200,200,100,100);
}
//HSB colorshift
//Blue Hue: 239
//Yellow Hue: 65
//Red Hue: 0
var h;
function setup() {
createCanvas(600, 600);
colorMode(HSB);
}
function draw() {
h = hour();
print(h);
//take 24 hour time and convert it to between 0 & 255 for the color slot
hColor = map(h,0,24,0,239);
//uncomment below - keep it a varying set of blue all the time
//hColor = map(h,0,24,200,250);
fill(hColor,100,100);
rect(200,200,100,100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment