Skip to content

Instantly share code, notes, and snippets.

@federico-pepe
Created August 28, 2017 21:59
Show Gist options
  • Save federico-pepe/726a361df9dc8edead734ae36946fc56 to your computer and use it in GitHub Desktop.
Save federico-pepe/726a361df9dc8edead734ae36946fc56 to your computer and use it in GitHub Desktop.
Una palette di colori da un'immagine
/*
* 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