Skip to content

Instantly share code, notes, and snippets.

@bramses
Created January 18, 2020 07:42
Show Gist options
  • Save bramses/56976c6f22fcab7a6a16f0ddf05858d9 to your computer and use it in GitHub Desktop.
Save bramses/56976c6f22fcab7a6a16f0ddf05858d9 to your computer and use it in GitHub Desktop.
Disentegrating Mountain [Processing]
/*
fork of P_2_1_2_04
*/
PImage img;
int tileCount = 50;
float tileWidth;
float tileHeight;
int actRandomSeed = 0;
void setup () {
size(500, 500);
img = loadImage("tyler-lastovich-ddLiNMqWAOM-unsplash.jpg"); // DATA/img.jpg
img.resize(500, 500);
tileWidth = width / tileCount;
tileHeight = height / tileCount;
}
void draw () {
clear();
randomSeed(actRandomSeed);
for (int y = 0; y < tileCount; y++) {
for (int x = 0; x < tileCount; x++) {
float posX = x * tileWidth;
float posY = y * tileHeight;
// vertex corners
float shiftX1 = mouseX / 20 * random(-1, 1);
float shiftY1 = mouseY / 20 * random(-1, 1);
float shiftX2 = mouseX / 20 * random(-1, 1);
float shiftY2 = mouseY / 20 * random(-1, 1);
float shiftX3 = mouseX / 20 * random(-1, 1);
float shiftY3 = mouseY / 20 * random(-1, 1);
float shiftX4 = mouseX / 20 * random(-1, 1);
float shiftY4 = mouseY / 20 * random(-1, 1);
pushMatrix();
translate(posX, posY);
color pix = img.get((int)posX, (int)posY);
fill(pix);
if (y % 2 == 0) {
beginShape();
vertex(shiftX1, shiftY1); // top left
vertex(shiftX2 + tileWidth, shiftY2); // top right
vertex(shiftX4 + tileWidth, shiftY4 + tileHeight); // bottom right
vertex(shiftX3, shiftY3 + tileHeight); // bottom left
endShape();
} else {
circle(tileWidth / 2, tileHeight / 2, tileWidth);
}
popMatrix();
}
}
}
void mousePressed () {
actRandomSeed = (int)random(100000);
println(actRandomSeed);
}
void keyPressed () {
if (key == 's') saveFrame();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment