Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Trying to trigger video Filters with a touch of several buttons Need Urgent Help

$
0
0
Hi,  I am a new programming student and for my school final I am trying to create a sort of Photo Booth using the camera on a mac or any kind of computer camera with different filters that are triggered with arrow keys like tints and distortions basically some of the things that are in Mac's Photo Booth. I tried some methods but was unsuccessful so i took it out of the program.


Here are the Files for everything in my program
Photo Booth

  1. import processing.video.*;//opens up processing libraries

    int currentKey;   //integer variable save coded key numeric rep of ASCII

    int s;// saved time

    int t = 5000;// 5 seconds

    //class
    Capture video;//class for cideo

    Button[] button = new Button[4];//class will be called button


    PImage img;//class img

    boolean state; // keyPressed
    //===================================
    void setup() {
      size(1500, 1098);
      background(0);

      img = loadImage("Octoton Background Big.jpg"); //image file name
      frameRate(30);
      imageMode(CENTER);
      //Inititialize class
      for (int i = 0; i< button.length; i++) {
        button[i] = new Button(250+(i*75), 250);
      }

      button[0].setColor(0, 255, 0);//green
      button[1].setColor(0, 0, 255);//blue
      button[2].setColor(255, 255, 0);//yellow
      button[3].setColor(142, 56, 142);//purple

      video = new Capture (this, 640, 480, 30);//(video, width, height, frameRate)
      video.start();

      s = millis(); //sets s to millis
      ellipseMode(CENTER);

      currentKey = 0;
    }
    //======================END SETUP===================



    void draw () {
     
      image(img, width/2, height/2);// background drawn 

      dispVid();  //draw video to screen

      Button1();

      Button2();

      Button3();

      Button4();
     
    }

    //function to check if a key has been pressed
    void keyPressed() {

      currentKey = keyCode;  //assign the keycode representation of the ASCII character to currentKey
      println(currentKey);  //print the value
    }

    //=============Button1=================

    void Button1() {
      if (currentKey == 38) {  //the keycode for ASCII UP button on the keyboard is 38. Eval if currentKey is 38
        button[0].display(true);
        println("Button 1 Pressed");
      }
      else {   //if the keycode is not UP aka 38 set the display method to false for the default
        button[0].display(false);//button deafault displayed
        println("Button 1 Not Pressed");
      }
    }

    //=============Button2=================

    void Button2() {
      if (currentKey == 40) { //the keycode for ASCII UP button on the keyboard is 40. Eval if currentKey is 40
        button[1].display(true);
        println("Button 2 Pressed");
      }
      else { //if the keycode is not UP aka 40 set the display method to false for the default
        button[1].display(false);//button deafault displayed
        println("Button 2 Not Pressed");
      }
    }

    //=============Button3=================

     void Button3() {
      if (currentKey == 37) {  //the keycode for ASCII UP button on the keyboard is 38. Eval if currentKey is 38
        button[2].display(true);
        println("Button 3 Pressed");
      }
      else {   //if the keycode is not UP aka 38 set the display method to false for the default
        button[2].display(false);//button deafault displayed
        println("Button 3 Not Pressed");
      }
    }

    //=============Button4=================

    void Button4() {
      if (currentKey == 39) { //the keycode for ASCII UP button on the keyboard is 40. Eval if currentKey is 40
        button[3].display(true);
        println("Button 4 Pressed");
      }
      else { //if the keycode is not UP aka 40 set the display method to false for the default
        button[3].display(false);//button deafault displayed
        println("Button 4 Not Pressed");
      }
    }
     //to draw current frame of video to the screen
    void dispVid() {

      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }   
      image(video, width/2, height/2+100);
    }

    //=======================CLASS=================
    class Button {
      color col; // color variable
      int x;
      int y;

      Button(int tempX, int tempY) { // constructor
        x = tempX;
        y = tempY;
      }


      void display(boolean tempState) {


        fill(155);//gray

        ellipse(x, 258, 60, 30); // Base of button

        if (tempState == true) {
          Pressed();
        }
        else {
          notPressed();
        }
      }

      //=======================notPressed=================
      void notPressed () {
        //Button Default

        fill(col);//color set 

        ellipse(x, 254, 50, 20);
        ellipse(x, 253, 50, 20);
        ellipse(x, 252, 50, 20);
        ellipse(x, 251, 50, 20);
        ellipse(x, 250, 50, 20);
        ellipse(x, 249, 50, 20);

        ellipse(x, 248, 50, 20);
        ellipse(x, 247, 50, 20);
        ellipse(x, 246, 50, 20);
        ellipse(x, 245, 50, 20);
      }


      //=======================Pressed=================
      void Pressed() {
        // Button Pressed

          fill(col);//color set

        ellipse(x, 254, 50, 20);
        ellipse(x, 253, 50, 20);
        ellipse(x, 252, 50, 20);
        ellipse(x, 251, 50, 20);
        ellipse(x, 250, 50, 20);
      }

      //=======================setColor=================
      void setColor(int tempR, int tempG, int tempB) {
        col = color(tempR, tempG, tempB);
      }
    }


Viewing all articles
Browse latest Browse all 1768

Trending Articles