User Tools

Site Tools


cs276:calm_stop_go

This example uses two tabs: Stop_And_Go and Lights. Lights defines a class for naming the lights of a stop light.

Stop_And_Go.pde

import de.voidplus.leapmotion.*;
 
/* NOTES:
 * Use the concepts you've learned (and maybe some code you've used) from the previous
 * assignment to help complete the following objectives. A gesture method has been
 * provided for you that determines the direction of a circle motion made with your finger. 
 * Make sure you learned how to make a recognized circle gesture in the Leap Motion Visualizer
 * The animation frame rate is initially set to one per second so be patient if the program seems
 * somewhat sluggish. A center circle has also been provided to you as a starting point.
 *
 * +== OBJECTIVES ==+
 * 1. Draw three identical circles in a vertical configuration (like a stop light)
 * 2. Make all three circles turn green for a clockwise gesture
 * 3. Make all three circles turn red for a counterclockwise gesture
 *
 * Hint: Add a fill color to your gesture switch cases.
 */
 
LeapMotion leap;
Lights stop, wait, go;
void setup() {
  size(200, 600, OPENGL); //size of our screen
  background(255); //sets the background to white
  frameRate(1); //sets a REALLY SLOW frame rate
  smooth(4);
  stop = new Lights(width/2, height/2 - 150, 100, color(255, 0, 0));
  wait = new Lights(width/2, height/2, 100, color(255, 255, 0));
  go = new Lights(width/2, height/2 + 150, 100, color(0, 255, 0));
  leap = new LeapMotion(this).withGestures(); //alows gestures
}
 
void draw() 
{
  background(255); //sets the background to white 
  /*
  stroke(#083902); //stroke sets the color to be used around shapes, RGB value is (8,57,2), 
  ellipse(width/2, height/2 - 150, 100, 100); // top circle
  stroke(#083902); //stroke sets the color to be used around shapes, RGB value is (8,57,2), 
  ellipse(width/2, height/2, 100, 100); // center circle
  stroke(#083902); //stroke sets the color to be used around shapes, RGB value is (8,57,2), 
  ellipse(width/2, height/2 + 150, 100, 100); // lower circle
  */
  stop.drawit();
  go.drawit();
  wait.drawit();
}
 
 
void leapOnCircleGesture(CircleGesture g, int state)  //this method tells us what to do when a circle gesture is detected
{
  int     id               = g.getId();
  Finger  finger           = g.getFinger();
  PVector position_center  = g.getCenter();
  float   radius           = g.getRadius();
  float   progress         = g.getProgress();
  long    duration         = g.getDuration();
  float   duration_seconds = g.getDurationInSeconds();
  int     direction        = g.getDirection(); //we do not need a lot of these, but they do not hurt!
 
 
  switch(direction) 
  {
  case 0: // Counter Clockwise rotatation
    System.out.println("STOP"); //So you can see if the Leap is detecting a counter clockwise direction in the console.
    // if it does, you will see STOP printed in the console, and hopefully results in your screen
    go.off();
    wait.on();
    // Figure this one out!!! Thread.wait(200);
    wait.off();
    stop.on();
    break;
  case 1: // Clockwise/Right gesture
    System.out.println("GO");
    go.on();
    stop.off();
    wait.off();
    break;
  }
}

Lights.pde:

class Lights {
  color fillC, fillOn, fillOff = 255;
  int xpos, ypos, size;
 
  Lights(int x, int y, int sz, color c) {
    fillOn = c;
    xpos = x;
    ypos = y;
    size = sz;
    fillC = fillOff;
  }
 
  void drawit() {
    fill(fillC);
     stroke(#083902); 
    ellipse(xpos, ypos, size, size);
  }
 
  void on() {
    fillC = fillOn;
    drawit();
  }
 
  void off() {
    fillC = fillOff;
    drawit();
  }
}
cs276/calm_stop_go.txt · Last modified: 2016/11/05 11:15 by scarl