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

Re : I am trying to create a sort of photoBooth In Processing

$
0
0
ok well Hopefully you can help with the button problem and maybe try the video anyway here is the code

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

    //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();


      ellipseMode(CENTER);
    }
    //======================END SETUP===================



    void draw () {

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

      //Calls the Specific Button from the Void Button
      Button0();

      Button1();

      Button2();

      Button3();

      image(video, width/2, height/2+100);
    }



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

    void Button0() {

      if (keyPressed) {
        if (keyCode == UP) {

          button[0].display(true);
          state = true;
        }
      }
      else {

        button[0].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }
      tint(mouseX, mouseY, 255);
    }

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


    void Button1() {
      if (keyPressed) {
        if (keyCode == DOWN) {
         
          button[1].display(true);
          state = true;
        }
      }
      else {
       
        button[1].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }
    }
    //=============Button3=================

    void Button2() {
      if (keyPressed) {
        if (keyCode == LEFT) {
         
          button[2].display(true);
          state = true;
        }
      }
      else {
       
        button[2].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }
    }

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

    void Button3() {
      if (keyPressed) {
        if (keyCode == RIGHT) {
         
          button[3].display(true);
          state = true;
        }
      }
      else {
       
        button[3].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }
    }
    //=======================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