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

How to choose a movie file to play?

$
0
0

I wrote a simple movie player that can play and pause, but I want to be able to for the sketch to wait for a key to be pressed that would play the said movie.

So nothing happens until you press '1' and then 'movie 1' is played.

(I'm pretty new to Processing but i think i've taught myself the basics, and I suspect redraw could be used for this?)


Proscene a few basic ? questions

$
0
0

turning off the default grid should be ? : scene.setGridIsDrawn(false); But dropping this into the BasicUse example(or any other) I get the error " The function "setGridIsDrawn(boolean)" does not exist"

Is it possible to change the orientation of this default grid ?

My scene consists of a number of small spheres arranged in the shape of a large sphere, I have these small spheres constrained so they can't be moved or scaled, what I would like to do is to be able to read out which one of these small spheres has been clicked/selected.... are there any basic examples anywhere that would show how this could be achieved(I can't see anything in the included examples)

cheers, mala

Manipulating Minim library for more accurate beat detection?

$
0
0

Hello, I've been looking at the minim library to implement a sort of DSP on my project. Simply put, I would like to detect the beats of an audio file, namely, the high, mid and low frequencies.

The minim website has a good amount of documentation, but I am unable to wrap my head around some of the concepts. To start, the library includes an inbuilt beat detection function.

However during my testing, the detected onset are not accurate. Naturally this boils down to the different genre and type of music the library was built on and the audio input I have fed the function. I have tried altering the values in the given example but I am unable to understand how the

beat.isRange(lowBand, highBand, numberOfOnsetsThreshold)

works.

Would I be better of implementing my own beat detection using FFT if I would just like to achieve generally accurate beat detection for most genre of music? And if so, are there any examples on how to do so once I have audio spectrum composed?

Contribution manager problems -- where to report?

$
0
0

Where do we report problems in the PDE contribution manager?

For example, in Processing 3.2.1 on OS X 10.10.5, my Libraries tab lists as available / compatible:

ToxicLibs 22

Installing (Install button) results in a temporary folder appearing in my /libraries, e.g.:

library5842271132355056316tmp/toxiclibs/

...and then a few seconds later it is deleted, with the message:

Could not find a library in the downloaded file.

PS3 controller on Macbook does not show up in the Game Control Plus library

$
0
0

Hi guys!

I am trying to control an Arduino based rescue robot with a playstation 3 controller through processing, but somehow processing is not able to 'see' the ps3 controller. I did manage to link the controller to my laptop (2014 macbook pro with MacOs Sierra) via bluetooth. And also when I run Enjoy2 (program to map ps3 buttons), it does work perfectly. So there is no question whether the ps3 is connected and working.

But when I am running the example sketch ShowDevices.pde from the Game Control Plus library in Processing, the ps3 controller does not show up. I am using processing 3.1.2 btw. I have searched the whole internet for a solution, but as far as I know, nobody has tried to connect a ps3 controller to processing with the latest macOS. I am wondering if somebody knows how to solve this problem, or, if there is an other way to read and process the input from a ps3 controller with processing (wired or via bluetooth).

with kind regards, Bas

Unfolding Maps — mapDisplay.getOuterPG() is not working!

$
0
0
import processing.core.PApplet;
import processing.core.PGraphics;

import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.providers.OpenStreetMap;
import de.fhpotsdam.unfolding.utils.MapUtils;


    private UnfoldingMap map;
    private PGraphics pg;

    private int n = 1000;

    public void setup() {

        size(n, n, P2D);
        map = new UnfoldingMap(this, new OpenStreetMap.OpenStreetMapProvider());
        MapUtils.createDefaultEventDispatcher(this, map);

    }

    public void draw() {

        background(0);
        pg = map.mapDisplay.getOuterPG();
        image(pg, 0, 0);

    }

Greetings! When I try to convert maps into PGraphics and display it, I see only black background :( Can anyone explain why it is so? Thank you!

Game Control Plus + PS Move Navigation Controller

$
0
0

I've been experimenting with the Playstation Move Navigation Controller. One analog stick, one D-pad, L1, L2, X and O buttons.

The Game Control Plus library identifies the Navigation Controller by name when connected through USB, but misreads its configuration, presenting it identically to the Playstation(R)3 Controller layout. Additionally, the controller doesn't actually function with the Game Control Plus examples (though a regular PS3 controller works). This may be because the Navigation Controller will not pair with Bluetooth in OSX; the controller is only connected via USB.

Every other controller mapping utility for OSX seems to have this problem, including software such as ControllerMate or 3rd party libraries such as psmoveapi and similar. So this problem is not unique.

But the Arduino USB Host Library 2.0 handles the PS Move Navigation Controller (though USB or Bluetooth) so it seems like it's not a limitation of the accessory itself:

https://github.com/felis/USB_Host_Shield_2.0

For Game Control Plus, is this a limitation of the underlying JInput library, or something that can be addressed in the GCP Processing Library? From browsing the forums here it looks like PS3 support was added by @quark last winter so that makes me think that each separate accessory might need to be accounted for independently in the library. Is that accurate?

Has anyone successfully used the PS Move Navigation Controller with Game Control Plus (or any other solution) for OSX?

calling cp5 elements from inside a class

$
0
0

Hi all, I'm a little stuck with this controlP5 problem. I went through some code to solve it but had no success with it. What I aim to do is to map these gui elements/controls to data but I think because they're in their own class there's another way to call them though couldn't figure out how. I placed the controlEvent in the main window and it succeeds to read the values but somehow I'm not able to map them. I would appreciate if someone could point me in the right direction here. Should I be adding callbacks to the individual sliders within the class? what's the proper way to do this?

thanks _ö

PS: I just patched the interface into a scene, the content is basically just for me to be able to visualise it.

int margin;
Top [] tops = new Top[100];
Interface gui;
String s;
float val;
color col;

void setup() {
  size(600, 400);
  margin = 200;
  col = 127;

  gui  = new Interface(this);
  gui.build();

  for (int i = 0; i < tops.length; i++) {
    tops[i] = new Top(margin);
  }
}


void draw() {
  background(80);
  fill(col);
  rectMode(CENTER);
  rect(width/2, height/2, width - margin, height - margin);


  for (int i = 0; i < tops.length; i++) {
    tops[i].display();
    //tops[i].update();
    //tops[i].borders();
  }
}

// to be mapped: col, margin, tops[i].maxSpeed, tops[i].maxForce

void controlEvent(CallbackEvent theEvent) {
  s = theEvent.getController().getName();
  val = theEvent.getController().getValue();
  println(s, val);
  margin = (int)map(val, 100, 500, 100, 300);
  for (int i = 0; i < tops.length; i++) {
    tops[i].r = (int)map(val, 100, 500, 5, 20);
  }
}


class Top {
  int margin, r;
  float x, y;
  PVector location, velocity, acceleration;
  float maxSpeed, maxForce;
  PVector noff;

  Top(int margin_) {
    margin = margin_;
    r = 5;
    int side = int(random(0, 3.9));
    switch(side) {
    case 0:
      x= random(width);
      y= random(margin/2);
      break;
    case 1:
      x= random(width);
      y= random(height-margin/2, height);
      break;
    case 2:
      x= random(margin/2);
      y= random(height);
      break;
    case 3:
      x= random(width-margin/2, width);
      y= random(height);
      break;
    }


    location = new PVector(x, y);
    velocity = new PVector();
    acceleration = new PVector(0, 0);
    noff = new PVector (random(1000), random(1000), random(1000));
    maxSpeed = 3;
    maxForce = 0.15;
  }
  void update() {
    acceleration.x = map(noise(noff.x), 0, 1, -1, 1);
    acceleration.y = map(noise(noff.y), 0, 1, -1, 1);
    //acceleration.z = map(noise(noff.z), 0, 1, -1, 1);
    noff.add(0.001, 0.001, 0.001);


    velocity.add(acceleration);
    velocity.limit(maxSpeed);
    location.add(velocity);
    acceleration.mult(0);

    if (location.x<0||location.x>width) velocity.x *=-1;
    if (location.y<0||location.y>height) velocity.y *=-1;

    /*
    boolean A,B,C,D;

     if(location.y<margin/2) A = true;
     else A = false;
     if(location.x>width-margin/2) B = true;
     else B = false;
     if(location.y>height-margin/2) C = true;
     else C = false;
     if(location.x<margin/2) D = true;
     else D = false;

     if(location.y>margin/2 && !B && !C && !D || y<height-margin/2 && !A && !B && !D) velocity.y *= -1;
     if(location.x>margin/2 && !A && !B && !C || x<width-margin/2 && !A && !C && !D) velocity.x *= -1;
     */
  }
  void display() {
    stroke(0);
    fill(50);
    ellipse(location.x, location.y, r, r);
  }
  /*void borders(){
   if(location.x<0||location.x>width) x *=-1;
   if(location.y<0||location.y>height) y *=-1;

   }*/
}


import controlP5.*;

class Interface {

  ControlP5 cp5;
  Group g1, g2, g3;
  Accordion accordion;
  DropdownList d2;
  int env_H, bo_H, ou_H;
  int sliderPosX, sliderPosY, sliderGap;
  int sliderSizeX, sliderSizeY;
  int groupWidth;


  //String [] sliderNames;
  //String [] groupNames;
  //String slider, group;
  //Group gCreate;


  Interface(PApplet this_) {
    cp5  = new ControlP5(this_);
    //s1 = new CallbackListener(this);
    sliderPosX = 10;
    sliderPosY = 10;
    sliderGap = 25;
    sliderSizeX = 160;
    sliderSizeY = 10;
    groupWidth = 180;
    env_H = sliderSizeY*2 + sliderGap*1;
    bo_H = sliderSizeY*2 + sliderGap*3;
    ou_H = sliderSizeY*2 + sliderGap*5;

    //sliderNames = new String [] {"TOLERANCE", "BOUNDARY VISIBILITY", "INFLUENCE", "FALLOFF", "QUALITY", "POPULATION", "OBEDIENCE", "INFLUENCE "};
    //groupNames = new String [] {"ENVIRONMENT", "OURO", "BOROS"};
  }

  void build() {
    cp5.addCallback();

    color gFg = color(200, 50, 100, 100);
    color gLabel = color(255);
    color gBg = color(50, 200, 100, 120);
    color sFg = color(10, 150);
    color sAct = color(50);
    color sBg = color(50, 120);
    color rBg = sBg;
    color rAct = sAct;

    String g1_slider1 = "g1_slider1";
    String g1_slider2 = "g1_slider2";
    String g2_slider1 = "g2_slider1";
    String g2_slider2 = "g2_slider2";
    String g2_slider3 = "g2_slider3";
    String g3_slider1 = "g3_slider1";
    String g3_slider2 = "g3_slider2";
    String g3_slider3 = "g3_slider3 "; // added a space to fix the identical name problem!--------



    g1 = cp5.addGroup("g1")
      .setPosition(100, 50)
      .setBarHeight(10)
      .setColorForeground(gFg)
      .setColorLabel(gLabel)
      .setColorBackground(gBg)
      .setColorValue(color(255, 126, 240))
      .setBackgroundHeight(env_H)
      .setBackgroundColor(color(100, 100))
      ;

    g2 = cp5.addGroup("g2")
      .setPosition(100, 150)
      .setBarHeight(10)
      .setColorForeground(gFg)
      .setColorLabel(gLabel)
      .setColorBackground(gBg)
      .setBackgroundHeight(ou_H)
      .setBackgroundColor(color(100, 100))
      ;

    g3 = cp5.addGroup("g3")
      .setPosition(100, 270)
      .setBarHeight(10)
      .setColorForeground(gFg)
      .setColorLabel(gLabel)
      .setColorBackground(gBg)
      .setBackgroundHeight(bo_H)
      .setBackgroundColor(color(100, 100))
      ;

    // environment sliders
    cp5.addSlider(g1_slider1)
      .setPosition(sliderPosX, sliderPosY)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setRange(100, 500)
      .setValue(100)
      .setGroup(g1)
      ;

    cp5.addSlider(g1_slider2)
      .setPosition(sliderPosX, sliderPosY+sliderGap)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g1)
      ;

    // g2 sliders
    cp5.addSlider(g2_slider1)
      .setPosition(sliderPosX, sliderPosY)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g2)
      ;

    cp5.addSlider(g2_slider2)
      .setPosition(sliderPosX, sliderPosY+sliderGap)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g2)
      ;

    cp5.addSlider(g2_slider3)
      .setSliderMode(Slider.FLEXIBLE)
      .setRange(-100, 100)
      .setDefaultValue(0)
      .setHandleSize(20)
      .setPosition(sliderPosX, sliderPosY+sliderGap*2)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g2)
      ;

    // CHECKBOX g2

    cp5.addCheckBox("check1")
      .setPosition(10, 90)
      .setSize(20, 20)
      .setColorActive(rAct)
      .setColorLabel(color(255))
      .setColorBackground(rBg)
      .setItemsPerRow(1)
      .setSpacingColumn(60)
      .addItem("check1", 0)
      .moveTo(g2)
      ;

    cp5.addCheckBox("check2")
      .setPosition(10, 112)
      .setSize(20, 20)
      .setColorActive(rAct)
      .setColorLabel(color(255))
      .setColorBackground(rBg)
      .setItemsPerRow(1)
      .setSpacingColumn(60)
      .addItem("check2", 0)
      .moveTo(g2)
      ;

    //g3 sliders
    cp5.addSlider(g3_slider1)
      .setPosition(sliderPosX, sliderPosY)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g3)
      ;

    cp5.addSlider(g3_slider2)
      .setPosition(sliderPosX, sliderPosY+sliderGap)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g3)
      ;

    cp5.addSlider(g3_slider3)
      .setPosition(sliderPosX, sliderPosY+sliderGap*2)
      .setSize(sliderSizeX, sliderSizeY)
      .setColorForeground(sFg)
      .setColorBackground(sBg)
      .setColorActive(sAct)
      .setGroup(g3)
      ;




    // caption alignment
    cp5.getController(g1_slider1).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g1_slider2).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g2_slider1).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g2_slider2).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g2_slider3).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g3_slider1).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g3_slider2).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
    cp5.getController(g3_slider3).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);


    accordion = cp5.addAccordion("acc")
      .setPosition(0, 0)
      .setWidth(180)
      .addItem(g1)
      .addItem(g2)
      .addItem(g3)
      ;

    accordion.setCollapseMode(Accordion.MULTI);



    // unsuccesful looping efforts ----------------------------------------

    /*
        for(int i = 0; i < groupNames.length; i++){
                group = "g" + i;
                for(int j = 0; j < groupNames.length; j++){
                    String groupTitle = groupNames[j];
                    gCreate = cp5.addGroup(groupTitle)
                                .setPosition(100,50)
                                .setWidth(groupWidth)
                                .setBackgroundHeight(100)
                                .setBackgroundColor(color(100))
                                ;
                }

            }
            for(int i = 0; i < sliderNames.length; i++){
                String sliderTitle = sliderNames[i];
                            cp5.addSlider(sliderTitle)
                            .setPosition(sliderPosX,sliderPosY)
                            .setSize(sliderSizeX,sliderSizeY)
                            .setGroup(group)
                            ;
                            cp5.getController(sliderTitle).getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);

                }
            */
  }
}


// add the above callback to controlP5


// add another callback to slider s1, callback event will only be invoked for this
// particular controller.

Is it possible to write to a PDF while using the P2D renderer?

$
0
0

I have a programming that is using the P2D renderer and I want to save frames to a PDF at a button press. I simply want to implement this code from the PDF examples on the processing website.

import processing.pdf.*;

boolean record;

void setup() {
  size(400, 400);
}

void draw() {
  if (record) {
    // Note that #### will be replaced with the frame number. Fancy!
    beginRecord(PDF, "frame-####.pdf");
  }

  // Draw something good here
  background(255);
  line(mouseX, mouseY, width/2, height/2);

  if (record) {
    endRecord();
    record = false;
  }
}

// Use a keypress so thousands of files aren't created
void mousePressed() {
  record = true;
}

Unfortunately, this implementation did not work for my code. It simply to produced blank PDF files. I tried simply switching the renderer to default, as it is in the example above and it was able to write a file with the image. However, my code uses PShapes and due to a bug in processing, it only looks correct using the P2D renderer, not the default. (this link shows why)

Is there a way around this? I really would like to save frames of my program to manipulate in Illustrator.

Is there a MySQL library for processing 3?

$
0
0

I just updated to P3 and the MySQL library is no longer working. I can not find information regarding a working update or new library. Could you please help by providing this information if available?

Áudio Minim

$
0
0

Porquê o nível do áudio de saída não é sempre o mesmo?

Why the level of the output audio is not always the same?

Can't find how to change highlightcolor parameter with unfolding

$
0
0

Hi, In a sketch I display map using unfolding. I added countries by following example ChloroplethMapApp. What I can't do is to change the color (by default a big red) of the country selected with my mouse. Please can someone explain how to change the hightlightColor parameter ? Thank you very much.

Face Tracking

$
0
0

Hi friends! I'm looking for a way of track a moving face on a camera. I need a basic tracking, just one face at a time.

I tried Ketai library, but it works only in Android.

Searching on the web I found some libraries for Javascript, like this one TRACKINGJS but I need something with more stability and performance.

Ideas and recomendations are welcome, thanks!

BackgroundSubtraction – How to keep the shape with the colors

$
0
0

Hi everybody, I need some help for a project. I'm looking for a solution since a week but nothing work, or I don't come up to do it.

So, I'm trying to remove the background of the video from the webcam and keep the object in movement with its shape and its color. There is the BackgroundSubtraction in the examples, and I could modify it a little to have a black background and the contour of the object that is draw when an object in motion is detected. But I would like we see ourself in this contour. Then, I continue my research and I find in OpenProcessing a women that done something that match the most with what i'm trying to do. And we could press space to freeze the shape that was in motion, and then we only see the shape that move (with transparency) and the one that was freezed.

What i'm trying to do is the same thing but without the image capture. I could modify it to remove the image capture but the result is not really good, cause there's no transparency (only when we move in the interstice of two shape?).

Here the original code:

/**
 * Background Subtraction
 * by Golan Levin.
 *
 * Detect the presence of people and objects in the frame using a simple
 * background-subtraction technique. To initialize the background, press a key.
 */


import processing.video.*;

int numPixels;
int[] backgroundPixels;
Capture video;

void setup() {
  // Change size to 320 x 240 if too slow at 640 x 480
  size(640, 480);

  video = new Capture(this, width, height, 24);
  numPixels = video.width * video.height;
  // Create array to store the background image
  backgroundPixels = new int[numPixels];
  // Make the pixels[] array available for direct manipulation
  loadPixels();
}

void draw() {
  video.start();
  if (video.available()) {
    video.read(); // Read a new video frame
    video.loadPixels(); // Make the pixels of video available
    // Difference between the current frame and the stored background
    int presenceSum = 0;
    for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
      // Fetch the current color in that location, and also the color
      // of the background in that spot
      color currColor = video.pixels[i];
      color bkgdColor = backgroundPixels[i];
      // Extract the red, green, and blue components of the current pixelÕs color
      int currR = (currColor >> 16) & 0xFF;
      int currG = (currColor >> 8) & 0xFF;
      int currB = currColor & 0xFF;
      // Extract the red, green, and blue components of the background pixelÕs color
      int bkgdR = (bkgdColor >> 16) & 0xFF;
      int bkgdG = (bkgdColor >> 8) & 0xFF;
      int bkgdB = bkgdColor & 0xFF;
      // Compute the difference of the red, green, and blue values
      int diffR = abs(currR - bkgdR);
      int diffG = abs(currG - bkgdG);
      int diffB = abs(currB - bkgdB);
      // Add these differences to the running tally
      presenceSum += diffR + diffG + diffB;
      // Render the difference image to the screen
      pixels[i] = color(diffR, diffG, diffB);
      // The following line does the same thing much faster, but is more technical
      //pixels[i] = 0xFF000000 | (diffR << 16) | (diffG << 8) | diffB;
    }
    updatePixels(); // Notify that the pixels[] array has changed
    println(presenceSum); // Print out the total amount of movement
  }
}

// When a key is pressed, capture the background image into the backgroundPixels
// buffer, by copying each of the current frameÕs pixels into it.
void keyPressed() {
  video.loadPixels();
  arraycopy(video.pixels, backgroundPixels);
}

And here the one that I modified:

/**
 * Background Subtraction
 * by Golan Levin.
 *
 * Detect the presence of people and objects in the frame using a simple
 * background-subtraction technique. To initialize the background, press a key.
 */


import processing.video.*;

int numPixels;
int[] backgroundPixels;
Capture video;

void setup() {
  size(720, 480);

  // This the default video input, see the GettingStartedCapture
  // example if it creates an error
  // video = new Capture(this, 160, 120);
  video = new Capture(this, width, height);

  // Start capturing the images from the camera
  video.start();

  numPixels = video.width * video.height;
  // Create array to store the background image
  backgroundPixels = new int[numPixels];
  // Make the pixels[] array available for direct manipulation
  loadPixels();
}

void draw() {
  video.loadPixels();
  arraycopy(video.pixels, backgroundPixels);
  updatePixels(); // Notify that the pixels[] array has changed
  //println(presenceSum); // Print out the total amount of movement
  if (video.available()) {
    video.read(); // Read a new video frame
    video.loadPixels(); // Make the pixels of video available
    // Difference between the current frame and the stored background
    int presenceSum = 0;
    for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
      // Fetch the current color in that location, and also the color
      // of the background in that spot
      color currColor = video.pixels[i];
      color bkgdColor = backgroundPixels[i];
      // Extract the red, green, and blue components of the current pixel's color
      int currR = (currColor >> 16) & 0xFF;
      int currG = (currColor >> 8) & 0xFF;
      int currB = currColor & 0xFF;
      // Extract the red, green, and blue components of the background pixel's color
      int bkgdR = (bkgdColor >> 16) & 0xFF;
      int bkgdG = (bkgdColor >> 8) & 0xFF;
      int bkgdB = bkgdColor & 0xFF;
      // Compute the difference of the red, green, and blue values
      int diffR = abs(currR - bkgdR);
      int diffG = abs(currG - bkgdG);
      int diffB = abs(currB - bkgdB);
      // Add these differences to the running tally
      // presenceSum += diffR + diffG + diffB;
      // Render the difference image to the screen
      // pixels[i] = color(diffR, diffG, diffB);
      // The following line does the same thing much faster, but is more technical
      pixels[i] = 0xFF000000 | (diffR << 16) | (diffG << 8) | diffB;
    }
  }
}

// When a key is pressed, capture the background image into the backgroundPixels
// buffer, by copying each of the current frame's pixels into it.
void keyPressed() {
}

Actually, if I can be more clear, I would like we see the object in motion in the code I modified like we see it when we press space to freeze the image. (with the transparency and the invert filter)

I really hope somebody could help me, it drives me crazy... Thanks a lot

Alexandre

Adding text boxes

$
0
0

How do I add text boxes to my program? I found out about controlP5 from google but does it work with version 3.2.1?


Optimizing Shapes3d code

$
0
0

I have returned to working on my dissertation project and need a little help. I completely rewrote my code from years ago to utilize Shapes3d and to simplify as much as possible, so that I can concentrate on the theory code, not so much the display code. The trouble is that when I switched from using PShapes and buffers for picking to using Shapes3d, I lost a magnitude of speed. On my old version, I could have up to 100x100x100 cubes. Now with the new code, I am luck to have rotation at 50x50x50.

I have three questions: 1) Would I be better using a minecraft type library/code with unlimited size of map, but only displaying what is close by and not the entire map?

2) When I loaded all of the map into a single shape and displayed it, it seem to really speed things up. Is there any way that I can do something similar with Shapes3d boxes/shapes?

3) I keep reading about culling and only displaying what is needed, but I thought all of that happened in the background of Processing, am I not enabling something that I should be? I am really surprised that I keep reaching these data visualization limits.

4) Any and all suggestions on optimization or improvements would be greatly appreciated. I really only want to code the final function (cellLogic). Any of the other code that can be improved and will get me back up to my 100x100x100 display needed, will really help.

5) Would I be better off using a gaming engine instead of P3? All of the gaming engines seem to be overkill for the limited amount of display capabilities I need.

Thank you for any and all help/suggestions that anybody has. The code is below.

Michael

import peasy.*;
import shapes3d.*;

// version 1.0 Base program
// version 2.0 Add Shape?
PeasyCam cam;
int   cells_per_side = 10;                         // number of cells per side - no greater than 100
int   winSize = 2100;                              //size of display window in both directions
int   numcells =0;

Box[][][] box = new Box[cells_per_side][cells_per_side][cells_per_side];
Shape3D picked = null;
boolean clicked = false;

float boundries = winSize *.8;                    // overall brain size in comparison to window
float init_rescale = 0.4, rescale=init_rescale;   // 0.1 .. 1.0  percentage cell takes of allocated space
float gridSize = boundries / cells_per_side;
float cellSize = gridSize * init_rescale;
float offset=(cells_per_side-1)*gridSize/2.0;
color[] faceColor = { 0x88FF0000, 0x8800FF00, 0x880000FF, 0x88FFFF00, 0x8800FFFF, 0x88FF00FF  };
double rotateAngle = .002;

/PShape  model;

//_________________________________________________________________

void setup() {
  size(2100, 2100, P3D);
  cursor(CROSS);
  cam = new PeasyCam(this, 2800);

  //model = createShape(GROUP);
  for (int i = 0; i < cells_per_side; i++) {
    for (int j = 0; j < cells_per_side; j++) {
      for (int k = 0; k < cells_per_side; k++) {
        box[i][j][k] = new Box(this, cellSize, cellSize, cellSize);
        box[i][j][k].moveTo(i*gridSize-offset,j*gridSize-offset,k*gridSize-offset);
        for (int c = 0; c<faceColor.length; c++) {box[i][j][k].fill(faceColor[c],int(pow(2,c)));}
        box[i][j][k].stroke(color(64, 0, 64));
        box[i][j][k].strokeWeight(0.6);
        box[i][j][k].visible(true);
        box[i][j][k].drawMode(S3D.SOLID);
        box[i][j][k].tag = "Box " + i + " " + j + " " + k;
    }}}
    // model.addChild(box[i][j][k]);
  }

//_________________________________________________________________
void draw() {
  background(#E0FFFF);
  cam.beginHUD();    // now draw things that you want relative to the camera's position and orientation
  cam.endHUD();

  pushMatrix();
      for (int i = 0; i < cells_per_side; i++) {
       for (int j = 0; j < cells_per_side; j++) {
        for (int k = 0; k < cells_per_side; k++) {
          box[i][j][k].draw();}}}
   popMatrix();

  // shape(model);    //This will draw the entire model
   cellLogic();
   cam.rotateY(rotateAngle);   //cam.rotateX(rotateAngle);   cam.rotateZ(rotateAngle);
  }

//_________________________________________________________________
void mouseClicked() {
    picked = Shape3D.pickShape(this, mouseX, mouseY);
    if (picked != null)      picked.visible(false);
    if (mouseButton == LEFT) {rotateAngle=0;} else if (mouseButton == RIGHT) {rotateAngle=.002;}
}

//_________________________________________________________________
//------------The actual application logic goes here
//_________________________________________________________________
final float A90=PI/2;
void cellLogic() {
  int a=floor(random(cells_per_side));
  int b=floor(random(cells_per_side));
  int c=floor(random(cells_per_side));

  box[a][b][c].rotateBy(int(random(cells_per_side))*A90,int(random(cells_per_side))*A90,int(random(cells_per_side))*A90);

}

Using ugens to write to WAV in non-realtime

$
0
0

I am trying to adapt a sketch I made using minim in realtime to write a WAV offline (not in real-time). I have come across examples using the javasound api to write a WAV from an array where a sine table is generated byte-by-byte, but I would like to use unit-generator based sound libraries like minim or jsyn to generate the audio data. Since those libraries are mainly used for realtime synthesis to an audio device, I am confused about how this would be accomplished.

One thing that sticks out in my mind is that in minim (I am less familiar with jsyn), I assume that chunks of data are written to the output stream consisting of multiple samples per draw() loop frame. I am just generally unsure of how to capture these frames to a buffer to write a file, or better to a stream that java can use to write the file piece by piece.

Sorry if this is vague, I am a bit lost in general regarding the architecture of these libraries and don;t have an understanding of what the bits and pieces are that would get unit generators working to write data in a non-realtime application.

Thanks for any help in advance, I can provide some of the code that I have worked on if that would clarify things.

ConcurrentModificationException

$
0
0
Hi I only started months ago using Processing. I used the library ControlP5 to create my GUI. I modified the example provided by the library called ControlP5Frames in /controllers. I want to display another window when I pressed a button in the main window. My problem is, error _ConcurrentModificationException_ occurs when I close the second window.


Below is my code:

`import java.awt.*;
import java.awt.event.*;
import controlP5.*;

private ControlP5 cp5;

ControlFrame cfConfig;

String actualColors[] = {"Red","Green","Blue","Yellow"};
  String arrangement[] = {"Corners","All Top","Right Side","Left Side"};
  int selectedColors[] = new int[4];
  int selectedArrangement = 0;
  int removeMe;

void initMainGUI(){

  cp5.addButton("config")
     .setLabel("Configuration")
     .setPosition(100,400)
     .setSize(200,19)
     ;

  cp5.addButton("homePosition")
     .setLabel("Home Position")
     .setPosition(400,400)
     .setSize(200,19)
     ;

  cp5.addButton("systemStart")
     .setLabel("Start Sorting")
     .setPosition(700,400)
     .setSize(200,19)
     ;

}

void config(){
 cfConfig = addControlFrame( "Configuration", 720, 600, 20, 50, color( 100 ), 0);
}

void setup(){
  size(1000, 500);
  cp5 = new ControlP5(this);

  initMainGUI();
}

void draw(){

}

ControlFrame addControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ,int type) {
  final Frame f = new Frame( theName );
  final ControlFrame p = new ControlFrame( this, theWidth, theHeight, theColor, type);

  f.add( p );
  p.init();
  f.setTitle(theName);
  f.setSize( p.w, p.h );
  f.setLocation( theX, theY );
  f.addWindowListener( new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
      p.dispose();
      f.dispose();
    }
  }
  );
  f.setResizable( false );
  f.setVisible( true );
  // sleep a little bit to allow p to call setup.
  // otherwise a nullpointerexception might be caused.
  try {
    Thread.sleep( 100 );
  }
  catch(Exception e) {
  }
  return p;
}

class ControlFrame extends PApplet {

  int w, h;
  int bg;
  int windowType;
  PApplet parent;
  ControlP5 cp5;

  public ControlFrame(PApplet _parent, int _w, int _h, int theColor,int type) {
    super();
    parent = _parent;
    w=_w;
    h=_h;
    bg = theColor;
    windowType=type;
  }


  public void setup() {
    size(w, h);
    cp5 = new ControlP5(this);
    if(windowType==0){
      initConfig();
    }
  }

  public void initConfig(){

  cp5.addScrollableList("prioOne")
     .setLabel(" ")
     .setPosition(100, 60)
     .setSize(100, 100)
     .setBarHeight(20)
     .setItemHeight(20)
     .addItems(actualColors)
     .setOpen(false)
     ;

  cp5.addTextlabel("labelOnce")
    .setText("Priority One")
    .setFont(createFont("Calibri",12))
    .setPosition(20,60)
    .setColorValue(#000000)
    ;

   cp5.addTextlabel("labelTwo")
    .setText("Priority Two")
    .setFont(createFont("Calibri",12))
    .setPosition(20,90)
    .setColorValue(#000000)
    ;

   cp5.addTextlabel("labelThree")
    .setText("Priority Three")
    .setFont(createFont("Calibri",12))
    .setPosition(20,120)
    .setColorValue(#000000)
    ;

   cp5.addTextlabel("labelFour")
    .setText("Priority Four")
    .setFont(createFont("Calibri",12))
    .setPosition(20,150)
    .setColorValue(#000000)
    ;

   cp5.addTextlabel("labelFive")
    .setText("Arrangement")
    .setFont(createFont("Calibri",12))
    .setPosition(20,180)
    .setColorValue(#000000)
    ;

  cp5.addTextlabel("labePOH")
  .setText("Priority One H")
  .setFont(createFont("Calibri",12))
  .setPosition(20,250)
  .setColorValue(#000000)
  ;

  cp5.addTextlabel("labePTH")
  .setText("Priority Two H")
  .setFont(createFont("Calibri",12))
  .setPosition(20,310)
  .setColorValue(#000000)
  ;

  cp5.addTextlabel("labePThH")
  .setText("Priority Three H")
  .setFont(createFont("Calibri",12))
  .setPosition(20,370)
  .setColorValue(#000000)
  ;

  cp5.addTextlabel("labePFH")
  .setText("Priority Four H")
  .setFont(createFont("Calibri",12))
  .setPosition(20,430)
  .setColorValue(#000000)
  ;

  cp5.addTextlabel("labeSmtH")
  .setText("Gripper H")
  .setFont(createFont("Calibri",12))
  .setPosition(20,490)
  .setColorValue(#000000)
  ;

  }

  boolean updateGui=false;
  int nextState=0;

  void updatingGui(){
  if(nextState==1){
    cp5.addScrollableList("prioTwo")
   .setLabel(" ")
   .setPosition(100, 90)
   .setSize(100, 100)
   .setBarHeight(20)
   .setItemHeight(20)
   .addItems(actualColors)
   .setOpen(false)
   .bringToFront();
   ;
  }else if(nextState==2){
    cp5.addScrollableList("prioThree")
   .setLabel(" ")
   .setPosition(100, 120)
   .setSize(100, 100)
   .setBarHeight(20)
   .setItemHeight(20)
   .addItems(actualColors)
   .setOpen(false)
   .bringToFront();
   ;
  }else if(nextState==3){
    cp5.addScrollableList("prioFour")
   .setLabel(" ")
   .setPosition(100, 150)
   .setSize(100, 100)
   .setBarHeight(20)
   .setItemHeight(20)
   .addItems(actualColors)
   .setOpen(false)
   .bringToFront();
   ;
  }else if(nextState==4){
    cp5.addScrollableList("prioFive")
   .setLabel(" ")
   .setPosition(100, 180)
   .setSize(100, 100)
   .setBarHeight(20)
   .setItemHeight(20)
   .addItems(arrangement)
   .setOpen(false)
   .bringToFront();
   ;
  }else if(nextState==5){
   cp5.addSlider("oneH")
     .setPosition(20,270)
     .setSize(200,20)
     .setRange(0,255)
     .setValue(128)
     .getCaptionLabel().align(ControlP5.TOP, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
     ;

   cp5.addSlider("twoH")
   .setPosition(20,330)
   .setSize(200,20)
   .setRange(0,255)
   .setValue(128)
   .getCaptionLabel().align(ControlP5.TOP, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
   ;

   cp5.addSlider("threeH")
     .setPosition(20,390)
     .setSize(200,20)
     .setRange(0,255)
     .setValue(128)
     .getCaptionLabel().align(ControlP5.TOP, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
     ;

   cp5.addSlider("fourH")
     .setPosition(20,450)
     .setSize(200,20)
     .setRange(0,255)
     .setValue(128)
     .getCaptionLabel().align(ControlP5.TOP, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
     ;

   cp5.addSlider("fiveH")
     .setPosition(20,510)
     .setSize(200,20)
     .setRange(0,255)
     .setValue(128)
     .getCaptionLabel().align(ControlP5.TOP, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
     ;

    }
  updateGui=false;
  }

  boolean prioOne=true;

  void prioOne(int n){
    println("Priority One: " + actualColors[n]);
    selectedColors[0]=n;
    if(prioOne){
      updateGui=true;
      nextState=1;
      prioOne=false;
    }
  }

  boolean prioTwo=true;

  void prioTwo(int n){
    println("Priority Two: " + actualColors[n]);
    selectedColors[1]=n;
    removeMe=n;
    if(prioTwo){
      updateGui=true;
      nextState=2;
      prioTwo=false;
    }
  }

  boolean prioThree=true;

  void prioThree(int n){
    println("Priority Three: " + actualColors[n]);
    selectedColors[2]=n;
    removeMe=n;
    if(prioThree){
      updateGui=true;
      nextState=3;
      prioThree=false;
    }
  }

  boolean prioFour=true;

  void prioFour(int n){
    println("Priority Four: " + actualColors[n]);
    selectedColors[3]=n;
    removeMe=n;
    if(prioFour){
      updateGui=true;
      nextState=4;
      prioFour=false;
    }
  }

  boolean prioFive=true;

  void prioFive(int n){
    println("Arrangement: "+arrangement[n]);
    selectedArrangement=n;
    removeMe=n;
    if(prioFive){
      updateGui=true;
      nextState=5;
      prioFive=false;
    }

  }

  void oneH(int theColor) {
    println("Priority One H: "+theColor);
  }

  void twoH(int theColor) {
    println("Priority Two H: "+theColor);
  }

  void threeH(int theColor) {
    println("Priority Three H: "+theColor);
  }

  void fourH(int theColor) {
    println("Priority Four H: "+theColor);
  }

  void fiveH(int theColor) {
    println("Gripper H: "+theColor);
  }

  public void draw(){
    background(bg);
    if(updateGui){
     updatingGui();
    }
  }


}


`

RiTa Wordnet in Spanish?

$
0
0

I've been looking for this for ages but no luck. Is possible to use the Rita library in spanish (Wordnet or not)?

Thanks a lot for any help!

No image using video library in netbeans

$
0
0

I am trying to use the processing video library in netbeans. I have added the processing core and video jars as libries in netbeans and can get a sketch running with no errors, but I can only hear the video and don't see anything.

When I print "myMovie.width" I get 0...

Here is my code:

package processingvideotest;

import processing.core.PApplet;
import processing.video.*;


public class ProcessingVideoTest extends PApplet{

    Movie myMovie;


    public void setup() {
    myMovie = new Movie(this,  "C:/Users/ollie/Documents/NetBeansProjects/ProcessingVideoTest/src/data/Evangelion.mp4");
    myMovie.play();
    myMovie.speed(1);
    myMovie.loop();

    }

    public void settings() {
      size(400, 400);

    }

    public void draw() {
    image(myMovie, 0, 0);
    }

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

    public static void main(String[] args) {
        PApplet.main(new String[] { "processingvideotest.ProcessingVideoTest" });
    }

}
Viewing all 2896 articles
Browse latest View live