Created
August 28, 2017 22:24
-
-
Save federico-pepe/1f1e9587d1bad41301fce0e7d1afa16c to your computer and use it in GitHub Desktop.
Una palette di colori da un'immagine
This file contains hidden or 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
/* | |
* Una palette di colori da un'immagine | |
* Federico Pepe, 28.08.2017 | |
* http://blog.federicopepe.com/processing | |
*/ | |
PImage img; | |
// Numero di "punti" della nostra palette | |
int numPoints = 5; | |
// Valore x di riferimento | |
int pointX; | |
void setup() { | |
size(1, 1); | |
surface.setResizable(true); | |
img = loadImage("flowers.jpg"); | |
surface.setSize(img.width, img.height+50); | |
} | |
void draw() { | |
image(img, 0, 0); | |
img.loadPixels(); | |
pointX = img.width / numPoints; | |
for (int i = 0; i <= numPoints-1; i++) { | |
int x = pointX/2+pointX*i; | |
int y = mouseY; | |
if (mouseY <= 0 || mouseY >= img.height) { | |
y = img.height/2; | |
} | |
stroke(255); | |
noFill(); | |
ellipse(x, y, 25, 25); | |
color c = img.pixels[x + y * img.width]; | |
fill(c); | |
rect(pointX*i, img.height, pointX, 50); | |
fill(255); | |
textAlign(CENTER); | |
text("#"+hex(c,6), x, img.height+30); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment