Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all 2896 articles
Browse latest View live

How do you enable Mouse Wheel Events on "G4P-GUI Designer" controls

$
0
0

I am using G4P GUI Designer creating a PID Controller Screen to interface serially with a custom designed Arduino PID Controller. I created many Custom Sliders using the GUI Designer, but I do not get Mouse Wheel events through the G4P Slider Control Event Method. I want to use mouseWheel Events since it provides greater control of value settings than with mouseDragged Events, when considering my old shaky hands. I DO GET the G4P Control mouseWheel Events in my "Main Window", but how do I translate the mouseWheel(Event) to spSliderChange(Object, Event)? Or better yet, how do I get the mouseWheel Events to occur in the GUI slider event handlers?

Example Slider generated by GUI Designer (I have 10 of them total in GUI) which do not get mouseWheel Events, however the G4P controls do get mouse drag and steady events:

public void spSliderChange(GCustomSlider source, GEvent event) { //_CODE_:spSlider:950263:
  println("custom_slider1 - GCustomSlider >> GEvent." + event + " @ " + millis());
} //_CODE_:spSlider:950263:

public void createGUI() {
    G4P.messagesEnabled(false);
    G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
    G4P.setCursor(ARROW);
    surface.setTitle("Sketch Window");
    spSlider = new GCustomSlider(this, 120, 410, 300, 80, "blue18px");
    spSlider.setShowValue(true);
    spSlider.setShowLimits(true);
    spSlider.setRotation(PI/2, GControlMode.CORNER);
    spSlider.setLimits(0.5, 1.0, -1.0);
    spSlider.setShowTicks(true);
    spSlider.setNumberFormat(G4P.DECIMAL, 2);
    spSlider.setOpaque(false);
    spSlider.addEventHandler(this, "spSliderChange");
}

GCustomSlider spSlider;

And this in my "Main Window" which does get mouseWheel Events on slider:

void mouseWheel(MouseEvent event) {
    println(" - mouseWheel >> GEvent." + event + " @ " + millis());
}

I appreciate your input, who ever responds. I am not a GUI designer, but rather a low level 'C' and 'C++' coder. Your help is appreciated!

Thank you!


Text field input is displayed but not editable

$
0
0

Hi guys, I'm a newbie in processing I am working on a game that requires text field, but unfortunately it is not editable, and I do not know why,

here's the code:

`import controlP5.*;

//What level of the game the player is at //import controlP5.*; //controlP5 cp5; int level =0; //What is being shown, 1=Instructions, 2=Dead screen, 3=Win screen, 4=In game int screen = 1; //Time limit for levels (if 0, timelimit doesn't apply) int timelimit = 0; //Stage of instructions the player is it int instructionsStage=1; int r = int(random(2, 30)); int value = int(random(1, 10)); int parse=0; String toCheck=""; //did you die in the example of the instructions?(0 = dead, 1 = alive) int demoDead=1;

//MAIN GAMEPLAY array for mouse positions, for black slug effect, and position of robot (xpos[0],ypos[0]) int[] xpos=new int[40]; int[] ypos=new int[40];

//TUTORIAL PT1 array for mouse positions, for black slug effect, and position of robot (xpos[0],ypos[0]) int[] xpos1=new int[40]; int[] ypos1=new int[40];

String tx = "DONE! CLICK TO MOVE ON"; PFont f; boolean mouseIsDown = false; boolean loading = false;

import controlP5.*; ControlP5 cp5; String url1, url2;

//Function for the slug and robot (1 for normal game play, 2 for non-robot levels, 3 for tutorial pt1) /* void slug(int a){ if(a==1 || a==2){ background(255); //array values of mouse positions shift for (int i=0; i<xpos.length-1; i++){ xpos[i]=xpos[i+1]; ypos[i]=ypos[i+1]; } //current mouse position is allways joining the array xpos[xpos.length-1]=mouseX; ypos[ypos.length-1]=mouseY; //creates slug effect for (int i=0; i<xpos.length; i++){ noStroke(); fill(255-i6); ellipse(xpos[i],ypos[i],(i/4)3,(i/4)*3); } } if(a==3){ demoDead=1; //array values of mouse positions shift for (int i=0; i<xpos1.length-1; i++){ xpos1[i]=xpos1[i+1]; ypos1[i]=ypos1[i+1]; } //last array position is moved along x (controls speed and direction the example slug moves in the tutorial) if((xpos1[xpos1.length-1])<=200){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+10); } if(((xpos1[xpos1.length-1])>=200)&&((xpos1[xpos1.length-1])<=225)){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+1); } if(((xpos1[xpos1.length-1])>=225)&&((xpos1[xpos1.length-1])<=400)){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+10); } if(((xpos1[xpos1.length-1])>=400)&&((xpos1[xpos1.length-1])<435)){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+1); } if((xpos1[0])>=435){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+1); } //hides slug and robot for short period before restaring the demo if((xpos1[0])>405){ text("Dead",350,232); demoDead=0; } //restarts the demo if((xpos1[0])>=440){ demoDead=1; //resetting array for(int i=0;i<xpos1.length;i++){ xpos1[i]=80; ypos1[i]=300; } }

//RESTART THE DEMO ONCE FINISHED //creates slug effect //only if it's ment to be visible if (demoDead==1){ for (int i=0; i<xpos1.length; i++){ noStroke(); fill(255-i6); ellipse(xpos1[i],ypos1[i],(i/4)3,(i/4)*3); } }
} if (a==1){
for (int i=0; i<xpos.length; i++){ //draws robot being on last mouse position in the array fill(255,0,0); ellipse(xpos[0],ypos[0],50,50); } } if (a==3){
for (int i=0; i<xpos.length; i++){ //draws robot being on last position in the array //only if it's ment to be visible if (demoDead==1){ fill(255,0,0); ellipse(xpos1[0],ypos1[0],50,50); } } } }

*/

//Reused button, 1=instrutions part 1, 2=instructions part 2, 3=begin game, 4=continue game

void button(int a) { fill(255, 234, 41); noStroke(); if (a==1) { rect(300, 500, 150, 50); fill(0); textAlign(CENTER); textSize(32); text("Start", 375, 535); } if (a==2) { rect(300, 500, 150, 50); fill(0); text("Next", 375, 535); } if (a==3) { rect(300, 100, 150, 50); fill(0); text("Start!", 350, 132); } if (a==4) {

rect(300, 100, 150, 50);
fill(0);
text("Resume", 350, 132);

} }

//INSTRUCTIONS function (a=level of the game, 0=not started) void instructions() { background(255, 255, 255); textSize(72); cursor(CROSS); fill(0); if (instructionsStage==1) { textAlign(CENTER); text("Wa7ed Men Khamsa!", 100, 100, 600, 600); button(1); if ((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>500)&&(mouseY<550))) { instructionsStage++; } } if (instructionsStage==2) {

{
  background(255);
  if (mouseIsDown == true)
  {
    loading = true;
    frameCount = 1;
  }
  if (loading == false)
  {

    /* int r = int(random(2,30));
     text (r, 400, 300);

     fill(0);
     textAlign(CENTER);
     textSize(20);
     text (tx, 400, 400);

     if(mouseIsDown == true){ */
    instructionsStage++;
  }
}
if (loading == true)
{
  fill(0);
  textAlign(CENTER);
  textSize(32);
  text ("Counting the Passengers: " + int((frameCount%301) / 3) + "%", 400, 250);
  rect(300, 300, 204, 24);
  fill(255);
  int fillX = ((frameCount%301) / 3 * 2);
  rect(502, 302, fillX-200, 20);
  if (frameCount%301 == 0)
  {
    loading = false;
  }
}

}

/* text("The scientits have programmed each robot to follow your moves exactly when you hold down your mouse button, but 1 second behind, so if you move too slowly, it will catch you up, which will get you killed.",100,425,600,600); button(2); //slug(3); / / if((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>100)&&(mouseY<150))){ instructionsStage++; } } */ if (instructionsStage==3) {

text (r, 400, 300);


textSize(32);
text("Passengers", 100, 350, 600, 600);
button(2);
if ((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>500)&&(mouseY<550))) {
  instructionsStage++;
}

} if (instructionsStage==4) { textSize(20); text(r, 130, 100); text("*", 160, 100); text(value, 190, 100); text("=", 220, 100); text(toCheck, 250, 100); //converting string to int parse = parseInt(toCheck);

  cp5 = new ControlP5(this);

cp5.addTextfield("textInput_1").setPosition(20, 100).setSize(200, 40).setAutoClear(false); //cp5.addTextfield("textInput_2").setPosition(20, 170).setSize(200, 40).setAutoClear(false); cp5.addBang("Submit").setPosition(240, 170).setSize(80, 40);

text("If the ticket price is 1 L.E, and each passenger pays 5 L.E, what is the total of their payment?", 100, 400, 600, 600);




if (level==0) {
  button(3);
} else {
  button(4);
}
if ((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>100)&&(mouseY<150))) {
  screen=4;
  instructionsStage=0;
}

} }

void setup() { size(800, 660); background(255); //MAIN GAMEPLAY initializing array of mouse positions as all equalling 0 for (int i=0; i<xpos.length; i++) { xpos[i]=0; ypos[i]=0; } //TUTORIAL PT 1 initializing array of mouse positions for (int i=0; i<xpos1.length; i++) { xpos1[i]=80; ypos1[i]=300; }

f = createFont("Dotum-20.vlw", 20, true);

}

void draw() { if (screen==1) {

instructions();

}

if (screen==3) {

Submit();

}

if (screen==4) { background(255); text("This is the first level. I'll make this at some point", 200, 200); } }

void mousePressed() { mouseIsDown = true; }

//this function is called every time you release a mouse button void mouseReleased() { mouseIsDown = false; }

void Submit () {

print("the following text was submitted :"); url1 = cp5.get(Textfield.class, "textInput_1").getText(); //url2 = cp5.get(Textfield.class, "textInput_2").getText(); print(" textInput 1 = " + url1); //print(" textInput 2 = " + url2); println();

}`

How to run multiple sinOscs in class objects

$
0
0

Hi all, new to Processing and would appreciate some help!

I'm trying to make a class where each instance of it has a sinOsc playing at a different frequency, with a slowly decreasing (and then increasing) volume for each. I can't find much in the way of in-depth tutorials on this object, and am stuck! here's the code:

PImage img;
import processing.sound.*;
SinOsc sine;


Sphere s1;
Sphere s2;

void setup() {
  size(665, 800);
  img = loadImage("MK.png");
  s1 = new Sphere(random(0, (img.height/2)), random(0, (img.width/2)), 255, 10);
  s2 = new Sphere(random(0, (img.height/2)), random(0, (img.width/2)), 255, 17);
  sine = new SinOsc(this);
  image (img, 0, 0, img.width/2, img.height/2);

  s1.bells();
  s2.bells();
}

//variables
int time = millis();


void draw() {
  s1.run();
  s2.run();


}

`

and for the class (Sphere) itself:

class Sphere {

  //GLOBAL
  float xpos = 0;//set variables for the class, default for all of this type
  float ypos = 0;
  int col1 = 255;
  int decay = 8;
  int timer;
  Float amp = 0.5;
  Float freq = (random(80, 400));
  int trans = 255;



//CONSTRUCTOR
    Sphere(float _xpos, float _ypos, int _col1, int _decay){
      xpos = _xpos;//args for each instantiation can then alter the global vars
      ypos = _ypos;
      col1 = _col1;
      decay = _decay;
    }


void run(){
  display();

}

void display(){
fill(col1, 0, 0, trans);
  ellipse(xpos, ypos, 10, 10);//global vars now altered to reflect creation args

  if (millis() - timer >= (decay * 10)){
     trans = trans - 10;
     amp = amp - 0.1;
     timer = millis();
   }

  if (trans <= 0){
     trans = 255;
   }
}

void bells(){

  sine.play();
  sine.freq(freq);
  sine.amp(amp);

}
}

Any help would be appreciated!

Processing.net launch Client running on a thread

$
0
0

Hello,

I'm trying to improve the performance of a program using threads for the development of the heaviest tasks.

However, I have problems with this code, and I can´t find a solution.

What I can do?

import processing.net.*;


Client myClientC;

public class ClientThread extends Thread {


    public ClientThread(String str) {
        super(str);
    }
    public void run() {
      try{println("OK");
      Client myClientC = new Client(this, "192.168.1.88" , 6025);
      }catch(Error e){}
    }
}
void setup(){
        ClientThread AAA = new ClientThread("ClientThread 1");
        AAA.start();
     }

void draw()
{
}

stability issues with sound

$
0
0

hello!

im have almost no programming experience and would be greatful for help :-) i wrote a small program toggling a slideshow & sounds (mp3) with arduino buttons, but it doesn't run stable.

when i press the buttons on arduino quickly, processing crashes with an error window. i wouldn't mind, but others are going to use it in a situation where chances are high they will hit the buttons quickly! it crashes, saying:

Java(TM) SE Platform binary doesn't work any more

i figued, if i cut out the part of code dealing with sound, i can hit the arduino buttons in a frenzy without problems.


a second matter is, if i try to export the sketch and run it as an *.exe (i close processing entirely to free the serial port) it just loads some blank screen, nothing happens. i have no i idea what to look for in this second matte. i am still guessing it doesn't start because there's a communication issue between arduino and the program once it's an *.exe?

    import processing.serial.*;
    import processing.sound.*;
    import cc.arduino.*;

    PFont f;

    Arduino arduino;
    SoundFile nowplaying;

    int y;               // int für screensaver line
    int counter = 1;     // int welche bild/textdatei eingelesen wird

    int coinPin = 2;     //anschluss münzprüfer
    int enterPin = 4;    // anschluss button
    int relayPin = 8;    // anschluss button
    int servoPin = 10;   // anschluss servo

    int coinState = 0;    // münze ja/nein
    int enterState = 0;   // button ja/nein

    int counterMax = 10;
    color colA = color(237, 51, 57);
    color colR = color(random(256), random(256), random(256));


    void setup () {
      printArray(PFont.list());          //create a font
      f = createFont("Oxygen-Bold.ttf", 64);
      textFont(f);
      textAlign(CENTER, CENTER);

      arduino = new Arduino(this, Arduino.list()[0], 57600);
      arduino.pinMode(coinPin, Arduino.INPUT);
      arduino.pinMode(enterPin, Arduino.INPUT);
      arduino.pinMode(relayPin, Arduino.OUTPUT);
      arduino.pinMode(servoPin, Arduino.SERVO);
      arduino.digitalWrite(relayPin, 0);
      arduino.servoWrite(servoPin, 180);

      size(600, 600);        // window size
      background(loadImage(counter + ".jpg"));
      nowplaying = new SoundFile(this, (counter + ".mp3"));
    }


    void draw() {

      if (arduino.digitalRead(coinPin) == 1) {
        counter = 1;
        background(loadImage(counter + ".jpg"));
        coinState = 1;

      }

      if (coinState == 1 && enterState != arduino.digitalRead(enterPin)) {
        enterState = arduino.digitalRead(enterPin);

        if (enterState == 1) {
          counter = counter + 1;

          if (counter  <= counterMax) {

            background(loadImage(counter + ".jpg"));
            nowplaying.stop();
            nowplaying = new SoundFile(this, (counter + ".mp3"));
            nowplaying.play();
          } else {

            nowplaying.stop();
            counter = 0;
            coinState = 0;



            arduino.servoWrite(servoPin, 0);
            delay(1000);
            arduino.servoWrite(servoPin, 180);
          }
        }
      }


      if (coinState==0) {

        background(255);
        fill(colA);
        text("ENTER COIN", 300, 300);
        stroke(colA); // screensaver line
        line(0, y, width, y);
        y++;
        if (y > height) {
          y = 0;
        }
      }


    }

Live video feed and identify tags

$
0
0

Hello all, I am very new to processing and trackmate, actually my task is, I have to take input from camera(live video), from the the glass, there we put some cubes with tag, and I want to write code, so i can identify, which tag is placed on the glass top. Something like this image

please help

How do get the right/left channels of a sound output via Minim and Javasound

$
0
0

Hey all,

I'm working on a spatial sound installation project and have hit a wall when it comes to sending specific audio to specific speakers.

My setup:

  • Processing with Minim (playback and effects) and Javasound (targeting the different sound cards)

  • 3 stereo USB mini sound cards connected to a USB hub

  • 5.1 surround speakers with 3 stereo output jacks, 1 for front left/right, 1 for rear left/right, and 1 for center/subwoofer

The idea is that unique mp3s are played through each speaker, but I can't seem to get deeper than the stereo device level when assigning outputs in Minim, so I can only assign audio on a per-soundcard basis rather than a per left/right channel basis. After I've found the correct output mixer with the Mixer.Info class and set it with .setOutputMixer() to the AudioOutput, I'm at a loss for how to find each left/right channel within the Mixer object.

Printing the output from mixer.getTargetLineInfo() on one of the soundcard mixers I create just gives me a single result:

interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes

when I would expect to see something like

  • Output right channel
  • Output left channel

Has anyone figured out how to target on a per channel basis? This is way harder than I was imagining it would be.

Integrate 3D map and Proscene Library (Cameras Paths for Map)

$
0
0

Hello!

I am using a new library (github.com/dimr/mapzen-processing) developed by Dimitris Rongotis in order to generate a 3D map with open data. I'd like to generate a camera path through that map. Basically so that people can "site see" along the map. I'll be embedding poems inside the map, and zooming up to look at them. Also thinking about scraping tweets, embedding them into the map in real time, and setting the camera to look at new ones that show up on the map (they're geo-located). Thing is, for some reason, pro-scene is cutting off sections of the map and I can't figure out why? Does anybody have any idea why this is happening?

import main.Mapzen;
import main.net.MapzenUrl;
import main.net.MapzenUrlBuilder;
//import peasy.PeasyCam;
import toxi.geom.Vec3D;
import toxi.processing.ToxiclibsSupport;
import java.util.List;

import remixlab.proscene.*;
import remixlab.bias.core.*;
import remixlab.bias.event.*;
import remixlab.dandelion.geom.Vec.*;


/**
 * Created by dimitris on 4/7/16.
 */

//PeasyCam cam;
private Mapzen mapzen;
ToxiclibsSupport toxi;

Scene scene;
ArrayList buttons;
float h;
PFont buttonFont;

float xCounter;
float yCounter;
float rCounter;
float clickCounter;
PFont font;
int camPosition = 0;

//***THIS IS WHERE YOU WILL PLUG IN COORDINATES;
//This is coordinates from your tweets, Vec3D is similar to PVector
Vec3D TweetCoordinate = new Vec3D(-122.408162, 37.755468, 0);
//this will hold coordinates converted to application dimensions
Vec3D convertedTweetCoordiante;
PGraphics pg;

public void setup() {
  // **do not** use setLayrers("roads")...only buildings
  MapzenUrl url = new MapzenUrlBuilder().setLongitude(-122.409531f).setLatitude(37.782281f).setZoom(13).setLayer("buildings").setKey("vector-tiles-PADQnWp").buildUrl();
  mapzen =  new Mapzen(this, url); //this PApplet size

  //scene.setBoundingBox(new Vec(0, 0, 0), new Vec(width, height, 1000));
  //scene.setRadius(1500);
  //scene.setCenter(new Vec(width/2, height/2));
  //scene.camera().setPosition(new Vec(width/2, height/2, 1000));

  scene = new Scene(this);
  //create a camera path and add some key frames:
  //key frames can be added at runtime with keys [j..n]
  scene.camera().setPosition(80, 0, 0);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  scene.camera().setPosition(30, 30, -80);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  scene.camera().setPosition(-30, -30, -80);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  scene.camera().setPosition(-80, 0, 0);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  //re-position the camera:
  scene.camera().setPosition(0, 0, 1);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.showAll();

  //this is the speed;
  scene.camera().keyFrameInterpolator(1).setInterpolationSpeed(0.1f);

  //drawing of camera paths are toggled with key 'r'.
  scene.setPathsVisualHint(true);

  buttons = new ArrayList(6);
  for (int i=0; i<5; ++i)
    buttons.add(null);

  buttonFont = loadFont("FreeSans-16.vlw");

  Button2D button = new ClickButton(scene, new PVector(10, 5), buttonFont, 0);
  h = button.myHeight;
  buttons.set(0, button);

  toxi=new ToxiclibsSupport(this);
  smooth();

  //coordinate convertion takes place
  convertedTweetCoordiante=mapzen.convert(TweetCoordinate);

  font = createFont("A.vlw", 200);
  textFont(font, 200);
  textMode(SCREEN);
}



public void draw() {
  background(0);

  //TEXT MANIPULATION;
  fill(255, 255);
  textSize(12);

  //#1; THIS IS THE TESTIMONY-TEXT;
  pushMatrix();
  translate(854, 1000, 5);
  rotateZ(-.0459);
  translate(-854, -1000, -5);
  text("1033 York St. : out of state partners, flipping the property, the Ellis eviction process, adversarial, unprofessional, renovations on a vacant unit, harassment, off the power without notice - settlement.", 854, 1000, 200, 200);
  popMatrix();

  //#2; THIS IS THE QUESTION-TEXT;
  pushMatrix();
  translate(1500+100, 500, 250);
  rotateZ(-.0459);
  rotateX(-1.6549987);
  rotateY(0.9099993);
  translate(-1500-100, -500, -250);
  translate(0, 0, 250);
  text("Is this the future we want or is it another, one where we manage the space and the data together?", 1500, 500, 200, 200);
  translate(0, 0, -250);
  popMatrix();

  //#3; THIS IS THE ADVERTISING-TEXT;
  pushMatrix();
  translate(1100, -100, 100);
  rotateZ(3.0100214);
  rotateX(4.71506);
  translate(-1100, +100, -100);
  translate(0, 0, 100);
  text("Anti-Eviction: antievictmap.com Data-Protection: ssd.eff.org Broadcasting: saitogroup.info 415-617-9782", 1000, -100, 200, 200);
  translate(0, 0, -100);
  popMatrix();

  //THIS IS THE MARKER OF THE HOUSE;
  pushMatrix();
  pushStyle();
  strokeWeight(2);
  stroke(255, 255, 255);
  translate(convertedTweetCoordiante.x(), convertedTweetCoordiante.y(), 0);
  float t=map(sin(frameCount*.2), -1, 1, 0, 200);
  line(0, 0, 0, 0, 0, t);
  popStyle();
  popMatrix();

  //THIS IS THE CAMERA STEERING APPARATUS;
  //COUNTERS;
  //pCounter++;
  //rCounter+=.00002;
  //DISCOVERY;
  //.getRotations();
  //.getPosition();
  //.getDistance();
  //IMPLEMENTATION;
  //cam.rotateX(rCounter);
  //cam.rotateY(rCounter);
  //cam.rotateZ(rCounter);
  //cam.setDistance(z);
  //cam.pan(x,y);
  //GET A POSITION;
  //println(cam.getLookAt());
  //println(cam.getRotations());
  //THIS IS A VERY SHITTY WAY OF STEERING THE CAMERA;
  //println(cam.getRotations());
  //println(cam.getPosition());
  //println(cam.getDistance());

  // for now: renderPolygons(red,green,blue,opacity) -->fill of the buildings, all sides of the building get the same fill color you set here
  mapzen.renderPolygons(255, 255, 255, 150);
  // drawGeoRoads(red,green,blue,strokeWeight)
  mapzen.drawGeoRoads(100, 100, 100, 1);

  updateButtons();
  displayButtons();
}

public void settings() {
  //        size(1300,850);
  size(1900, 1050, "processing.opengl.PGraphics3D");
  //        fullScreen(P3D,2);
}


void updateButtons() {
  for (int i = 1; i < buttons.size(); i++) {
    // Check if CameraPathPlayer is still valid
    if ((buttons.get(i) != null) && (scene.camera().keyFrameInterpolator(i) == null ) )
      buttons.set(i, null);
    // Or add it if needed
    if ((scene.camera().keyFrameInterpolator(i) != null) && (buttons.get(i) == null))
      buttons.set(i, new ClickButton(scene, new PVector(10, + ( i ) * ( h + 7 )), buttonFont, i));
  }
}

void displayButtons() {
  for (int i = 0; i < buttons.size(); i++) {
    Button2D button = (Button2D) buttons.get(i);
    if ( button != null )
      button.display();
  }
}

/**
 * Button 2D.
 * by Jean Pierre Charalambos.
 *
 * Base class of "2d buttons" that shows how simple is to implement
 * a MouseGrabber which can enable complex mouse interactions.
 */

public abstract class Button2D extends GrabberObject {
  public Scene scene;
  String myText;
  PFont myFont;
  float myWidth;
  float myHeight;
  PVector position;

  public Button2D(Scene scn, PVector p, PFont font) {
    this(scn, p, font, "");
  }

  public Button2D(Scene scn, PVector p, PFont font, String t) {
    scene = scn;
    position = p;
    myText = t;
    myFont = font;
    textFont(myFont);
    textAlign(LEFT);
    setText(t);
    scene.motionAgent().addGrabber(this);
  }

  public void setText(String text) {
    myText = text;
    myWidth = textWidth(myText);
    myHeight = textAscent() + textDescent();
  }

  public void display() {
    pushStyle();
    fill(255);
    if (grabsInput(scene.motionAgent()))
      fill(255);
    else
      fill(100);
    scene.beginScreenDrawing();
    text(myText, position.x, position.y, myWidth+1, myHeight);
    scene.endScreenDrawing();
    popStyle();
  }

  @Override
  public boolean checkIfGrabsInput(DOF2Event event) {
    float x = event.x();
    float y = event.y();
    return ((position.x <= x) && (x <= position.x + myWidth) && (position.y <= y) && (y <= position.y + myHeight));
  }
}

public class ClickButton extends Button2D {
  int path;

  public ClickButton(Scene scn, PVector p, PFont font, int index) {
    this(scn, p, font, "", index);
  }

  public ClickButton(Scene scn, PVector p, PFont font, String t, int index) {
    super(scn, p, font, t);
    path = index;
  }

  @Override
    public void performInteraction(ClickEvent event) {
    if (event.clickCount() == 1)
      if (path == 0)
        scene.togglePathsVisualHint();
      else
        scene.eye().playPath(path);
  }

  public void display() {
    String text = new String();
    if (path == 0)
      if (scene.pathsVisualHint())
        text = "don't edit camera paths";
      else
        text = "edit camera paths";
    else {
      if (grabsInput(scene.motionAgent())) {
        if (scene.eye().keyFrameInterpolator(path).numberOfKeyFrames() > 1)
          if (scene.eye().keyFrameInterpolator(path).interpolationStarted())
            text = "stop path ";
          else
            text = "play path ";
        else
          text = "restore position ";
      } else {
        if (scene.eye().keyFrameInterpolator(path).numberOfKeyFrames() > 1)
          text = "path ";
        else
          text = "position ";
      }
      text += ((Integer) path).toString();
    }
    setText(text);
    super.display();
  }
}

Send Email From Processing

$
0
0

I am looking to send an Email from Processing. I am gathering data, and would like an easy way to send alerts when certain events happen.

It looks like this has been covered in the past but most of the resources have been deprecated. Shiffman had a pretty good one but that is not listed anymore: http://www.shiffman.net/2007/11/13/e-mail-processing/

Is this an easy thing to do? I figured it might be fairly useful and widespread.

Thank you for any tips or advice.

How to make a video stop playing and screen++;

$
0
0

Hi guys, I have a basic set up of an animation storyline in which when the user clicks the mouse or does certain interactions, it then runs the next 'screen' or next animation. The issue I'm having is that on screen 5 a click of the mouse plays a video I made in after effects. However, this video then stops on the last frame and stays. I cannot work out how to 'screen++' after the video stops. I have tried duration, millis, etc. and nothing seems to be working. Could somebody please shed some light on what might be going on, or how I could achieve this?

import processing.video.*;
Movie myMovie;

Cell[] cells= new Cell[1000];

float x, y;
PFont Baskerville;
int screen=1;
int drawRandomLines = 0;
int ellipseSize = 0;
int totalCells = 0;

void setup () {
  size(1024, 768);
  smooth(3);
  noStroke();
  Baskerville = createFont("Baskerville", 30);
  textFont(Baskerville);
  textAlign(CENTER);
  noStroke();
  x = width/2;
  y = 0;
  myMovie = new Movie(this, "dominant_species.mov");
  //myMovie.play();
}

void draw () {

  if (screen==1) {
    background(4, 16, 36);
    fill(255, 219, 157);
    noStroke();
    //draw first screen
    ellipse(512, 384, 16, 16);
    text("Here is a cell.", width/2, height/2-40);

    // } if (y >= 384) {

    //y = height/2;

    text("Here is a cell.", width/2, height/2-40);
  } else if (screen==2) {
    background(4, 16, 36);

    fill(255, 219, 157, 20);
    rect(mouseX, 0, -mouseX, 768);
    fill(255, 219, 157);
    text("One of millions in the body.", width/2, height/2-40);

    cells[totalCells] = new Cell();

    totalCells ++ ;

    if (totalCells >= cells.length) {
      totalCells = 0;
    }

    for (int i = 0; i < totalCells; i++) {
      cells[i].move();
      cells[i].display();
    }

    if (mouseX >= 900) {
      screen++;
    }

    if (mouseY < 10 ) {
      screen++; //add one onto screen
    }
  } else if (screen==3) {
    background(255, 219, 157);
    //background(4,16,36);
    //draw third screen
    //testing to see if the mouse is inside a circle
    fill(4, 16, 36);
    text("Throughout our daily lives...", width/2, height/2-40);
  } else if (screen==4) {
    background(255, 219, 157);
    noStroke();

    text("our cells duplicate in order to heal and develop.", width/2, height/2+200);


    fill(4, 16, 36);
    ellipse(width/2-40, height/2-40, ellipseSize, ellipseSize);
    ellipse(width/2+40, height/2+40, ellipseSize, ellipseSize);
  } else if (screen==5) {
    background(4, 16, 36);
    noStroke();

    fill(255, 219, 157);
    text("That's how we've gone from a single celled organism...", width/2, height/2-20);
    image(myMovie, 0, 0);

    fill(4, 16, 36);
    ellipse(width/2-40, height/2-40, ellipseSize, ellipseSize);
    ellipse(width/2+40, height/2+40, ellipseSize, ellipseSize);
    //draw fifth screen
    //image(myMovie, 0, 0);
  }
}

//called only once when the user presses the mouse
void mousePressed () {
  if (screen==1) {
    //testing for a button notice it is the same bounds as the
    //rect we are drawing in the test for screen==1 inside draw
    //you could just write 170 instead of 130+40 but I left this
    //here so you can see how the test values relate to the rect coordinates
    float d = dist(mouseX, mouseY, 512, 384);

    if (d<20) {
      screen++;
      //myMovie.play();
    }
  } else if (screen==5) {

    myMovie.play();
  } else if (screen==3) {
    screen++;
  }
}


//called whenever the mouse is movoed
void mouseMoved () {
  if (screen == 4) {
    ellipseSize=ellipseSize+5;
    if (ellipseSize > width) {
      println("threshold");
      //take us back to the beginning
      //reset all of our variables
      //screen=1;
      drawRandomLines = 0;
      ellipseSize = 0;
      screen++;
    }
  } else if (screen == 6) {
    //take a look inside the screen==5 inside draw
    //ellipseSize++;
    //if (ellipseSize > width) {
    //println("threshold");
    //take us back to the beginning
    //reset all of our variables
    //screen=1;
    //drawRandomLines = 0;
    //ellipseSize = 0;
  }
}


void movieEvent(Movie m) {
  m.read();
}


//NEW TAB__ CELL CLASS

class Cell {

  float x, y;   // Variables for location of raindrop
  float speed; // Speed of raindrop
  color c;
  float r;     // Radius of raindrop

  Cell() {
    r = 8;                 // All raindrops are the same size
    x = random(mouseX);     // Start with a random x location
    y = -r*4;              // Start a little above the window
    speed = random(1, 5);   // Pick a random speed
    c = color(255,219,157); // Color
  }

  // Move the raindrop down
  void move() {
    // Increment by speed
    y += speed;
  }

  // Check if it hits the bottom
  boolean reachedBottom() {
    // If we go a little beyond the bottom
    if (y > height + r*4) {
      return true;
    } else {
      return false;
    }
  }

  // Display the raindrop
  void display() {
    // Display the drop
    fill(c);
    noStroke();
    ellipse(x, y, r*2, r*2);
  }

}
`

New in processing, constructor problem.

$
0
0

Hello, I'm new on processing. I'm trying to put my sketch in a class, so I can later on build more stuff on top. But a the very beginning of that I get an error on : cam = new Capture(this, 320, 240, 30); "the constructor doesn't exist". But it does, it's in the library. Any idea how to solve that ? Thanks

import processing.video.*;
Pixi myPixi;

void setup() {

  size(1200, 1200);
  myPixi = new Pixi();
}


void draw() {

  myPixi.trans();
}


class Pixi {

  int pointillize = 36;
  int Lx[] = {1, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300};
  int Ly[] = {1, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220};

  Pixi() {

    Capture cam;
    cam = new Capture(this, 320, 240, 30);
    cam.start();
    background(0);
    rectMode(CENTER);
  }



  void trans() {

    cam.read();
    int x = Lx[ (int) random(Lx.length) ];
    int y = Ly[ (int) random(Ly.length) ];
    int loc = x + y*cam.width;
    loadPixels();
    float r = red(cam.pixels[loc]);
    float g = green(cam.pixels[loc]);
    float b = blue(cam.pixels[loc]);
    noStroke();
    fill(r, g, b, 255);
    rect(((x+150)*2), ((y+150)*2), pointillize, pointillize);
  }
}

Sound library does not work in Eclipse

$
0
0

Hi all,

I have got stuck by this trouble. I am now using Eclipse to write the programs of Processing, and I kept having troubles. The latest one I am facing is regarding the Sound library. I created a SinOsc object and use

sine = new SinOsc(this);

to initialise a new object. It works fine in Processing, but when I run it in Eclipse, the error messages pop out:

Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: no MethClaInterface in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at processing.sound.MethClaInterface.(Unknown Source)
    at processing.sound.Engine.(Unknown Source)
    at processing.sound.Engine.(Unknown Source)
    at processing.sound.Engine$LazyHolder.(Unknown Source)
    at processing.sound.Engine.start(Unknown Source)
    at processing.sound.SinOsc.(Unknown Source)
    at SoundExperiment.setup(SoundExperiment.java:15)
    at processing.core.PApplet.handleDraw(PApplet.java:2378)
    at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1527)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

Here is the whole code:

import processing.core.PApplet;
import processing.sound.*;

public class SoundExperiment extends PApplet {
    SinOsc sine;

    public void settings(){
        size(600,600);
    }

    public void setup(){
        sine = new SinOsc(this);
        sine.play();
    }

    public void draw(){

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        PApplet.main("SoundExperiment");
    }
}

Thank you!!

Blob detection

$
0
0

I was just wondering if it is possible to use blob detection to trigger a key board press. so if my hand went over to a certain part of the screen where i want it to correlate to the letter "w" for example it signals that "w" was pressed on the keyboard?

i have downloaded the blob detection library but im not to sure how to use it what i want to do is have 4 different buttons so when blob detection picks up the blob it that specific area it would either play a video or signal a keyboard press to play a video in resolume?

how to identify which client disconnected from the server at server side application.

$
0
0

when many no. clients are connected with the server and for any reason when clients disconnected or closed socket with server , how to identify which of the clients disconnected from server at server side application program.

Camera - Area Detection and Interaction problem

$
0
0

Hi there,

I was wondering if anyone could help me detect whether or not there is movement in just a specific area of a camera capture?

The idea is if a hand is moving in one area, an object starts to move one way, if movement is detected in the a different area the object moves the other way.

I've looked at the motion sensor example (http://learningprocessing.com/examples/chp16/example-16-14-MotionSensor) but I'm not sure how to just limit the 'sensor' to certain regions on the screen!

Would really appreciate any help!!

Thanks.


Simpleopenni.jar in Ubunto 12

$
0
0

I wrote my sketch in processing 2.2.1 at windows 7 64 bit. To avoid CPU Consuming, I decided to build a script which is executable in Linux utilizing export feature of processing. Although both of original sketch in Windows 7 and its standalone file run perfectly in windows 7, but the linux script (standalone file for linux namely linux.application64) does not run in Ubunto 12. Noting I use last version of Simpleopenni library in my code and i get the following error: "cant load Simpleopenni library (libsimple openni64.so):java.lang.unsatisfied link error: cant load the library"

Would you please help me to solve this problem?

Bests

Running example SMT

$
0
0

Hi,

I'm new to Processing. I'm trying to run the bacis SMT example but I have this error that I don't understand how to solve it : processing.core.PApplet$6 cannot be cast to javax.swing.JFrame

If you have any tips, thanks in advance

ControlP5 Matrix using arduino

$
0
0

Hi Folks,

I've created a drum sequencer using the controlP5 matrix and I'm looking to use pushbuttons on an Arduino to turn on and off the buttons. Firstly, is this possible? and if so, how do I tell the matrix to take input from the pushbutton instead of the mouse click?

Any help would be much appreciated.

Cheers,

tactu5

$
0
0

Hi, I'm having no success trying to import the tactu5 library version 1.0.2 under processing 3.1.1 (I'm running on a Mac with Yosemite 10.10.5). I get an error saying that there was an "Error during download and install of tactu5." It created a temporary folder in the libraries folder but the example program SimpleExample.pde can't find any of the library files. Does anyone know of a work around?

Collision with boundaries

$
0
0

Hello, do you know how to do that when a ball collisions with a specific boundary, make a sound? This is the code

//import pbox2d.*; //import org.jbox2d.common.*; //import org.jbox2d.dynamics.joints.*; //import org.jbox2d.collision.shapes.*; //import org.jbox2d.collision.shapes.Shape; //import org.jbox2d.common.*; //import org.jbox2d.dynamics.*;

//PBox2D box2d; ArrayList balls; ArrayList boundaries;

boundaries.add(new Boundary(108.32, 402.37, 33.72, 5, 320)); boundaries.add(new Boundary(184, 461, 36.27, 5, 319));

void setup() { size(1280, 720); smooth(); //box2d = new PBox2D(this); //box2d.createWorld(); //box2d.setGravity(0, -20); balls = new ArrayList(); }

void keyPressed() { if (key=='z') { balls.add(new Ball(63, 0, 8)); } }

void draw() { background(0); //image (fondo, 0, 0); //box2d.step(); for (Ball b : balls) { b.draw(); } }

class Ball { float px, py, r, vx, vy, ax, ay; Ball(float ix, float iy, float ir) { px=ix; py=iy; r=ir; vx=0; vy=0; ax=0; ay=1; } void draw() { simulate(); render(); } void simulate() { vx+=ax; vy+=ay; px+=vx; py+=vy; } void render(){ fill(255,0,0); ellipse(px,py,r,r); } }

Viewing all 2896 articles
Browse latest View live