16/02/2020
Building up on the previous post
Canvas canvas;
void setup() {
size(320, 320);
background(255);
frameRate(5);
int initialStep = 5;
float thresh = 0.65;
canvas = new Canvas(initialStep, thresh);
}
class Canvas {
int tilingStep;
int stepDirection = 1;
int frame = 1;
float tilingThresh;
Canvas(int step, float thresh) {
tilingStep = step;
tilingThresh = thresh;
}
void drawLine(int x, int y, float w, float h) {
strokeWeight(random(2));
if ( random(1) > tilingThresh)
{
stroke(#17BEBB);
line(x, y, x+w, y+h);
}
else
{
stroke(#E4572E);
line(x+w, y, x, y+h);
}
}
void drawCanvas(){
for (int x = 0; x < width; x += tilingStep) {
for (int y = 0; y < height; y += tilingStep) {
drawLine(x, y, tilingStep, tilingStep);
}
}
}
void saveFrame(){
save(String.format("%04d.png", frame));
frame ++;
}
void updateStep(){
if (tilingStep >= 30 || tilingStep <= 4)
{
stepDirection *= -1;
}
tilingStep += stepDirection;
}
}
void draw() {
background(255);
for (int i=0; i<2; i++)
{
canvas.drawCanvas();
}
canvas.updateStep();
canvas.saveFrame();
if (canvas.frame == 51)
{
exit();
}
}
Convert to gif as
convert -delay 30 *.png +repage -loop 0 out.gif