sketchDownload
var dx1;
var dy1;
var dx2;
var dy2;
function setup() {
createCanvas(400, 300);
background(200);
}
function draw() {
drawLines(0, 50, 400, 200, 150, 300, 100, 100, 50);
drawLines(100, 0, 300, 300, 150, 200, 350, 100, 50);
drawLines(0, 200, 300, 100, 300, 300, 400, 300, 50);
drawLines(350, 100, 300, 200, 150, 300, 350, 100, 50);
noLoop();
}
function drawLines(x1, y1, x2, y2, x3, y3, x4, y4, numLines) {
dx1 = (x3-x1)/numLines;
dy1 = (y3-y1)/numLines;
dx2 = (x4-x2)/numLines;
dy2 = (y4-y2)/numLines;
line(x1, y1, x3, y3);
line(x2, y2, x4, y4);
for (var i = 0; i <= numLines; i += 1) {
line(x1, y1, x2, y2);
x1 += dx1;
y1 += dy1;
x2 += dx2;
y2 += dy2;
}
}
Although my art isn’t super cool, I’m glad that I was able to write a method to draw shapes. Now I can spam it as many times as I want and just put in the parameters for where the lines should start and end 🙂