Created
October 2, 2015 16:24
-
-
Save iandioch/abc39f6e11f88ddca344 to your computer and use it in GitHub Desktop.
Finds the average of a number of colours. Makes interesting palettes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
color a = color(255, 152, 145); | |
color b = color(52, 81, 255); | |
void setup(){ | |
size(500,500); | |
} | |
void draw(){ | |
fill(a); | |
noStroke(); | |
rect(0,0, width/3f, height); | |
fill(b); | |
rect(width*2/3f, 0, width/3, height); | |
fill(mean(a, b)); | |
rect(width/3f, 0, width/3f, height); | |
} | |
void mouseReleased(){ | |
b = color(random(255), random(255), random(255)); | |
} | |
void keyReleased(){ | |
a = color(random(255), random(255), random(255)); | |
} | |
int mean(color a, color... vals){ | |
float rsum = red(a); | |
float gsum = green(a); | |
float bsum = blue(a); | |
for(int i = 0; i < vals.length; i ++){ | |
rsum += red(vals[i]); | |
gsum += green(vals[i]); | |
bsum += blue(vals[i]); | |
} | |
int n = 1 + vals.length; | |
float rmean = rsum/n; | |
float gmean = gsum/n; | |
float bmean = bsum/n; | |
return color(rmean, gmean, bmean); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment