hdw – Project 4 – String Art

sketch

//Helen Wu
//Section A
//hdw@andrew.cmu.edu
//Project 4


function setup() {
    createCanvas(400, 300);
    background(255);
  }

function draw() {

//curve one and two
for (var a = 0; a <= 41; a += 3) {
  strokeWeight(1);
  stroke(210);
  line(a, 0, 3*a, height-a);
  line(3*a, height-a, 5*a,300);

  line(width-a, height, width-3*a, a-height);
  line(width-3*a, a-height, -5*a, 0);
}


//three and four
for (var a = 3; a <= 500; a+=5) {
  strokeWeight(1);
  stroke(240,190,190);
  line(30,0,3*a,height-a);
  line(3*a,height-a,0,30);

  line(width-30,height,width-3*a,-a);
  line(width-3*a,-a,height,width-30);
}

//curve five and six
for (var a = 0; a <= 130; a += 3) {
  strokeWeight(1);
  stroke(245);
  fill(170,210,240);
  line (width-3*a, height-a, 5*a, 300);
  curve(width-a, width, width-3*a, height-a, width-3*a, height-a, 5*a, 300);
}

//curve seven + eight
for (var a = 0; a <= 130; a += 3) {
  strokeWeight(1);
  stroke(245);
  fill(170,210,240);
  line (3*a, a, width-5*a,height-300);
  curve(width-a, width, width-3*a, height-a, width-3*a, height-a, 5*a, 300);
}

//curve nine
for (var b = 3; b <=90; b += 5) {
  strokeWeight(1);
  stroke(160,210,230);
  fill(255,255,255,0);
  curve(0,0,b,b,b*4,b+5,400,400)
}

}

I struggled a bit on this week’s project. It’s hard to predict where the curves and lines will end up, so I went with a more experimental approach with my project. I do like the way the colors interact with each other, and the interesting texture created by the criss cross. However, I wish I could have the lines behave more uniformly.

aerubin-project-04-string-art

I was inspired by the interesting curves and shapes that are depicted in paintings of waves. I began by drawing a single wave and then trying different lengths and positions to create the desired effect. I also added movement in the bottom-most waves that makes it seem like it is moving from left to right. I really enjoy using the “for loops” in our design, it makes coding much faster and simpler than writing out every parameter for each line.

sketch

//Angela Rubin
//Section C
//aerubin@andrew.cmu.edu
//Project-04-String-Art

var Y_AXIS = 1;
var c1, c2;

function setup() {
    createCanvas(300, 400);
    background(220);
    c1 = color(255, 183, 60);
    c2 = color(45, 100, 245);
}

function draw() {
    background(220);

    setGradient(0, 0, 300, 400, c1, c2, Y_AXIS);

    for(var i=0; i <200; i++) {
        littlewaves(i);
}
    for(var p=0; p <200; p++) {
        rightwave(p);
}
    //Sun
    noStroke();
    fill(255, 250, 217);
    ellipse(153, 204, 50, 50);

}

function littlewaves(x) {
    //little waves on bottom
    for(var z=0; z<10; z++) {
    push();
    translate(x+(z*20)+(mouseX/2),30); //moves waves 
    rotate(radians(x*2));
    stroke(53, 74, 107);
    line(150,200,10 + x, 400);
    pop(); 
}
}

function rightwave(y) {
    //middle curve
    push();
    translate(y+210, 60);
    rotate(radians(y));
    stroke(97, 132, 158);
    line(150,200,10 + y, 200);
    pop();

    //large wave, dark colored
    push();
    translate(y+122, 170);
    rotate(radians(y*2));
    stroke(82, 115, 149);
    line(150,230,10 + y, 20);
    pop();

    //large wave, light colored
    push();
    translate(y+50, 150);
    rotate(radians(y));
    stroke(70, 170, 200);
    line(150,230,10 + y, 20);
    pop();
}

function setGradient(x, y, w, h, c1, c2, axis) {

    //Sets Gradient in Background
    noFill();
    if (axis == Y_AXIS) {
    for (var i = y; i < y+h; i++) {
    var inter = map(i, y, y+h, 0, 1);
    var c = lerpColor(c1, c2, inter);
        stroke(c);
        line(x, i, x+w, i);
    }
  }
}

dayoungl Project 04

sketch

//Sharon Lee
//dayoungl@andrew.cmu.edu
//Section E
//Project 4
var ychange = 30;
var xchange = 10; 
var x1 = 1;
var x2 = 150;
var x3 = 100;
var y1 = 200;
var y2 = 1;
var y3 = 55;
var r;
var g;
var b;
function setup(){
	//randomzied colour
	r = random(255);
	g = random(255);
	b = random(255);
	createCanvas(300,400);	
}

function draw() {
	background (255);
	for(var i = 0; i < 100; i +=1){
		strokeWeight(0.5);
		stroke(0);
		line(x2, mouseY, 300 , ychange *i);
		line(x2, mouseY, 0 , ychange *i);
		stroke(r,g,b);
		strokeWeight(1);
		line(mouseX, ychange * i, xchange * i, y2); 
		line(x2, y1, 300, ychange *i);
		line(x2, y1, 0, ychange * i);
	}
}

//when mouse is clicked, string changes colour
function mousePressed (){
	stroke(r,g,b);
	r = random(255);
	g = random(255);
	b = random(255);
}

I wanted to make my string art minimal as possible because I like minimalistic art. I like the fact that this looks like a graphic poster.

Project-04-StringArt-sjahania

sketch

var density; //changes how thick the arcs are

//changes the colors
var col1; 
var col2;


function setup() {
    createCanvas(400, 300);
    background(240);
}

function draw() {
	//redraws a new canvas every time the mouse is pressed
	fill(240);
	rect(0,0,400,300);

	//sets the colors based on the x coordinate of the mouse
	col1 = mouseX/(400/255);
	col2 = mouseX/(400/255);

	for (var a = 0; a < 400; a += density) {
		//draws the top left arc
		stroke(180,255 - col2,180);
		line(a, 0, 0, 400-a);

		//draws bottom left arc
		stroke(255 - col1,180,180);
		line(400 - a, 300, 0, 300 - a);

		//draws bottom right arc
		stroke(180,col2,180);
		line(a, 300, 400, 300 - a);


		//draws top right arc
		stroke(col1,180,180);
		line(a, 0, 400, a);
	}

}
//changes the thickness of the arcs by drawing a different # of lines
function mousePressed() {
	density = random(5,12);
}


Using the for loop took me a while because it is different enough from python to really throw me off. Once I figured it out, I had fun making different shapes, but I settled for something symmetrical because the other shapes I made weren’t very aesthetically pleasing. Then I played with colors.

jamieh-Project-04-String-Art

Clicking the top and bottom grey bars changes the amount of lines and position of the lines.
Clicking the canvas flips the colours of the two different sets of lines.
Moving from quadrant to quadrant changes the line weights.

sketch

/*
Jamie Ho
jamieh@andrew.cmu.edu
10:30
Project 4
*/

var ratio;
var centreX;
var centreY;
var lines;
var t;


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

    ratio = 30;				//changes position of control points
    centreX = width/2;
    centreY = height/2;
    lines = 10;				//changes how how many divisions there are on the curve 
    						//which generates the white and blue lines 
}

function draw() {
	background(0);

	for (var i = 0; i <= lines; i++) {
	  t = i / lines;

	  //curve 1 from top L corner to mouse
	  c1x = curvePoint(mouseX, 0, mouseX, width/ratio*2, t);
	  c1y = curvePoint(mouseY, 0, mouseY, height/ratio*6, t);

	  //curve 2 from bottom L corner to mouse
	  c2x = curvePoint(mouseX, 0, width/ratio*6, width, t);
	  c2y = curvePoint(mouseY, height, mouseY, height/ratio*2, t);

	  //curve 3 from top R corner to mouse
	  c3x = curvePoint(width/ratio*2, width, mouseX, mouseX, t);
	  c3y = curvePoint(mouseY, 0, height/ratio*2, mouseY, t);

	  //curve 4 from bottom R corner to mouse
	  c4x = curvePoint(mouseX, width, width/ratio*6, 0, t);
	  c4y = curvePoint(mouseY, height, mouseY, height/ratio*6, t);

	  strokeWeight(1);
	  if(mouseX < centreX & mouseY < centreY){				//top L
			strokeWeight(0.15);
		} else if(mouseX > centreX & mouseY < centreY){	//top R
		  	strokeWeight(0.60);
		} else if(mouseX < centreX & mouseY > centreY){	//bottom L
		  	strokeWeight(0.30);
		} else {											//bottom R
		  	strokeWeight(0.90);
		}

	  if(mouseIsPressed){
		//white lines become blue
	  	stroke(204, 230, 255);
		  	line(c1x, c1y, c2x, c2y);
			line(c1x, c1y, c3x, c3y);
			line(c1x, c1y, c4x, c4y);
			line(c2x, c2y, c1x, c1y);
			line(c2x, c2y, c3x, c3y);
			line(c2x, c2y, c4x, c4y);
			line(c3x, c3y, c1x, c1y);
			line(c3x, c3y, c2x, c2y);
			line(c3x, c3y, c4x, c4y);

		//blue lines become white
		stroke("WHITE");
		  	line(c1x, c1y, c4y, c4x);
			line(c2x, c2y, c1y, c1x);
			line(c3x, c3y, c2y, c2x);
			line(c4x, c4y, c3y, c3x);

	  } else{
	  	//lines have different grey scales
	  	stroke(75);
			line(c1x, c1y, c2x, c2y);
			line(c1x, c1y, c3x, c3y);
			line(c1x, c1y, c4x, c4y);
		stroke(150);	  
			line(c2x, c2y, c1x, c1y);
			line(c2x, c2y, c3x, c3y);
			line(c2x, c2y, c4x, c4y);
		stroke(255);
			line(c3x, c3y, c1x, c1y);
			line(c3x, c3y, c2x, c2y);
			line(c3x, c3y, c4x, c4y);
		//blue lines
		stroke(0, 119, 230);
		  	line(c1x, c1y, c2y, c2x);
			line(c2x, c2y, c3y, c3x);
			line(c3x, c3y, c4y, c4x);
			line(c4x, c4y, c1y, c1x);
	  }
	}

		//the four rectangles here are for ease of seeing where to mouse click
		noStroke();
		fill(200, 200);
		rect(0, 0, width/2, 20);				
		rect(0, height-20, width/2, 20);		
		
		fill(200, 100);
		rect(width/2, 0, width, 20);
		rect(width/2, height-20, width, 20);

		stroke("RED");
		strokeWeight(1);
		//Up arrow
		line(width/4, 0, width/4, 20);	
		line(width/4-10, 10, width/4, 0);
		line(width/4+10, 10, width/4, 0);
		//Right arrow
		line(width/4*3-10, 10, width/4*3+10, 10);
		line(width/4*3, 0, width/4*3+10, 10);
		line(width/4*3+10, 10, width/4*3, 20);
		
		
		if(mouseIsPressed & mouseY < 20 && mouseX < width/2 && lines < 60){			//if click on top L bar
			lines += 1;																	//amt of lines increases to 59
		} else if(mouseIsPressed & mouseY > 280 && mouseX < width/2 && lines > 1){		//if click on bottom L bar
			lines -= 1;																	//amt of lines decreases to 1
		}

		if(mouseIsPressed & mouseY < 20 && mouseX > width/2){							//if click on top R bar
			ratio -= 1;																	//lines shift right
		} else if(mouseIsPressed & mouseY > 280 && mouseX > width/2){					//if click on bottom R bar
			ratio += 1;																	//lines shift left
		}
}

The hardest part was trying not to repeat code, which I had trouble with in the for loop to achieve the effect of what happens when mouse is pressed.

mjeong1-Project-04-String-Art-SectionA

sketch

//Min Young Jeong
//Section A 9:30am
//mjeong1@andrew.cmu.edu
//Project-04

function setup() {
    createCanvas(400,300);
}
function draw() {
    background(225);
    strokeWeight(0.3);
    var r = mouseX; //controls r vallue of color based on mouseX
    var g = mouseY; //controls g vallue of color based on mouseY
    for (i = 0; i < 100; i++) {
        var x1 = 0;
        var x2 = i * mouseX/40;
        //x2 incrementally increases based on mouseX
        var y1 = i * mouseY/30;
        //y1 incrementally increases based on mouseY
        var y2 = height;
    stroke(r,g,100);
    line(x1,y1,x2,y2); //lower left 
    line(width-x1,height-y1,width-x2,height-y2);//upper right
    line(width-x1,height-y1,x2,y2); //lower right
    line(x1,0,x2,height);//left "right triangle" geometry
    line(width-x1,height,width-x2,0);//right "right triangle" geometry

    }
}

For this assignment, I drew inspiration from wave. I created  five different geometry using strings and made them intersection at some point to give some characteristic of the wave. Also, I wanted to create an interactive string art. Position of mouse controls distance and color of the strings.

juyeonk-project04-stringart

sketch

var black = 0;

//dimension of the very first square
var a = 400/1.618;

//dimension of the margin on the top and bottom
var b = 150 - 200/1.618;

//dimensions of each squares
var dim1 = 400/1.618;
var dim2 = 400 - a;
var dim3 = 2 * a - 400;
var dim4 = 800 - 3 * a;
var dim5 = 5 * a - 1200;
var dim6 = 2000 - 8 * a;
var dim7 = 13 * a - 3200;

//color of each string
var color = 255;

function setup() {
    createCanvas(400, 300);
}

function draw() {
    var color = 255;
    background(black); //sets up the background color
    
    
    //strings sprouting out from the corner of the biggest square
    for (var i = 0; i <= a; i += a/20) {
        stroke(color);
        line(a, a + b, i, a + b - i);
    }
    
    //within the square there are always two corners facing each other that are sprouting the strings 
     for (var i = 0; i <= a; i += a/20) {
        stroke(color);
        line(0, b, i, a + b - i);
    }
    
    //strings sprouting out from the corner of the second biggest square
    for (var i = 0; i <= dim2; i += dim2 /20) {
        stroke(color);
        line(a, b + 400 - a, a + i, b + i);
    }
    
    //the opposite corner
    for (var i = 0; i <= dim2; i += dim2 /20) {
        stroke(color);
        line(400, b, a + i, b + i);
    }
    
    //strings sprouting out from the corner of the third biggest square
    for (var i = 0; i <= dim3; i += dim3/20) {
        stroke(color);
        line(width - 2 * a + 400, b + 400 - a, width - 2 * a + 400 + i, 300 - b - i)
    }
    
    //oppotiste corner
    for (var i = 0; i <= dim3; i += dim3/20) {
        stroke(color);
        line(400, height - b, width - 2 * a + 400 + i, 300 - b - i)
    }
    
    //strings sprouting out from the corner of the fourth biggest square
    for (var i = 0; i <= 800 - 3 * a; i += (800 - 3 * a)/20)
        {
        stroke(color);
        line(a + 800 - 3 * a, height - b - 800 + 3 * a, width - 2 * a + 400 - i, 300 - b - i)
        }
    
    //opposite corner
    for (var i = 0; i <= 800 - 3 * a; i += (800 - 3 * a)/20)
        {
        stroke(color);
        line(a, height - b, width - 2 * a + 400 - i, 300 - b - i)
        }
    
    //strings sprouting out from the corner of the fifth biggest square
    for (var i = 0; i <= 5 * a - 1200; i += (5 * a - 1200)/20)
        {
        stroke(color);
        line(a + 5 * a - 1200, 300 - b - 800 + 3 * a, a + i, b + 400 - a - i + 5 * a - 1200)
        }
    
    //opposite corner
        for (var i = 0; i <= dim5; i += dim5/20)
        {
        stroke(color);
        line(a, b + 400 - a, a + i, b + 400 - a - i + 5 * a - 1200)
        }
    
    //strings sprouting out from the corner of the sixth biggest square
    for (var i = 0; i <= dim6; i += dim6/20)
        {
        stroke(color);
        line(a + dim5 + dim6, b + dim2, a + dim5 + i, b + dim2 + i)
        }
    
    //opposite corner
        for (var i = 0; i <= dim6; i += dim6/20)
        {
        stroke(color);
        line(a + dim5, b + dim2 + dim6, a + dim5 + i, b + dim2 + i)
        }
    
    //strings sprouting out from the corner of the seventh biggest square
        for (var i = 0; i <= dim7; i += dim7/20)
        {
        stroke(color);
        line(width - dim3 - dim7, b + dim2 + dim6, width - dim3 - dim7 + i, b + dim2 + dim6 + dim7 - i)
        }
    
    //opposite corner
        for (var i = 0; i <= dim7; i += dim7/20)
        {
        stroke(color);
        line(width - dim3, b + dim2 + dim6 + dim7, width - dim3 - dim7 + i, b + dim2 + dim6 + dim7 - i)
        }
}



For this project I wanted to create a drawing based on golden ratio. It would have been nice if I could figure out a way to make the spiral-y shape made of sets of lines but I’m satisfied with what I have.

The most challenging part of this project was to figure out a logic that would make the strings loop around the pattern you want. Instead of making an array of lines I had to figure out a way to make the lines rotate around a fixed coordinate point. But other than, the project was farily do-able. I wish I planned something more challenging.sketch

myoungsh-project-04-string-art

sketch

function setup() {
  createCanvas(400, 300);
  background(0);
  angleMode(DEGREES);
  for(var x = 100; x < 300; x += 10) { //vary x
    stroke(256);
    line(width, x, x, 0); //draw a line, curve it using varied x
  }
  push(); //reflect the curve
  scale(-1, 1);
  translate(-400, 0);
  for(var y = 100; y < 300; y += 10) {
    stroke(256);
    line(width, y, y, 0); 
  }
  pop();
  push(); //reflect both curves
  scale(1, -1);
  translate(0, -300);
  for(var n = 100; n < 300; n += 10) {
    stroke(256);
    line(width, n, n, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var z = 100; z < 300; z += 10) {
    stroke(256);
    line(width, z, z, 0); 
  }
  pop();
  pop();
  push(); //disapear into the distance
  scale(.5, .5);
  translate(200, 150);
  for(var x1 = 100; x1 < 300; x1 += 10) {
    stroke(256);
    line(width, x1, x1, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var y1 = 100; y1 < 300; y1 += 10) {
    stroke(256);
    line(width, y1, y1, 0); 
  }
  pop();
  push();
  scale(1, -1);
  translate(0, -300);
  for(var n1 = 100; n1 < 300; n1 += 10) {
    stroke(256);
    line(width, n1, n1, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var z1 = 100; z1 < 300; z1 += 10) {
    stroke(256);
    line(width, z1, z1, 0); 
  }
  pop();
  pop();
  pop();
  push(); //go even further back
  scale(.25, .25);
  translate(600, 450);
  for(var x2 = 100; x2 < 300; x2 += 10) {
    stroke(256);
    line(width, x2, x2, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var y2 = 100; y2 < 300; y2 += 10) {
    stroke(256);
    line(width, y2, y2, 0); 
  }
  pop();
  push();
  scale(1, -1);
  translate(0, -300);
  for(var n2 = 100; n2 < 300; n2 += 10) {
    stroke(256);
    line(width, n2, n2, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var z2 = 100; z2 < 300; z2 += 10) {
    stroke(256);
    line(width, z2, z2, 0); 
  }
  pop();
  pop();
  push();
  scale(.5, .5);
  translate(200, 150);
  for(var x3 = 100; x3 < 300; x3 += 10) {
    stroke(256);
    line(width, x3, x3, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var y3 = 100; y3 < 300; y3 += 10) {
    stroke(256);
    line(width, y3, y3, 0); 
  }
  pop();
  push();
  scale(1, -1);
  translate(0, -300);
  for(var n3 = 100; n3 < 300; n3 += 10) {
    stroke(256);
    line(width, n3, n3, 0); 
  }
  push();
  scale(-1, 1);
  translate(-400, 0);
  for(var z3 = 100; z3 < 300; z3 += 10) {
    stroke(256);
    line(width, z3, z3, 0); 
  }
  pop();
  pop();
  pop();
  pop();
}

This project started with a lot of frustration with only being able to create arrays of line. And then once I was able to create a curve creating another curve, and controlling it was close to impossible within the same for loop. To solve this problem I copied the same curve and used translations to draw more.

ghou-project-04-StringArt

sketch

//Grace Wanying Hou
//15-104 Section D
//ghou@andrew.cmu.edu
//Assignment 04 

// increases
var inc = 15;
var xint = 15;
// positions
var x1 = 1; 
var y1 = 499;
var x2 = 499;
var y2 = 1; 
//colours
var lr;
var lg;
var lb;

function setup(){
    createCanvas(500,500);
    background(0);
}

function draw() {
    
    var m = mouseX/25; // colour gets "redrawn" and changes with mouse 
	for(var i = 0; i < m; i += 1) {
		strokeWeight(1);
        lr = i*mouseX/2-500;
        lg = i*mouseY/2;
        lb = i*-mouseY/2+600;
		stroke(lr,lg,lb); //white

        line(x1, inc * i, inc * i, y1); //bottom left
        line(inc * i, y1, x2, y1 - inc * i); //bottom right
        line(x2 - inc * i, y2, x2, y1 - inc * i); //top right
		line(x2 - inc * i, y2, x1, inc * i); //top left
	}
}













 

I wanted to create something interactive or something that changes. I always found string art really cool especially the optical illusions. This piece was a little challenging to put together because of the amount of variables it required it gets a little bit confusing

hannahk2-Project-04

 

sketch

//Hannah Kim
//Section A
//hannahk2@andrew.cmu.edu
//Project-04

function setup() {
    createCanvas(300, 400);
}
function draw() {
  background(0);

//make rows of lines stemming from the center
//change opacity of lines to give glowing effect
for (var lineW = 50; lineW < 250; lineW += 8) {
	stroke(143, 204, 51, 85);
      line(150, 200, lineW, 50);
  }
for (var lineW = 50; lineW < 250; lineW += 8) {
	stroke(114, 163, 41, 90);
      line(150, 200, lineW, 100);
  }
for (var lineW = 50; lineW < 250; lineW += 8) {
	stroke(86, 122, 31, 95);
      line(150, 200, lineW, 150);
  }
for (var lineW = 50; lineW < 250; lineW += 8) {
    //use map function to make middle row of lines
    //lines move up and down if mouse moves up and down
		var lineY = map(mouseY, 0, 200, 0, 400);
		stroke(59, 92, 10);
     	line(150, 200, lineW, lineY);
  }
for (var lineW = 50; lineW < 250; lineW += 8) {
	stroke(86, 122, 31);
      line(150, 200, lineW, 250);
  }
for (var lineW = 50; lineW < 250; lineW += 8) {
	stroke(114, 163, 41);
      line(150, 200, lineW, 300);
  }
for (var lineW = 50; lineW < 250; lineW += 8) {
	stroke(143, 204, 51);
      line(150, 200, lineW, 350);
  }
}

 

My goal for this project was really just to get comfortable using the for loop function. I really wanted to create a laser-esque feeling effect by using layers of string groups and making one “scan” from the top of the canvas to the bottom.