Project 4 – String Art

sketch
var dx1;
var dy1;
var dx2;
var dy2;
var numLines = 100;
var angle = 0;

function setup() {
    createCanvas(400, 400);
    background(220);
    text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
    background(0);
    stroke(255);
    strokeWeight(0.25);

    dx1 = (0)/numLines;
    dy1 = (400)/numLines;
    dx2 = (400)/numLines;
    dy2 = (0)/numLines;
    var x1 = 0;
    var y1 = 10;
    var x2 = 0;
    var y2 = 400;

    for (var i = 0; i <= numLines; i += 1) {

        //bottom left
        line(x1, y1, x2, y2);
        //top right
        line(x1 + 400, y1, x2, y2 - 400);
        //bottom left 2
        line(x1 + 400, y1 + 400, x2 - 400, y2 - 400);
        //top right 2
        line(x1, y1 - 400, x2 + 400, y2);
        //mouse movement  
        line(x2, y1, x1, mouseY);
        line(x2, y1, x1 + 400, mouseY);

        //opacity change
        if(mouseX > 0) {
            stroke(max(mouseX, 0));
        }
        x1 += dx1;
        y1 += dy1;
        x2 += dx2;
        y2 += dy2;

    }

    
}

I was inspired by geometric lines, and parabolic curves.

Leave a Reply