17/02/2020
Second tutorial from generativeartistry.com
void setup() {
size(320, 320);
pixelDensity(2);
strokeWeight(3);
frameRate(5);
}
float randomJoy(float j) {
float distance_to_center = abs(j - width * random(0.4,0.6));
float variance = max(width * 0.5 - 50 - distance_to_center, 0.0);
float r = random(1.25) * variance * 0.5 - 1;
return r;
}
class Pt {
float x;
float y;
Pt(float x_, float y_) {
x = x_;
y = y_;
}
}
class Line {
Pt a;
Pt b;
Line(Pt a_, Pt b_) {
a = a_;
b = b_;
}
}
ArrayList<ArrayList<Pt>> make_lines(int step) {
ArrayList<ArrayList<Pt>> lines = new ArrayList<ArrayList<Pt>>();
for (float i=7*step; i <= height-step; i+=step) {
ArrayList<Pt> line_from_pts = new ArrayList<Pt>();
for (float j=step; j <= width-step; j+=step) {
line_from_pts.add(new Pt(j, i - randomJoy(j)));
}
lines.add(line_from_pts);
}
return lines;
}
void draw_lines(ArrayList<ArrayList<Pt>> lines)
{
for (int i=0; i < lines.size(); i++) {
stroke(123/(lines.size()-1)*i,
255-255/(lines.size()-1)*i,
255-123/(lines.size()-1)*i);
beginShape();
Pt a = lines.get(i).get(0);
curveVertex(a.x, a.y);
for (int j=0; j < lines.get(i).size(); j++) {
Pt b = lines.get(i).get(j);
curveVertex(b.x, b.y);
}
endShape();
}
}
void draw() {
background(255);
//stroke(255);
int step = 10;
ArrayList<ArrayList<Pt>> lines = make_lines(step);
draw_lines(lines);
saveFrame("joy-###.png");
exit();
}