Project-04: String Art

sketch
    // Fangzheng Zhu
    // Section D
    // jtimczyk@andrew.cmu.edu
    // Project-04-string art

var y = 100;
var x = 100;
var m = -1;
var n = -1;

function setup() {
  createCanvas(400, 300); 
  stroke(255); 
  strokeWeight(0.5);    
  frameRate(30);
}

function draw() { 
  background(0 , 5);
  stroke(y,100,x);

// 1st string animation

  y = y + (3*m); 
  if (y < 0) { 
    m = m*(-1); 
  } 
  if (y > height) {
    m = m*(-1);
  }

// 1st strings 
  line(0, y, width/2, height/2); 
  line(width, y, width/2, height/2); 

  line(0, y, width/2, height); 
  line(width, y, width/2, height); 

  line(0, y, width/2, 0); 
  line(width, y, width/2, 0); 

// 2st string animation
  x = x + (3*n); 
  if (x < 0) { 
    n = n*(-1);
  } 
  if (x>width) {
    n = n*(-1);
  }

// 2st strings

  line(0, height/2, x, 0);
  line(0, height/2, x, height);

  line(width/2, height/2, x, 0);
  line(width/2, height/2, x, height);

  line(width, height/2, x, 0);
  line(width, height/2, x, height);

  

} 


Leave a Reply