xxxxxxxxxx
PImage img;
boolean mouseClickedFlag = false;
int numPolygons = 20;
int detailLevel = 5;
void setup() {
size(800, 800);
background(0);
loadImageAndResize("fuschlsee.jpeg"); // Replace with the path to your image
noLoop();
}
void loadImageAndResize(String imagePath) {
img = loadImage(imagePath);
img.resize(width, height);
}
void draw() {
if (mouseClickedFlag) {
background(0); // Clear the canvas on click
loadImageAndResize("fuschlsee.jpeg"); // Reload the original image
updateParameters();
cubismStyle(img, numPolygons, detailLevel);
mouseClickedFlag = false; // Set the flag to false after updating once
noLoop(); // Stop looping after the first frame
}
}
void keyPressed() {
if (key == 's' || key == 'S') {
saveFrame("output#######.png");
}
}
void mousePressed() {
if (!mouseClickedFlag) {
mouseClickedFlag = true;
loop(); // Start looping to update the drawing
}
}
void updateParameters() {
// Set the parameters randomly
numPolygons = int(random(10, 41)); // Random number of polygons between 10 and 40
detailLevel = int(random(3, 11)); // Random detail level between 3 and 10
}
void cubismStyle(PImage img, int numPolygons, int detailLevel) {
for (int i = 0; i < numPolygons; i++) {
int vertices = int(random(4, 8));
beginShape();
// Blend colors based on a random factor
float blendFactor = random(0.2, 0.8);
fill(
lerpColor(color(255), color(random(255), random(255), random(255)), blendFactor)
);
// Set the stroke color
stroke(0);
strokeWeight(0.5); // Set the constant stroke weight
for (int j = 0; j < vertices; j++) {
float x = random(width);
float y = random(height);
vertex(x, y);
}
endShape(CLOSE);
}
// Add shading to simulate depth
loadPixels();
img.loadPixels();
for (int i = 0; i < width; i += detailLevel) {
for (int j = 0; j < height; j += detailLevel) {
float b = brightness(img.pixels[j * width + i]);
// Map brightness to depth (darker areas appear closer)
float depth = map(b, 0, 255, -50, 50);
// Draw small rectangles for shading
fill(0, 20);
noStroke();
rect(i, j, detailLevel, detailLevel + depth);
}
}
updatePixels();
}