Skip to content

Instantly share code, notes, and snippets.

@AlcaDesign
Last active February 2, 2017 01:41

Revisions

  1. AlcaDesign revised this gist Feb 2, 2017. 1 changed file with 38 additions and 37 deletions.
    75 changes: 38 additions & 37 deletions StarPatterns.pde
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,50 @@
    float sliderA, sliderB;
    float dim = 20;

    void setup() {
    size(600, 600);
    sliderA = random(0, dim);
    sliderB = random(0, dim * 2);
    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);
    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();
    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) {
  2. AlcaDesign created this gist Feb 2, 2017.
    56 changes: 56 additions & 0 deletions StarPatterns.pde
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    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);
    }