Skip to content

Instantly share code, notes, and snippets.

@daneden
Last active November 1, 2016 06:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daneden/622c8707580d777831b4932709f42216 to your computer and use it in GitHub Desktop.
Save daneden/622c8707580d777831b4932709f42216 to your computer and use it in GitHub Desktop.
// - Draw a series of points in a straight line and draw a line between them;
// - Make a copy of the preceding series of points, slightly mutate their x/y coordinates, and draw a line between them;
// - Repeat
ArrayList<PVector> points;
int pTotal = 300; // The total number of points per line
float w; // This will be used to define the drawing area
// Noise variables
float offsetX = 0;
float offsetY = 1000;
// Initialising the points is straightforward enough
ArrayList<PVector> makePoints(int noOfPoints) {
ArrayList<PVector> p = new ArrayList<PVector>();
float dist = (height-(height*0.2))/(noOfPoints*2);
for (int i = 0; i < (2*noOfPoints); i++) { // Multiplying noOfPoints gives us denser lines
PVector point = new PVector(0, i*dist);
p.add(point);
}
return p;
}
// Mutate the points by randomly moving their x/y coords, with the maximum magnitude set by noise()
ArrayList<PVector> mutatePoints(ArrayList<PVector> p) {
for (int i = 0; i < p.size(); i++) {
PVector point = p.get(i);
float x = noise(offsetX);
float y = noise(offsetY);
point.x += random(-x, x);
point.y += random(-y, y);
offsetX += 0.01;
offsetY += 0.01;
}
return p;
}
void setup() {
size(1000, 1000);
noLoop();
pixelDensity(displayDensity());
points = makePoints(pTotal);
w = width-(width*0.2);
noFill();
}
void draw() {
background(255);
stroke(0, 100);
translate(width*0.1, height*0.1);
// This rotation and translation is fairly hacky, just to have the fabric drawn top-bottom instead of left-right
rotate(PI/2);
translate(0, -height*0.8);
for (int i = 0; i < (width*0.31); i++) { // "width*0.31" is completely arbitrary, but this basically effects the "length" of the material
pushMatrix();
translate((w/pTotal)*i, 0);
rotate(0.0005 * i);
beginShape();
for (int j = 1; j < points.size(); j++) {
vertex(points.get(j).x, points.get(j).y);
}
endShape();
popMatrix();
points = mutatePoints(points);
}
}
void mousePressed() {
if(mouseX > width/2) {
saveFrame();
}
points = makePoints(pTotal);
redraw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment