/*Tanvi Harkare
Section B
tharkare@andrew.cmu.edu
Project-04-String Art */
var R; //variables for random color for line
var G;
var B;
var x1 = 0; //starting points for location of lines
var x2 = 0;
var y1 = 0;
var y2 = 100;
var x3 = 25; //starting position for second set of lines
var x4 = 25;
var y3 = 25;
var y4 = 150;
var x5 = 50; //starting position for third set of lines
var x6 = 50;
var y5 = 50;
var y6 = 200;
var x7 = 75; //starting position for fourth set of lines
var x8 = 75;
var y7 = 75;
var y8 = 250;
var x1stepSize = 15; //increment values for each point
var x2stepSize = 5;
var y1stepSize = 0;
var y2stepSize = 10;
var x3stepSize = 20; //increment values for second set of lines
var x4stepSize = 10;
var y3stepSize = 0;
var y4stepSize = 10;
var x5stepSize = 25; //increment value for third set of lines
var x6stepSize = 15;
var y5stepSize = 0;
var y6stepSize = 10;
var x7stepSize = 20; //increment value for fourth set of lines
var x8stepSize = 10;
var y7stepSize = 0;
var y8stepSize = 10;
function setup() {
createCanvas(400, 300);
background(0);
}
function draw() {
//curve starting from 0, 0
for(var i = 0; i < 50; i++){
curveChange = random(.35, 1);
changeColor();
stroke(R, G, B);
line(x1, y1, x2, y2);
x1 += x1stepSize;
x2 += x2stepSize;
y2 -= y2stepSize;
y2stepSize -= curveChange;
}
//curve starting from 25, 25
for(var i = 0; i < 50; i++){
curveChange = random(.35, 1);
changeColor();
stroke(R, G, B);
line(x3, y3, x4, y4);
x3 += x3stepSize;
x4 += x4stepSize;
y4 -= y4stepSize;
y4stepSize -= curveChange;
}
//curve starting from 50, 50
for(var i = 0; i < 50; i++){
curveChange = random(.35, 1);
changeColor();
stroke(R, G, B);
line(x5, y5, x6, y6);
x5 += x5stepSize;
x6 += x6stepSize;
y6 -= y6stepSize;
y6stepSize -= curveChange;
}
//curve starting from 75, 75
for(var i = 0; i < 50; i++){
curveChange = random(.35, 1);
changeColor();
stroke(R, G, B);
line(x7, y7, x8, y8);
x7 += x7stepSize;
x8 += x8stepSize;
y8 -= y8stepSize;
y8stepSize -= curveChange;
}
}
function changeColor(){
/* assigns different color values for every
line that is drawn in the draw() function */
R = random(0, 255);
G = random(0, 255);
B = random(0, 255);
}
I had a lot of fun with this project, especially in creating different ways to show the curves made through the string art. In my sketch, the color of each line is different and changes each time you run the code; I did this by creating my own function. Additionally, the curvature of the string art changes slightly to create a different effect ever time.