Project 04: String Art

string art
//Amy Hu
//amyhu
//Section D

var dx1;
var dy1;
var dx2;
var dy2;
var numLines = 30;

function setup() {
    createCanvas(400, 400);
    background(200);

    for(var angle = 0; angle <= 360; angle += 45){
        translate(width/2,height/2);
        line(0,-50,0,-150);
        line(150,0,50,0);
        dx1 = (0-0)/numLines;        
        dy1 = (-150+50)/numLines;
        dx2 = (50-150)/numLines;       
        dy2 = (0-0)/numLines;
        rotate(radians(angle));
    }

}

function draw() {

    translate(width/2,height/2);

    for(var angle = 0; angle <= 360; angle += 45){
        var x1 = 0;
        var y1 = -50;
        var x2 = 150;
        var y2 = 0;
        for (var i = 0; i <= numLines; i += 1) {
            line(x1, y1, x2, y2);
            x1 += dx1;
            y1 += dy1;
            x2 += dx2;
            y2 += dy2;
        }
        rotate(radians(angle));
    }
    

    noLoop();
}

Leave a Reply