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

Putting Drawing into the scene with proscene

$
0
0

Hello guys,

Could anyone help how to put a "drawing" or image, using the Proscene library? I would like to put on the scene "Human Body" representing the body, and rotate the same, seeing different angles. Below is the example code.

//https://www.openprocessing.org/sketch/100377

import remixlab.proscene.*;

Particle[] particle;
Scene scene;

int nbPart, neckThick, headShape, shoulderSize, armSize, hipSize,lowerSize, upperSize, thighSize, handSize, legSize, footSize;
PFont font;

void setup() {
  size(displayWidth, displayHeight, P3D);
  background(0);
  noFill();

  scene = new Scene(this);
  scene.addAnimationHandler(this, "animateScene");
  scene.setAxesVisualHint(false);
  scene.setAnimationPeriod(40); // 25Hz
  scene.startAnimation();

  nbPart = 2000;
  particle = new Particle[nbPart];
  for (int i = 0; i < particle.length; i++)
    particle[i] = new Particle();

  font = loadFont("CourierNewPSMT-48.vlw");
  atualizaPontos();
  corpo();
}

void draw() {
  background(0);

  pushStyle();
  strokeWeight(0.7);
  beginShape(POINTS);

  for (int i = 0; i < nbPart; i++) {
    particle[i].draw();
  }

  corpo();

  endShape();
  popStyle();
}

void keyPressed() {
  if ((key == 'x') || (key == 'X'))
    scene.setAnimationPeriod(scene.animationPeriod()-2);
  if ((key == 'y') || (key == 'Y'))
    scene.setAnimationPeriod(scene.animationPeriod()+2);
}

void animateScene(Scene s) {
  for (int i = 0; i < nbPart; i++)
    if (particle[i] != null)
      particle[i].animate();
}

void atualizaPontos(){
  neckThick    = 3;
  headShape    = 0;
  shoulderSize = 5;
  armSize      = -1;
  hipSize      = -3;
  lowerSize    = -5;
  upperSize    = 2;
  thighSize    = -5;
  handSize     = 15;
  legSize      = 0;
  footSize     = 14;
}

void corpo() {
  head(headShape);
  neck(neckThick);
  shoulders(shoulderSize);
  upperArms(armSize);
  hips(hipSize);
  lowerBody(lowerSize);
  upperBody(upperSize);
  thighs(thighSize);
  kneecaps();
  hands(handSize);
  legs(legSize);
  feet(footSize);
}

void mostrarDados(){
  println("neckThick: " + neckThick);
  println("headShape: " + headShape);
  println("shoulderSize: " + shoulderSize);
  println("armSize: " + armSize);
  println("hipSize: " + hipSize);
  println("lowerSize: " + lowerSize);
  println("upperSize: " + upperSize);
  println("thighSize: " + thighSize);
  println("handSize: " + handSize);
  println("legSize: " + legSize);
  println("footSize: " + footSize);
}

void head(int headSize) {
  fill(255);
  bezier(300, 70, 10, 308, 30, 10, 372, 30, 10, 385, 70, 10); //scalp
  bezier(300, 70, 10, 300-headSize, 120, 10, 315-headSize, 135, 10, 320, 140, 10); //side
  bezier(385, 70, 10, 385+headSize, 120, 10, 370+headSize, 135, 10, 365, 140, 10); //side
  bezier(320, 140, 10, 340, 155, 10, 345, 155, 10, 365, 140, 10); //chin
}

void neck(int neckWidth) {
  fill(255);
  bezier(320, 140, 10, 325-neckWidth, 170, 10, 320-neckWidth, 180, 10, 315, 180, 10); //left neck
  bezier(365, 140, 10, 355+neckWidth, 170, 10, 365+neckWidth, 180, 10, 365, 180, 10); //right neck
}

void shoulders(int shoulderWidth) {
  fill(255);
  bezier(210, 200, 10, 305, 190-shoulderWidth, 10, 310, 185-shoulderWidth, 10, 315, 180, 10); //left trapezius
  bezier(365, 180, 10, 370, 190-shoulderWidth, 10, 380, 195-shoulderWidth, 10, 480, 200, 10); //right trapezius
  bezier(210, 200, 10, 205, 205, 10, 205, 205, 10, 200, 220, 10); // left shoulder
  bezier(480, 200, 10, 485, 205, 10, 485, 205, 10, 490, 220, 10); // right shoulder
}

void upperBody(int upperWidth) {
  fill(255);
  bezier(240, 250, 10, 245-upperWidth, 300+upperWidth, 10, 250-upperWidth, 325+upperWidth, 10, 275, 325, 10); //left pectoral
  bezier(450, 250, 10, 450+upperWidth, 300+upperWidth, 10, 430+upperWidth, 325+upperWidth, 10, 415, 325, 10); //right pectoral
  bezier(330, 300, 10, 325, 320, 10, 320, 320, 10, 300, 325, 10); //inner boob
  bezier(360, 300, 10, 370, 320, 10, 375, 320, 10, 390, 325, 10); //inner boob
}

void lowerBody(int lowerWidth) {
  fill(255);
  bezier (260, 320, 10, 260-lowerWidth, 350+lowerWidth/2, 10,  270-lowerWidth, 380+lowerWidth/2, 10, 265, 415, 10); // left side
  bezier (430, 320, 10, 430+lowerWidth, 350+lowerWidth/2, 10, 420+lowerWidth, 380+lowerWidth/2, 10, 425, 415, 10); // right side
  //bezier (270, 380, 260-lowerWidth, 400+lowerWidth/2, 260-lowerWidth, 410+lowerWidth/2, 270, 415); // left flab
  //bezier (420, 380, 430+lowerWidth, 400+lowerWidth/2, 430+lowerWidth, 410+lowerWidth/2, 420, 415); // right flab
}

void hips(int hipWidth) {
  fill(255);
  bezier(265, 410, 10, 265-hipWidth, 430, 10, 255-hipWidth, 435, 10, 260, 450, 10); //left hip
  bezier(425, 410, 10, 425+hipWidth, 430, 10, 435+hipWidth, 435, 10, 430, 450, 10); //left hip
}

void thighs(int thighWidth) {
  fill(255);
  bezier(260, 450, 10, 240-thighWidth, 500, 10, 250-thighWidth, 525, 10, 270, 650, 10); //left thigh side
  bezier(335, 480, 10, 340+thighWidth, 500, 10, 330+thighWidth, 525, 10, 320, 650, 10); //right thigh side
  bezier(430, 450, 10, 445+thighWidth, 500, 10, 440+thighWidth, 525, 10, 420, 650, 10); //left thigh side
  bezier(360, 480, 10, 355-thighWidth, 500, 10, 355-thighWidth, 525, 10, 370, 650, 10); //right thigh side
  bezier(335, 480, 10, 340, 483, 10, 340, 483, 10, 360, 480, 10);
}

void kneecaps() {
  fill(255);
  bezier(270, 650, 10, 270, 655, 10, 265, 655, 10, 270, 690, 10); // left kneecap side
  bezier(320, 650, 10, 320, 655, 10, 325, 655, 10, 320, 690, 10); // right kneecap side
  bezier(420, 650, 10, 420, 655, 10, 425, 655, 10, 420, 690, 10); // left kneecap side
  bezier(370, 650, 10, 370, 655, 10, 365, 655, 10, 370, 690, 10); // right kneecap side
}

void upperArms(int armWidth) {
  fill(255);
  bezier(200, 220, 10, 190-armWidth, 300, 10, 200-armWidth, 310, 10, 200, 350, 10); // left forearm side
  bezier(200, 350, 10, 180-armWidth, 425, 10, 200-armWidth, 500, 10, 200, 500, 10); // left arm side
  bezier(240, 250, 10, 240+armWidth, 300, 10, 235+armWidth, 310, 10, 235, 350, 10); // left forearm inside
  bezier(235, 350, 10, 240+armWidth, 425, 10, 230+armWidth, 450, 10, 225, 500, 10); // left arm inside
  bezier(490, 220, 10, 500+armWidth, 300, 10, 490+armWidth, 310, 10, 490, 350, 10); // right forearm
  bezier(490, 350, 10, 510+armWidth, 425, 10, 490+armWidth, 500, 10, 490, 500, 10); // right arm
  bezier(450, 250, 10, 450-armWidth, 300, 10, 455-armWidth, 310, 10, 455, 350, 10); // right forearm inside
  bezier(455, 350, 10, 460-armWidth, 425, 10, 455-armWidth, 450, 10, 465, 500, 10); // right arm inside
}

void hands(int handWidth) {
  fill(255);
  bezier(200, 500, 10, 210-handWidth, 530, 10, 175-handWidth, 560, 10, 220, 575, 10); // left hand
  bezier(220, 575, 10, 225+handWidth, 575, 10, 220+handWidth, 560, 10, 225, 500, 10); // left hand
  bezier(490, 500, 10, 480+handWidth, 530, 10, 500+handWidth, 560, 10, 490, 575, 10); // right hand
  bezier(465, 500, 10, 460-handWidth, 575, 10, 455-handWidth, 560, 10, 490, 575, 10); // right hand
}

void legs(int legWidth) {
  fill(255);
  bezier(270, 690, 10, 255-legWidth, 775, 10, 265-legWidth, 800, 10, 275, 850, 10); //left calf
  bezier(320, 690, 10, 320+legWidth, 775, 10, 300+legWidth, 800, 10, 300, 850, 10); //left calf
  bezier(420, 690, 10, 435+legWidth, 775, 10, 415+legWidth, 800, 10, 405, 850, 10); //right calf
  bezier(370, 690, 10, 370-legWidth, 775, 10, 380-legWidth, 800, 10, 380, 850, 10); //left calf
}

void feet(int footWidth) {
  fill(255);
  bezier(275, 850, 10, 250-footWidth, 900+footWidth, 10, 280-footWidth, 900+footWidth, 10, 300, 850, 10); // left foot
  bezier(405, 850, 10, 430+footWidth, 900+footWidth, 10, 400+footWidth, 900+footWidth, 10, 380, 850, 10); // left foot
}

class Particle {
  PVector speed;
  PVector pos;
  int age;
  int ageMax;

  public Particle() {
    speed = new PVector();
    pos = new PVector();
    init();
  }

  public void animate() {
    speed.z -= 0.05f;
    pos = PVector.add(pos, PVector.mult(speed, 10f));

    if (pos.z < 0.0) {
      speed.z = -0.8f * speed.z;
      pos.z = 0.0f;
    }

    if (++age == ageMax)
      init();
  }

  public void draw() {
    stroke( 255 * ((float) age / (float) ageMax), 255 * ((float) age / (float) ageMax), 255);
    vertex(pos.x, pos.y, pos.z);
  }

  public void init() {
    pos = new PVector(0.0f, 0.0f, 0.0f);
    float angle = 2.0f * PI * random(1);
    float norm = 0.04f * random(1);
    speed = new PVector(norm * cos(angle), norm * sin(angle), random(1));
    age = 0;
    ageMax = 50 + (int) random(100);
  }
}

Thank you for attention


When triggering a sound file there is a delay or latency, can this be reduced?

$
0
0

Heres a simple example that demonstrates the 70mS delay between triggering a sound file and it actually creating the sound.

This was tested with processing 3 on a windows platform. A microphone signal showing the sound is compared with the serial data signal indicating the command to play.

Am I doing something wrong? Can the delay be reduced?

Thanks for any help.

cheers, Andy

// A quick demo to show the delay between .play() and the sound being generated
//
// every second, a serial character is sent - to trigger the oscilloscope on channel 1.
// then a sound file is played (edited .wav so there is no quiet start in the file)
// a microphone detects the sound which is displayed on the oscilloscope channel 2.
// the delay averages 70ms (varying between 65mS to 85mS)
//
// What is causing the delay and can it be reduced?



import processing.serial.*;
import processing.sound.*;
Serial myPort1;  // The serial port
SoundFile Sound1;
int now, last;


void setup()
{
  // List all the available serial ports
  printArray(Serial.list());
  // specify a specific port (to keep it simple)

  try {
        myPort1 = new Serial(this, Serial.list()[2], 57600);
        myPort1.clear();
      } catch (RuntimeException e)
      {
      }

  if (null != myPort1) print("Attached port1 to [2], ", Serial.list()[2], "\n");
  else print("port1 not connected\n");

  // open the .wav sound file which is a drum sound with no quiet time before the sample.
  Sound1 = new SoundFile(this, "click.wav");

  // set up timing to trigger sound every second
  last = millis();
}


void draw()
{
  int now = millis();
  // if 1000mS elapsed since last sound, trigger again
  if ( (now - last) >= 1000 )
  {
    last = now;  // record time of click
    DoClick();
  }
}


// make the sound
void DoClick()
{
  // trigger the sound before sending oscilloscope trigger
   Sound1.play();
  // send serial character as a simple timing trigger.
  // done after sound so we cant blame the serial port for the delay.
  if (null != myPort1)
  {
    myPort1.write(0x22);
  }
}

sound_latency

Problem stablishing communication via OSC between mac and ubuntu

$
0
0

Hi, all,

I’m trying to communicate with oscp5 via ethernet, with a simple example, between mac and ubuntu. As mac is receiving, not the same with ubuntu. I’m pretty new with ubuntu but, first of all i’ve set the ip for the ubuntu:

          sudo ifconfig enp8s0 192.168.1.6 netmask 255.255.255.0

(As enp8s0 is the ethernet id )

My ip on the mac is 192.168.1.3

And here are the codes:

In ubuntu:

  /**
   * oscP5sendreceive by andreas schlegel
   * example shows how to send and receive osc messages.
   * oscP5 website at http://www.sojamo.de/oscP5
   */

  import oscP5.*;
  import netP5.*;

  OscP5 oscP5;
  NetAddress myRemoteLocation;
  String ipMac="192.168.1.3";
  String ipUb="192.168.1.5";
  int macPort = 12000;
  int ubPort=57120;

  void setup() {
    size(400,400);
    frameRate(25);
    oscP5 = new OscP5(this,macPort);
    myRemoteLocation = new NetAddress(ipMac,ubPort);
  }


  void draw() {
    background(0);
  }

  void mousePressed() {
    OscMessage myMessage = new OscMessage("/test");
    myMessage.add(123);
    oscP5.send(myMessage, myRemoteLocation);
  }


  void oscEvent(OscMessage theOscMessage) {
    print("### received an osc message.");
    print(" addrpattern: "+theOscMessage.addrPattern());
    println(" typetag: "+theOscMessage.typetag());
  }

In mac:

  /**
   * oscP5sendreceive by andreas schlegel
   * example shows how to send and receive osc messages.
   * oscP5 website at http://www.sojamo.de/oscP5
   */

  import oscP5.*;
  import netP5.*;

  OscP5 oscP5;
  NetAddress myRemoteLocation;
  String ipMac="192.168.1.3";
  String ipUb="192.168.1.5";
  int macPort = 12000;
  int ubPort=57120;

  void setup() {
    size(400,400);
    frameRate(25);
    oscP5 = new OscP5(this,ubPort);
    myRemoteLocation = new NetAddress(ipUb,macPort);
  }


  void draw() {
    background(0);
  }

  void mousePressed() {
    OscMessage myMessage = new OscMessage("/test");
    myMessage.add(123); /* add an int to the osc message */
    oscP5.send(myMessage, myRemoteLocation);
  }


  void oscEvent(OscMessage theOscMessage) {
    float value = theOscMessage.get(0).floatValue();
    println(" value: "+value);

  }

Any clue or advice will be very very welcome. A lot of thanks!

Question about tweaking G4P 3.5

$
0
0

I wrote a program I use a lot it Processing 2.2.1 and use G4P as part of the GUI. The problem is, I use a pen monitor and the GUI doesn't allow my pen touches ( MouseEvent.PRESSED) to trigger an event. It requires a click (MouseEvent.CLICKED). A few cut and pastes in different java files and I pretty much fixed that:

        case MouseEvent.PRESS:
        if(focusIsWith != this && currSpot >= 0  && z > focusObjectZ()){
                dragging = false;
                status = PRESS_CONTROL;
                takeFocus();
                if(reportAllButtonEvents)
                    fireEvent(this, GEvent.PRESSED);
                bufferInvalid = true;

                if(focusIsWith == this){   //cut and pasted from below
                    status = OFF_CONTROL;
                    bufferInvalid = true;
                    loseFocus(null);
                    dragging = false;
                    fireEvent(this, GEvent.CLICKED);
                }
            }
            break;
        case MouseEvent.CLICK:
            // No need to test for isOver() since if the component has focus
            // and the mouse has not moved since MOUSE_PRESSED otherwise we
            // would not get the Java MouseEvent.MOUSE_CLICKED event
            if(focusIsWith == this){
                status = OFF_CONTROL;
                bufferInvalid = true;
                loseFocus(null);
                dragging = false;
                fireEvent(this, GEvent.CLICKED);
            }
            break;

This broke some scroll bars ( can't differentiate between clicks and drags), but my GUI doesn't use scroll bars except in droplists, and I just lengthened them so they didn't need scroll bars. This has much improved my workflow so I don't have to put down the stylus to click a button or a Checkbox in the gui. I would like to make one final tweak. I'd like to make the area to gain focus around the slider control a little larger. It work now, but you have to be right on top of the dot to get focus and slide it. I want to make it so you just have to be reasonably close. Where would I look for that in the source?

opencv problem with bootcamp

$
0
0

I'm trying to do face detection on a video with opencv on bootcamp (windows 10) and processing 2.2.1

import processing.video.*;

Movie video; import gab.opencv.*; import java.awt.Rectangle;

OpenCV opencv; Rectangle[] faces;

void setup() { size(640,360);

video = new Movie(this, "people.mp4"); video.play(); video.loop();
opencv = new OpenCV(this, video.width, video.height); opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); }

void draw() { background(0); fill(255);
image(video,0,0);
opencv.loadImage(video); faces = opencv.detect();
}

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

It crashes at the line: opencv.loadImage(video);

With the message: IndexOutOfBoundsException: Index 3: Size 0

Any ideas? This works fine on mac osx with the same version of processing.

Drawing the human silhouette with bezier

$
0
0

Hello guys,

Sorry but I will try to ask something complicated again ... (laughs) ...

Below are two code snippets in the first example has a "silhouette" human, designed with bezier, the example I took in OpenProcessing.

Then there is another code, which like to do something similar, ie have the outline of the human body, but only in 3D, with proscene library could to facilitate rotacionamento, I got an example here in the forum.

Someone would know where I FIND tips on how to facilitate to mount coordinated the human body? (Build the mesh ...) to make these contours in 3D?

If anyone can help me with any tips, I thank the attention.

Thank you very much

first Program

int neckThick, headShape, shoulderSize, armSize, hipSize, lowerSize, upperSize, thighSize, handSize, legSize, footSize;

void setup() {
  size(displayWidth, displayHeight, P3D);
  smooth();
  strokeWeight(2);
  noFill();
  stroke(10,50,255,80);

  atualizaPontos();
}

void draw() {
  background(255);
  desenhaCorpo();;
}

void atualizaPontos(){
  neckThick    = 3;
  headShape    = 0;
  shoulderSize = 5;
  armSize      = -1;
  hipSize      = -3;
  lowerSize    = -5;
  upperSize    = 2;
  thighSize    = -5;
  handSize     = 15;
  legSize      = 0;
  footSize     = 14;
}

void desenhaCorpo() {
  head(headShape);
  neck(neckThick);
  shoulders(shoulderSize);
  upperArms(armSize);
  hips(hipSize);
  lowerBody(lowerSize);
  upperBody(upperSize);
  thighs(thighSize);
  kneecaps();
  hands(handSize);
  legs(legSize);
  feet(footSize);
}

void head(int headSize) {
  bezier(300, 70, 308, 30, 372, 30, 385, 70); //scalp
  bezier(300, 70, 300-headSize, 120, 315-headSize, 135, 320, 140); //side
  bezier(385, 70, 385+headSize, 120, 370+headSize, 135, 365, 140); //side
  bezier(320, 140, 340, 155, 345, 155, 365, 140); //chin
}
void neck(int neckWidth) {
  bezier(320, 140, 325-neckWidth, 170, 320-neckWidth, 180, 315, 180); //left neck
  bezier(365, 140, 355+neckWidth, 170, 365+neckWidth, 180, 365, 180); //right neck
}
void shoulders(int shoulderWidth) {
  bezier(210, 200, 305, 190-shoulderWidth, 310, 185-shoulderWidth, 315, 180); //left trapezius
  bezier(365, 180, 370, 190-shoulderWidth, 380, 195-shoulderWidth, 480, 200); //right trapezius
  bezier(210, 200, 205, 205, 205, 205, 200, 220); // left shoulder
  bezier(480, 200, 485, 205, 485, 205, 490, 220); // right shoulder
}
void upperBody(int upperWidth) {
  bezier(240, 250, 245-upperWidth, 300+upperWidth, 250-upperWidth, 325+upperWidth, 275, 325); //left pectoral
  bezier(450, 250, 450+upperWidth, 300+upperWidth, 430+upperWidth, 325+upperWidth, 415, 325); //right pectoral
  bezier(330, 300, 325, 320, 320, 320, 300, 325); //inner boob
  bezier(360, 300, 370, 320, 375, 320, 390, 325); //inner boob
}
void lowerBody(int lowerWidth) {
  bezier (260, 320, 260-lowerWidth, 350+lowerWidth/2, 270-lowerWidth, 380+lowerWidth/2, 265, 415); // left side
  bezier (430, 320, 430+lowerWidth, 350+lowerWidth/2, 420+lowerWidth, 380+lowerWidth/2, 425, 415); // right side
}
void hips(int hipWidth) {
  bezier(265, 410, 265-hipWidth, 430, 255-hipWidth, 435, 260, 450); //left hip
  bezier(425, 410, 425+hipWidth, 430, 435+hipWidth, 435, 430, 450); //left hip
}
void thighs(int thighWidth) {
  bezier(260, 450, 240-thighWidth, 500, 250-thighWidth, 525, 270, 650); //left thigh side
  bezier(335, 480, 340+thighWidth, 500, 330+thighWidth, 525, 320, 650); //right thigh side
  bezier(430, 450, 445+thighWidth, 500, 440+thighWidth, 525, 420, 650); //left thigh side
  bezier(360, 480, 355-thighWidth, 500, 355-thighWidth, 525, 370, 650); //right thigh side
  bezier(335, 480, 340, 483, 340, 483, 360, 480);
}
void kneecaps() {
  bezier(270, 650, 270, 655, 265, 655, 270, 690); // left kneecap side
  bezier(320, 650, 320, 655, 325, 655, 320, 690); // right kneecap side
  bezier(420, 650, 420, 655, 425, 655, 420, 690); // left kneecap side
  bezier(370, 650, 370, 655, 365, 655, 370, 690); // right kneecap side
}
void upperArms(int armWidth) {
  bezier(200, 220, 190-armWidth, 300, 200-armWidth, 310, 200, 350); // left forearm side
  bezier(200, 350, 180-armWidth, 425, 200-armWidth, 500, 200, 500); // left arm side
  bezier(240, 250, 240+armWidth, 300, 235+armWidth, 310, 235, 350); // left forearm inside
  bezier(235, 350, 240+armWidth, 425, 230+armWidth, 450, 225, 500); // left arm inside
  bezier(490, 220, 500+armWidth, 300, 490+armWidth, 310, 490, 350); // right forearm
  bezier(490, 350, 510+armWidth, 425, 490+armWidth, 500, 490, 500); // right arm
  bezier(450, 250, 450-armWidth, 300, 455-armWidth, 310, 455, 350); // right forearm inside
  bezier(455, 350, 460-armWidth, 425, 455-armWidth, 450, 465, 500); // right arm inside
}
void hands(int handWidth) {
  bezier(200, 500, 210-handWidth, 530, 175-handWidth, 560, 220, 575); // left hand
  bezier(220, 575, 225+handWidth, 575, 220+handWidth, 560, 225, 500); // left hand
  bezier(490, 500, 480+handWidth, 530, 500+handWidth, 560, 490, 575); // right hand
  bezier(465, 500, 460-handWidth, 575, 455-handWidth, 560, 490, 575); // right hand
}
void legs(int legWidth) {
  bezier(270, 690, 255-legWidth, 775, 265-legWidth, 800, 275, 850); //left calf
  bezier(320, 690, 320+legWidth, 775, 300+legWidth, 800, 300, 850); //left calf
  bezier(420, 690, 435+legWidth, 775, 415+legWidth, 800, 405, 850); //right calf
  bezier(370, 690, 370-legWidth, 775, 380-legWidth, 800, 380, 850); //left calf
}
void feet(int footWidth) {
  bezier(275, 850, 250-footWidth, 900+footWidth, 280-footWidth, 900+footWidth, 300, 850); // left foot
  bezier(405, 850, 430+footWidth, 900+footWidth, 400+footWidth, 900+footWidth, 380, 850); // left foot
}

second program

import remixlab.proscene.*;

Scene scene;
float px[], py[], mesh[][][];

void setup() {
  size(displayWidth, displayHeight, P3D);
  smooth(); //Suavição de Contorno
  lights(); //Inicia Luzes no ambiente

  //Inicia ambiente para Cena
  scene = new Scene(this);
  scene.setAxesVisualHint(false);
  scene.setGridVisualHint(false);
  scene.showAll();

  //Cria Matriz para a malha
  px = new float[40];
  py = new float[40];
  float t = 0;

  for(int i = 0; i < px.length; i++) {
    px[i] = bezierPoint(50, 130, 130, 50, t);
    py[i] = bezierPoint(450, 350, 150, 50, t);
    //px[i] = bezierPoint(300, 308, 370, 300, t);
    //py[i] = bezierPoint(70, 30, 30, 70, t);
    t += (1.0/(float)(px.length-1));
    ellipse(px[i], py[i], 5, 5);
    println(t);
  }

  //Cria Malha
  mesh = createMesh(px,py,20, -60,60);
  //mesh = createMesh(px,py,170, -360,360);

  scene.startAnimation();
}

void draw() {
  background(0);
  ambientLight(128, 128, 128);
  directionalLight(255, 255, 255, 0, 1, -100);

  //head(-3);
  stroke(255);
  //noStroke();
  //fill(255,120,0);
  drawMesh(mesh);
}

void head(int headSize) {
  fill(255);
  bezier(300, 70, 30, 308, 30, 30, 372, 30, 30, 385, 70, 30); //scalp
  bezier(300, 70, 30, 300-headSize, 120, 30, 315-headSize, 135, 30, 320, 140, 30); //side
  bezier(385, 70, 30, 385+headSize, 120, 30, 370+headSize, 135, 30, 365, 140, 30); //side
  bezier(320, 140, 30, 340, 155, 30, 345, 155, 30, 365, 140, 30); //chin
}

//Desenha Malha
void drawMesh(float mesh[][][]) {
  //println(mesh.length+" "+mesh[0].length+" "+mesh[0][0].length);
  for(int i = 0; i < mesh.length-1; i++) {
    beginShape(QUAD_STRIP);
    for(int j = 0; j < mesh[0].length; j++) {
      vertex(mesh[i][j][0], mesh[i][j][1], mesh[i][j][2]);
      vertex(mesh[i+1][j][0], mesh[i+1][j][1], mesh[i+1][j][2]);
    }
    endShape();
  }
}

//Cria malha
float [][][] createMesh(float px[],float py[],int numrot, float startDeg,float endDeg) {
  float deg, x, z;
  double cosval, sinval, tmp1, tmp2;

  float [][][] mesh = new float[numrot][px.length][3];
  endDeg -= startDeg;

  for(int i = 0; i < numrot; i++) {
    deg = radians(startDeg + (endDeg/(float)(numrot-1)) * (float)i);
    for(int j = 0; j < px.length; j++) {
      x = px[j];
      z = 0;
      cosval = Math.cos(deg);
      sinval = Math.sin(deg);
      tmp1   = x * cosval - z * sinval;
      tmp2   = x * sinval + z * cosval;
      mesh[i][j][0] = (float) tmp1;
      mesh[i][j][1] = py[j];
      mesh[i][j][2] = (float) tmp2;
    }
  }
  return mesh;
}

Translate doesn't work with vertex

$
0
0

Hey guys,

I'm completely new to processing, seems a magnificent tool!

But I have a problem which in the end comes to this prototype example:

size (600,600);
translate(width/2, height/2);
background(255);
stroke(0);
noFill();

//does work
beginShape();
vertex(0,0);
vertex(20,0);
vertex(20,20);
vertex(0,20);
vertex(0,0);
endShape();

//doesn't work, no square drawn
beginShape();
vertex(0,0);
translate(50,0);
vertex(0,0);
translate(0,50);
vertex(0,0);
translate(-50,0);
vertex(0,0);
translate(0,-50);
vertex(0,0);
endShape();

It would be nice for my further application if the second square would be drawn correctly as well (I know, this example is stupid, but it's the easiest way to explain my problem I think).

Does translate not work together with vertex or beginshape/endshape?

Thanks a lot for your help!

Martin

Synchronizing sound and graphics: drawing commands need "flushing"?

$
0
0

I draw a background then several circles using ellipse(). I want to create a sound synchronized with the appearance of each circle. In a test of the circle-building loop, each call to ellipse() is immediately followed by calls to wave.patch(out); delay(250); wave.unpatch(out); delay(250);.

What happens is the background is drawn, the sound sequence is executed in a series of beeps while only the background is showing, then the set of circles is drawn.

I suspect the graphics commands are stacked up or queued and, despite code sequencing, are not executed until the sound functions are carried out. I would like to force each circle to be drawn individually and its associated sound heard at that time. Hints?


Video file formats?

$
0
0

Can anyone recommend preferred file formats for the Processing 3 Video library? I am running some tests in H264 and playback is choppy. I know that format makes a huge difference. Does anyone have experience or knowledge in this area? Which formats play smoothly?

I'm just messing with this very simple code from one of the examples right now:

  import processing.video.*;
    Movie myMovie;

    void setup() {
      size(1920, 1080);
      background(0);
      myMovie = new Movie(this, "temporaldraft.mp4");
      myMovie.loop();
    }

    void draw() {
      image(myMovie, 0, 0, 1920, 1080);
    }

    // Called every time a new frame is available to read
    void movieEvent(Movie m) {
      m.read();
    }

Thanks!!

BoofCV detecting x and y coordinates of fiducials

$
0
0

Hi

I am trying to find the x and y coordinates of detected fiducials from Processing BoofCV. Can someone please point me to some examples?

Thanks in advance.

S

Using Mindset Library for accessing Neurosky

$
0
0

Hello, I am trying to run an example sketch to use Neurosky on windows 7 in processing 3.1.1. I am using this library available at www.jorgecardoso.eu/processing/MindSetProcessing. Example sketch name : 'Mindset All Values'.

When I run the sketch : The error comes as "Error opening serial port /dev/cu.MindWaveMobile-DevA: Port busy" and the output window goes to loading state. There is no application running in parallel still it is showing the port busy error..

Once I shut the output window I can see more errors :

blinkEvent() method not defined. rawEvent() method not defined. Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and help ? Troubleshooting.

This is my first post in forum but I am using processing since long time. Thanks in advance for the support.

Where can I get SimpleOpenNi?

$
0
0

Hello, I'm a new user in processing. I recently installed Kinect v1 and I'm trying to do skeleton tracking. It seems like I have to use SimpleOpenNi for the function, but I could not search the library from 'add library' or google code archive... Can someone please help me?

Giving custom PCM data to BeatDetect

$
0
0

How should audio data be formatted when it's passed to BeatDetect.detect()?

Let's say the audio data I have is stereo PCM data... [leftsample1, rightsample2, leftsample2, rightsample2, ...., leftsamplen, rightsamplen]. Should I pass that directly in to BeatDetect.detect()? or should I convert my stereo data in to a mono data and pass that in instead? or should I split out each channel in to its own array and pass each in to its own BeatDetector object?

Clicking an Image to change it to another image

$
0
0

I'm very new to processing and have been trying to figure this out for awhile and I'm sure it is easy but I need help.

All I'm trying to do is turn the jellyfish image to the plastic bag image when it is clicked. I have a couple of jellyfish spread out through the sketch but wanted them to only changed when they are clicked indivdually. Here is the code that I have been working with, I'm very confused on what to put into the void mousePressed()

PImage ocean; PImage jellyfish; PImage bag;

void setup(){ size(1280, 520); //background image PImage ocean; ocean = loadImage("ocean.jpg"); background(ocean);

jellyfish = loadImage("jellyfish.png"); bag = loadImage("plastic_bag.png");

}

void draw(){ image(jellyfish, 500, 120); image(jellyfish, 600, 320); image(jellyfish, 100, 20); image(jellyfish, 1000, 50); }

void mousePressed(){

}

}

using processing.sound: java VM failes to initialize

$
0
0

For a a few weeks now I have this problem: when I start my sketch with processing.sound in it in 50% of all starts I get the following error message in the console:

Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.

The error does not occure if I do not use processing.sound.

I figured out meanwhile that processing.sound does not function with Asio drivers (used by most audio interfaces). So you have to use the onboard audio card which in my case is an Via HD Audio. But I need the Asio drivers for my audio interface for some stuff in MaxMSP and want to send one channel of the audio from Max to Processing. This I achieve by rerouting one channel from the audio interface by cabel to the input of my onboard audio. In the system settings of Windows for the audio input the Via onboard audio must be selected as standard.

This works basically reliable IF it runs and the error message does not occure what is the case in about 50% of the sketch starts. But why these error? And how to solve this? Because I need this functioning in 2 weeks help is very much appreciated.

System: Win 7, 64 bit Audio interface: Behringer FCA1616 with Asio drivers.


TTS with mbrola is not working

$
0
0

Hello, i tried to get mbrola running in processing. I installed everything and as erro i get that:

Make sure you FULLY specify the path to
the MBROLA directory using the mbrola.base
system property.

import guru.ttslib.*;

TTS tts;

void setup() {
      System.setProperty("mbrola.base", "C:/Users/Paul/Downloads/Compressed/mbrola");
      tts = new TTS("mbrola_us1");
}

void draw() {
}

void mousePressed() {
  tts.speak("Hi! I am a speaking Processing sketch");
}

can somebody help me to fix it?

Thanks!

Creating frequencies?

$
0
0

Hey guys, so I was wondering if someone of you knows how to make frequencies with Processing. For example, I want to make a slider, which can change (sound)frequencies from 1000Hz to 2000Hz. I searched a lot, but I couldn't find any help on how to do this. Maybe someone of you knows, help is greatly appreciated :)

Drop library drag-and-drop not working in P2D or P3D mode

$
0
0

sDrop works fine with the default renderer, but if the sketch is running in P2D or P3D mode, drag-n-drop does not work anymore, for example :

size(400, 400, P3D);

Any workaround for this?

Gstreamer video plugin issue

$
0
0

Hello,

Here is my program ;

import processing.video.*;

Movie myMovie;

void setup(){
  size(1280, 720);
  myMovie = new Movie(this, "test.mp4");
  myMovie.play();
}

void draw(){
  myMovie.read();
  image(myMovie, 0, 0);
}

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

I just want to play a video with processing but when I run it, I've go this issue :

"A library relies on native code that's not available.
Or only works properly when the sketch is run as a 32-bit application."

Is anybody has an idea ?

Slider changing Frequencies?

$
0
0

Hey guys, so I have this slider, which should change the frequencies when you move it, but I don't know how to realise this. Does anyone have an idea on how to do this?

// import everything necessary to make sound.
import controlP5.*;
import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
ControlP5 cp5;
ControlP5 cp6;
Minim minim;
AudioOutput out;

Oscil      wave;
// keep track of the current Frequency so we can display it
Frequency  currentFreq;

int Hertz = 100;
int slider2 = 50;

// setup is run once at the beginning
void setup()
{
  // initialize the drawing window
  size(500, 130);

  cp5 = new ControlP5(this);
  cp5.addSlider("Hertz").setPosition(205,105).setRange(100,200);

  cp6 = new ControlP5(this);
  cp6.addSlider("Volume").setPosition(350,105).setRange(0,100);

  // initialize the minim and out objects
  minim = new Minim(this);
  out   = minim.getLineOut();

  currentFreq = Frequency.ofHertz( 100 );
  wave = new Oscil( currentFreq, 0.6f, Waves.TRIANGLE );

  wave.patch( out );
}

// draw is run many times
void draw()
{
  // erase the window to brown
  background( 0, 0, 0 );
  // draw using a beige stroke
  stroke( 255, 255, 255 );

  text( "Frequenz in Hertz: " + currentFreq.asHz(), 15, 113 );

  // draw the waveforms
  for( int i = 0; i < out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x1, 50 + out.left.get(i+1)*50);
  }
}

// change the Hz when pressing keys on the keyboard
void keyPressed()
{
  if ( key == 'a' ) currentFreq = Frequency.ofHertz( 100 );
  if ( key == 's' ) currentFreq = Frequency.ofHertz( 200 );

  // note that there are two other static methods for constructing Frequency objects
  // currentFreq = Frequency.ofHertz( 440 );

  wave.setFrequency( currentFreq );
}
Viewing all 2896 articles
Browse latest View live