//global variables that hold x and y position as well as the amount that is added to both values
//(different x and y variables per function)
var x1 = -100;
var y1 = 0;
var x1Step = 2;
var y1Step = 4;
var x2 = 400;
var y2 = 0;
var x2Step = 2;
var y2Step = 2;
var gradient = 0;
var gradient2 = 256;
var gradient3 = 256;
var x11 = 0;
var x22 = 400;
var y11 = 300;
var y22 = 0;
var x11Step = 0.5;
var y11Step = 1;
var x22Step = 0.5;
var y22Step = 1;
function setup() {
createCanvas(400,300);
}
function draw() {
//makes background change color value
background(gradient3--);
//calls functions that produce lines
lines();
lines2();
lines34();
}
//lines converging in center
function lines(){
var x1constrain = constrain(mouseX,-100,0);
strokeWeight(0.8);
for(var i=0;i<1000;i+=10){
stroke(gradient+i);
line(x1constrain+i, 0, 0, y1-i);
}
x1+=x1Step;
y1+=y1Step;
}
//lines converging in center
function lines2(){
var y2constrain =constrain(mouseX,-100,0);
strokeWeight(0.8);
for(var i=0;i<1000;i+=10){
stroke(gradient2-i);
line(x2-i, 300, 400, y2constrain+i);
}
x2-=x2Step;
y2+=y2Step;
}
//slower corner lines
function lines34(){
//increases i at a faster rate so as to draw less lines
for(var i=0;i<1000;i+=30){
stroke(gradient+i*1.2);
line(x11+i,0,0,y11-i);
stroke(gradient+i*1.2);
line(x22-i,300,400,y22+i);
}
//changes x11 and y22 values so that it creates a curve
x11+=x11Step;
y11-=y11Step;
x22-=x22Step;
y22+=y22Step;
}
For this project, I decided that I wanted to play with adding motion into my string art. I started with figuring out the values in order to make the first loop of lines in the top left corner and used my experimentation with that in order to mirror the lines into the bottom right corner.
While I thought that the two looked interesting together, I decided that rather than create two more loops for the other corners, I wanted to create two new series of lines that would start from the same corner but act in a very different way. While playing around with that concept, I came up with the code below.
//lines1 variables
var x1=0;
var x1Step=0.5;
var y1=300;
var y1Step=1;
var x2=400;
var x2Step=1;
var y2=0;
var y2Step=1;
var gradient=0;
var y3=100;
var y3Step=0.5;
var x3=1000;
var x3Step=1;
var y4=400;
var y4Step=1;
var x4=400;
var x4Step=1;
function setup() {
createCanvas(400,300);
}
function draw() {
background(255,200,200);
lines1();
}
function lines1(){
if(y1 >0 & y1 < 300){
for(var i=0;i<1000;i+=20){
strokeWeight(0.8);
//gradient black to white lines
stroke(gradient+i*1.2);
line(x1+i,0,0,y1-i);
//teal lines
stroke(gradient+i*1.2);
line(x2-i,300,400,y2+i);
}
}
for(var i=0;i<1000;i+=60){
strokeWeight(0.8);
stroke(0);
line(0,y3+i,x3-i,0);
stroke(256);
line(0,y4-i,x4+i,0);
}
x1+=x1Step;
y1-=y1Step;
x2-=x2Step;
y2+=y2Step;
x3+=x3Step;
y3-=y3Step;
x4-=x4Step;
y4+=y4Step;
}
Although I found that I was able to satisfy the requirements of the project, I decided that I was not satisfied with the inconsistent ways that the lines would move, so I restarted and played around with changing different variables. Through more experimentation, I was able to come up with my final code, which appeared more sophisticated in terms of the spacing of the grid it created as well as the monochrome colors.