Created
August 28, 2017 21:59
-
-
Save federico-pepe/726a361df9dc8edead734ae36946fc56 to your computer and use it in GitHub Desktop.
Una palette di colori da un'immagine
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
/* | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment