Curran Zhang- Project 09- Portrait

sketch

/*Curran Zhang
 curranz
 Project 9
 Section A
 */

var Ball = [];
var img = ['https://i.imgur.com/6PlJkcb.jpg',
           'https://i.imgur.com/MIU3YvB.jpg']
                     
var dir;
var picIndex = 1;
var currentIndex = 0;

function preload(){
  pic = loadImage(img[picIndex]);
}

function setup(){
  createCanvas(480,480);
  pic.loadPixels();
  background(50);
  dir = random(5,10);
}

function properties(px,py,pdy){
  b = { x: px,
        y: py,
        dy: pdy,
        speed: ballSpeed,
        ball: ballMake,
        bSize: random(3,6)
      }
  return b; 
}

function ballMake(){
  var xx = constrain(floor(this.x),0,width-1);
  var yy = constrain(floor(this.y),0,height-1);
  var pix = pic.get(this.x, this.y);

  fill(pix)
  stroke(0);
  strokeWeight(0.1);
  ellipse(this.x, this.y, this.bSize, this.bSize);
}

function ballSpeed(){
  this.y += this.dy * random(.1,.3);
}

function draw(){
  //Creating an array of all the individual balls
  newBall =[];
  for (var i = 0; i <Ball.length; i++) {
    var b = Ball[i];
    b.speed();
    b.ball();
    newBall.push(b);
  }
  Ball = newBall;

 //Applying all the drawn properties onto the canvas
  var bb = properties(random(width), 0, dir);
  Ball.push(bb);
}

/*
//Failed attempt to shuffle through the array to switch the image
function mouseClicked(){
picIndex = int(random(0,1))
        while (currentIndex == picIndex){
         picIndex = int(random(0,1))
        }
        currentIndex = bodyIndex;
}
*/

For this project, I used pictures from my friend Kelly. I tried to create a snow falling effect of the individual pixels. I tried to place the pictures into an array which would eventually shuffle through with mouseClicked(), however it would just freeze up. Even though it didn’t work, I am satisfied with the glittery effect that it produces.

Droopy Effect in the Begining
Final Product

 

Leave a Reply