Project 09

sketch
//Paul
//kengpul
//Section A

var img;
var newImg;

function preload() {
  img = loadImage('https://i.imgur.com/pqOHKd9.jpg');
}

function setup() {
  createCanvas(300, 400);
    image(img,0,0,300,400);

    for (var y = 0; y < img.height; y++) {
    for (var x = 0; x < img.width; x++) {
      // Read the pixel's color
      var ogCol = img.get(x, y);

      //creates interesting effects with the color with inversion and similar ieffects
      var r = red(ogCol);
      var g = 210 - green(ogCol);
      var b = 255 - 90 - blue(ogCol);

      var newCol = color(r, g, b);

      // Set the new pixel's color
      img.set(x, y, newCol);
    }
  }
  img.updatePixels();
  
    image(img, 0, 0, width, height);
}

function draw() {
    noStroke();
    if(mouseIsPressed){
        randomPixels();
    }
  
}



function randomPixels(){ // creates random sized magnification 
  //of wherever the mouse is on while pressed scattered across the screen
    
    var newImg = img.get(mouseX,mouseY,random(30,70),random(30,70));
    img.updatePixels();

    image(newImg, random(-10,width), random(-10,height), random(10,20),random(10,20));
}

function keyPressed(){
    //when key pressed reset
    //when key pressed reset the small square samples created wit mouse click
  if(key == "r" || key == "R"){
      image(img,0,0,300,400);
      var r = 255 - 90 - red(ogCol);
      var g = 210 - green(ogCol);
      var b = blue(ogCol);
  }



///!!! the program takes a whille to load between each filters so it might take a few sec.





//filter a
    if(key == "A" || key == "a"){

    image(img,0,0,300,400);

    for (var y = 0; y < img.height; y++) {
    for (var x = 0; x < img.width; x++) {
      // Read the pixel's color
      var ogCol = img.get(x, y);

      //creates interesting effects with the color with inversion and similar ieffects
      var r = 255 - 90 - red(ogCol);
      var g = 210 - green(ogCol);
      var b = blue(ogCol);
      var newCol = color(r, g, b);

      // Set the new pixel's color
      img.set(x, y, newCol);
    }
  }
  img.updatePixels();
    image(img, 0, 0, width, height);
  //filter b
  }else if(key == "B" || key == "b"){
    //when key pressed reset
    //background(100);
    image(img,0,0,300,400);

     image(img,0,0,300,400);

    for (var y = 0; y < img.height; y++) {
    for (var x = 0; x < img.width; x++) {
      // Read the pixel's color
      var ogCol = img.get(x, y);

      //creates interesting effects with the color with inversion and similar ieffects
      var r = 255 - 90 - (ogCol);
      var g = 210 - green(ogCol);
      var b = blue(ogCol);
      var newCol = color(r, g, b);

      // Set the new pixel's color
      img.set(x, y, newCol);
    }
  }
  img.updatePixels();
    image(img, 0, 0, width, height);
  //filter C
  }else if(key == "C" || key == "c"){
    //when key pressed reset
    //background(100);
    image(img,0,0,300,400);

     image(img,0,0,300,400);

    for (var y = 0; y < img.height; y++) {
    for (var x = 0; x < img.width; x++) {
      // Read the pixel's color
      var ogCol = img.get(x, y);

      //creates interesting effects with the color with inversion and similar ieffects
      var r = 255 - red(ogCol);
      var g = 0- green(ogCol);
      var b = 50- blue(ogCol);
      var newCol = color(r, g, b);

      // Set the new pixel's color
      img.set(x, y, newCol);
    }
  }
  img.updatePixels();
  
    image(img, 0, 0, width, height);
  }


}






Leave a Reply