Skip to content

Instantly share code, notes, and snippets.

@AlcaDesign
Last active February 2, 2017 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlcaDesign/68bd3b09de9a7ba9a1db2531aeaa5fad to your computer and use it in GitHub Desktop.
Save AlcaDesign/68bd3b09de9a7ba9a1db2531aeaa5fad to your computer and use it in GitHub Desktop.
Direct Processing conversion of adalberth's p5.js version: https://gist.github.com/adalberth/b204be0e599e89c6d5357b4546c1b086
float sliderA, sliderB;
float dim = 20;
void setup() {
size(600, 600);
sliderA = random(0, dim);
sliderB = random(0, dim * 2);
}
void draw() {
clear();
sliderA = map(mouseX, 0, width, 0, dim);
sliderB = map(mouseY, 0, height, 0, dim * 2.0);
drawFirstElement();
repeatSample(0, 0, dim, dim);
}
void drawFirstElement () {
pushMatrix();
stroke(255);
line(sliderB, 0, sliderA, sliderA);
popMatrix();
PImage a = get(0, 0, floor(dim * 2), floor(dim));
pushMatrix();
translate(dim * 2, 0);
scale(-1, 1);
image(a, 0, 0);
popMatrix();
PImage b = get(0, 0, floor(dim * 2), floor(dim * 2));
pushMatrix();
translate(dim * 2, 0);
rotate(radians(90));
image(b, 0, 0);
popMatrix();
pushMatrix();
translate(0, dim * 2);
scale(1, -1);
image(b, 0, 0);
popMatrix();
pushMatrix();
translate(0, 0);
rotate(radians(90));
scale(1, -1);
image(b, 0, 0);
popMatrix();
}
void repeatSample(int x, int y, float w, float h) {
if (w > 500 ) return;
PImage sample = get(x, y, floor(w * 2), floor(h * 2));
image(sample, x + w * 2, y, w * 2, h * 2);
image(sample, x + w * 2, y + w * 2, w * 2, h * 2);
image(sample, x, y + w * 2, w * 2, h * 2);
repeatSample(x, y, w * 2, h * 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment