Project 04 – String art

Randomly generated string vortex effect

sketch
//Aarnav Patel
//aarnavp
//Section D

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


function setup() {
    createCanvas(400, 300);
    background(220);

}

function draw() {
	strokeWeight(0.25)	//to better see string

    for (var i = 0; i < 10; i += 1) {	//the amount of vortex triangles drawn
       	let x1 = random(0, width);
    	let y1 = random(0, height);
    	let x2 = width / 2;
    	let y2 = height / 2;
        //centering all lines towards middle on end point – converging vortex
        
        let x3 = random(0, width);
        let y3 = random(0, height);
        let x4 = random(0, width);
        let y4 = random(0, height);

    	line(x1, y1, x2, y2);
    	//line(x3, y3, x4, y4);

    	dx1 = (x2 - x1) / numLines;
    	dy1 = (y2 - y1) / numLines;
    	dx2 = (x3 - x4) / numLines;
    	dy2 = (y3 - y4) / numLines;
    	//creating evenly spaced lines for each "line art pair"

    	for (var j = 0; j < numLines; j += 1) {
    	    if (i == 5) {		//making the middle vortex triangle red
    			stroke("red");
    		} else {
    			stroke(0)
    		}

    		line(x1, y1, x2, y2);
    		x1 += dx1;
    		y1 += dy1;
    		x2 += dx2;
    		y2 += dy2;

    	}

    }
    noLoop();


}

Leave a Reply