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

Mapping a 3D Sphere with GPS data possible?

$
0
0

Hello I'm totally new to this forum but I've been using Processing for 6 months now in terms of my Design study, so I'm not really used to the technical jargon of the programming world.

I have a Vision of a Project for this Semester that I simply started to sketch but I don't know if it's even possible.

As for now all I have is a Globe that I can view from different angles through PeasyCam. For my Project I want specific Emojis tweeted around the Globe shown at the Location they come from on my Globe. (Live Data Visualization)

Is it even possible? Because as for now I haven't found anything similar done in Processing on the net. Is there a Tool/Library or whatever to map the GPS date in my 3D Globe?

I know its not much so far but this is the code for my Globe

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

Planet earth;

PeasyCam cam;
PImage img;
PImage bg;

void setup() {
  size (1000, 600, P3D);
  img = loadImage("World3.jpg");
  //int i = 10;

  cam = new PeasyCam(this, 200);
  earth = new Planet(50);
}

void draw() {
  bg = loadImage("Black.png");
  background(bg);
  lights();
  earth.show();
}

______



class Planet {
  float radius;
  float angle;
  float distance;
  Planet [] planets;
  float orbitSpeed;
  PVector v;



  PShape globe;

  Planet (float r) {
    v = PVector.random3D();
    radius = r;
    noStroke();
    noFill();
    globe = createShape(SPHERE, radius);
    globe.setTexture(img);
  }

  void show () {
    pushMatrix();
    noStroke();
    fill(255);
    //rotate(angle);
    translate(v.x, v.y, v.z);
    shape(globe);
    popMatrix();
  }
}

Thanks in advance!


Audio Visualization - color issue

$
0
0

Hi guys, I'm working on a project that visualizes input audio and I'm having difficulties making the color change according to the input sound frequency. Right now, tI'm just multiplying the band and freq by different numbers to mimic a lame attempt at the effect I'm going for. Ideally, the color would turn yellow when the input sounds are high pitch, and it would turn orange when the input sounds are medium pitch, and then it would turn purple when the input sounds are low pitch.

Here's what I have so far:

import ddf.minim.analysis.*;
import ddf.minim.*;

//global variables
Minim minim;          //minim object
AudioInput input;     //object for realtime audio
FFT fft;

void setup()
{
  size(displayWidth,displayHeight, P3D);         //scene is in 3D space
  minim = new Minim(this);                       //instantiate minim object
  input = minim.getLineIn(Minim.STEREO, 2048, 192000.0);
  fft = new FFT( input.bufferSize(), input.sampleRate());
  angle = new float[fft.specSize()];
  frameRate(240);

}

void draw()
{
  fft.forward(input.mix);       //use sound from microphone
  arcs();                       //visuals
}

float[] angle;
float[] y, x;

int rings = 7;         //variable for number of sets of rings
int ringDensity = 4;   //variable for number of rings within ring sets
int number = 24;       //variable for number of arcs that make up ring

void arcs()
{
  translate(width/2, height/2);     //move to center of window
  noFill();

  for (int h=1; h<(ringDensity*2); h=h+2) {
    for (int i=h; i<(rings); i=i+10) {
        for (int k = 0; k < fft.specSize() ; k++) {

        angle[k] = angle[k] + fft.getFreq(k)/3000;

        rotateX(sin(angle[k]/20));    //control 3D x rotation
        rotateY(cos(angle[k]/10));    //control 3D y rotation
        rotateZ(tan(angle[k]/30));    //control 3D z rotation


        //color stuff
        int count = 0;
        int lowTot = 0;
        int midTot = 0;
        int highTot = 0;
        for (int l = 0; l < input.left.size()/10; l+=5)
        {

          lowTot+=  (abs(fft.getBand(k)));
          midTot+=  (abs(fft.getAvg(k)));
          highTot+= (abs(fft.getFreq(k)));
          count++;
          }

        float diameter = map(40 * i * angle[k], 0, count, 50, 90);    //movement doesn't grow
        arc(0, 0, diameter, diameter, radians(k*(360/number)), radians((k+1)*(360/number)));

        stroke( map( lowTot, 0, count * 10, 0, 255 ),map( midTot, 0, count * 10, 0, 255 ),map( highTot, 0, count * 10, 0, 255 ));
        strokeWeight(map(fft.getBand(h), 0, count , 1, 200));
        }
       }
      }
    }

void stop()
{
  //closes minim classes
  input.close();
  minim.stop();
  super.stop();
}

Flickr Image Loader Error

$
0
0

Hi, I am using the ImageLoader library (which can be accessed at https://github.com/keshrath/ImageLoader) to access images from Flickr into Processing. A few days ago, everything was fine, but suddenly the sample code returns an error almost evertime I attempt to run it. The error reads

"org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service."

and then goes on to say,

"Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:unable to find valid certification path to requested target "

Here is the sample code I am trying to run: so far I've tried replacing my API Key, using a different computer, and using different websites to load images from (google and tumblr), but so far nothing has worked.

import at.mukprojects.imageloader.*;
import at.mukprojects.imageloader.flickr.*;
import at.mukprojects.imageloader.image.*;

String apiKey = "yourApiKey";
String apiSecret = "yourApiSecret";

ImageLoader loader;
ImageList list;
Image img;

void setup() {
  size(800, 450);

  loader = new FlickrLoader(this, apiKey, apiSecret);
  list = loader.start("sunset beach", false, 60 * 1000);
}

void draw() {
  if (img == null) {
    img = list.getRandom();
  } else {
    image(img.getImg(), 0, 0, width, height);
  }
}

void mousePressed() {
  img = list.getRandom();
}

Any help with diagnosing the issue would be really great, thanks!

Video Playback Errors

$
0
0

Hey, I'm having alot of trouble with getting several videos to be displayed in my sketch. They were originally in wmv formats and when the sketch ran, nothing would happen. I've tried converting them to other formats with the same result, except that in mp4, the video doesn't show up but the audio will play. Any ideas?

Urgent (Video Masking)

$
0
0

Hi, I'm new to processing and I'm using the library video for a project. I'm trying to crop out the circle part of the image so that the video can be running through it and someone can put their head in the circle like a photo booth. Any suggestions would be greatly appreciated!!

unnamed

Control pure data's pitch and volume in processing

$
0
0

This is pure data side: ![6RG~PYQ1GHVCC93MOXN">MG~PYQ1GHVCC93MOXN

I need use two sliders in processing to controls the pitch and volume. I use client to connect pure data and processing files. I know how to draw slider, but how can I use slider to change the values in PD?

G4P builder can't edit previously builded GUI

$
0
0

When I run G4P builder tool, it always start a new GUI and deletes all the gui tab contents.

Using G4P in PApplet Mode

$
0
0

So, I'm trying to run Processing outside the IDE. I'm extending the PApplet class and going about my merry way and everything seems to be working fine.

Now, when I'm using g4p as part of the extended PApplet, everything is fine. Screen Shot 2016-12-04 at 17.19.23

But when I move everything into its own Gui class (which has a reference to the original PApplet that gets passed into the constructors of all the different components) and use it that way I keep getting NullPointers in the event handler.

So what fundamentally changes about how things work that this happens? I want to keep my Gui code separate from my main PApplet code.


Creating GUI for music visualizer

$
0
0

Cant seem to find any examples on how to create a GUI for music visualizer. The GUI I want to create is just a simple one that can browse music from my computer and play music through it. And also has standard buttons like play, pause and stop. Can anyone guide me or show me some examples ??

Change color of line based on song frequency.

$
0
0

Hello,

I am trying to write a code that will use a song's frequency to change the color of a line that moves across the campus to create some sort of abstract picture. Currently, I am stumped on how to achieve this effect. If anyone has any advice on how to do this, it would be much appreciated.

This is my code currently (which probably has a great amount of errors in it; I'm still new to processing):

import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; float k; float r; float g; float b;

Minim minim; AudioPlayer player; FFT fft;

void setup() { size( 800, 600 );

minim = new Minim( this );

player = minim.loadFile("Little Secrets.mp3");
player.play();
fft = new FFT( player.bufferSize(), player.sampleRate() );

}

void draw() {

float x = map( player.position(), 0, player.length(), 0, width );

float e = 0;
for ( int i = 0; i < fft.specSize(); i++ ) {
    e += abs( fft.getBand( i ) ) / 1000;

}

{ int k = color(r-e,g/e,b+e); float r = red(pixels[k]); float g = green(pixels[k]); float b = blue(pixels[k]);

}

stroke( color(r-e, g/e, b+e) );
strokeWeight (5);
line( x, 0, x, height );

}

void stop() { player.close(); minim.stop(); super.stop(); }

Video library | Highest resolution cam not working

$
0
0

Hello everyone, so, the thing is that I made an algorithm to choose the best option for each camera available given by the capture.list() function, so like there are up to 10 different options to each camera and I'm picking the one with the best resolution and highest fps and giving the user the ability to change between those top cameras. The problem is that the best option for my built-in laptop's camera is: "name=HP Truevision HD,size=1280x720,fps=30" but nothing shows up, it doesn't seem to be recording nor is the led next to it on. However, it does work if I choose a lower resolution like: "name=HP Truevision HD,size=640x380,fps=30", so the problem is the size, is there a way to make the best one work? how?

Also, there is the option: "CyberLink Camera", but this one won't work with any option, why?

If anybody could help me, I'll be really thankful.

Finding camera up with yaw, pitch and roll?

$
0
0

Hey!

I am trying to do object picking with rays in Processing. Everything works fine, except I cannot find the right 'up' vector of the camera. I am using Peasy library.

I could get the cameraUp vector by:

right = PVector.cross(view,new PVector(0,0,1)); then

cameraUp = PVector.cross(view, right);

However the problem is that when I am orbiting with the camera the up vector (0,0,1) gets rotated. I would like to find the up vector of the rotated coordinate system. Peasy lets you access the pitch, yaw and roll.

I tried doing it with:

    up.x = cos(cam.getRotations()[0])*sin(cam.getRotations()[1]);
    up.y = -cos(cam.getRotations()[1]);
    up.z = sin(cam.getRotations()[0])*sin(cam.getRotations()[1]);

and a few similar versions, but I just can't get it to work. it might be due to peasy defining the axis differently.

Any hint on how I could solve this?

Any answer would be much appreciated:)

Pause draw()

$
0
0

I know that is not a good practice using delay() but i'm trying different ways to pause a sketch and I can't.

I'm trying to run a simple program, with minim, when line in reaches X volume, a trigger is shot, and the program shows and image for two seconds. Then, the program continues listening to. I load the image outside the bounds of the canvas (x and y = 3000) and when the volume reaches 100, x and y is changed to 0 0, so, the image appears in the screen.

For now all works but the delay. How could I make the program pause for two seconds while is showing the image? I can make the delay when I want, but the image appears AFTER it, not before.

Thanks!

This is my code: ``import ddf.minim.*;

Minim minim;
AudioInput in;
PImage img;
PFont font;

float maxValue;
float minValue;
int frameValue;
  int posX =3000;
  int posY = 3000;

void setup()
{
  size(800, 600, P3D);
 img = loadImage("/Users/pablo/Downloads/vamo.jpg");
frameValue=200;
  minim = new Minim(this);
  minim.debugOn();
  // use the getLineIn method of the Minim object to get an AudioInput
  in = minim.getLineIn(Minim.STEREO, 512);
  font = createFont ("Arial", 60);

   posX =3000;
   posY = 3000;
}

void draw()
{

  background(0);
  stroke(255);
  image(img, posX, posY);
  //actual
  text("Actual: "+in.right.level()*100, 10, height/2);

   if(in.right.level()*100>10){   //if the volume reaches 10
     println("im in");
      posX=30;
      posY=30;
      //delay(3000);
      //frameRate(10);
  }else{
      posX=3000;
      posY=3000;
  }

}

Sometimes my character stops collecting the "food"

$
0
0

Hello everyone!

I'm making a snake game where an individual icon collecting "food" but sometimes the icon wont pick up the food and sometimes it will and then will stop at some random point. Is there an obvious part of my code causing this that im missing? Also, I cannot for the life of me figure out how to get the game to have a game over and restart setting when the icon hits the wall. Also, how can I call the "Welcome" screen into the main code to pop up before the game? I'm sorry for all these questions. I've been working on this for 10+ hours and I'm not seeing everything clearly anymore.

_________________________Main Body__________________________

    import ddf.minim.*;
    import ddf.minim.signals.*;
    import ddf.minim.analysis.*;
    import ddf.minim.effects.*;

Minim minim;
AudioPlayer player;

Logo B;
Welcome W;
int grid = 35;
int Time;
PImage BH;
PImage SC;
PImage Rink;


PVector Cup;


void setup() {

  size(800, 422);
  B = new Logo();
  W= new Welcome();
  frameRate(8);
  pickLocation();
  BH = loadImage("BH.png");
  SC = loadImage("SC.png");
  Rink = loadImage("Rink.jpg");

  minim = new Minim( this );

  player = minim.loadFile("CD.mp3");
  player.play();
}

void pickLocation() {
  int across = width/grid;
  int down = height/grid;
  Cup = new PVector(floor(random(across)), floor(random(down)));
  Cup.mult(grid);
}

void draw() {
  background(Rink);


  if (B.capture(Cup)) {
    pickLocation();
  }
  B.death();
  B.update();
  B.show();


  image(SC, Cup.x, Cup.y, grid, grid);
}

void keyPressed() {

  if (keyCode == UP) {
    B.dir(0, -1);
  } else if (keyCode == DOWN) {
    B.dir(0, 1);
  } else if (keyCode == RIGHT) {
    B.dir(1, 0);
  } else if (keyCode == LEFT) {
    B.dir(-1, 0);
  }
}

_________________Logo__________________

class Logo {
  float x = 0;
  float y = 0;
  float xspeed = 1;
  float yspeed = 0;
  int total = 0;
  boolean endgame=false;
  ArrayList<PVector> hawk = new ArrayList<PVector>();

  Logo() {
  }

  boolean capture(PVector pos) {
    float d = dist(x, y, pos.x, pos.y);
    if (d < 1) {
      return true;
    } else {
      return false;
    }
  }

  void dir(float x, float y) {
    xspeed = x;
    yspeed = y;
  }

  void death() {
    for (int i = 0; i < hawk.size(); i++) {
      PVector pos = hawk.get(i);
      float d = dist(x, y, pos.x, pos.y);
      if (d < 1) {
        text("starting over",100,100);
        total = 0;
        hawk.clear();
      }
    }
  }

  void update() {

    x = x + xspeed*grid;
    y = y + yspeed*grid;

    x = constrain(x, 0, width-grid);
    y = constrain(y, 0, height-grid);
  }

  void show() {
    image(BH, x, y, grid, grid);
  }
}

____________________Welcome______________________

class Welcome {
  PFont Silom;
  boolean buttonpressed;
  int buttonA, buttonB, buttonC, buttonD;

  Welcome()
  {
    Silom = loadFont("Silom.vlw");

    buttonpressed = false;
    buttonC = 215;
    buttonD = 100;
    buttonA = (width-510);
    buttonB = (height-410);


    textFont(Silom, 70);
    if (buttonpressed) {
      println("Begin");
    } else {
      fill(255);
      rect(buttonA, buttonB, buttonC, buttonD);
      fill (0);
      text("START", buttonA+5, buttonB+buttonD-25);
    }
    {

      if (buttonpressed) {
        fill(255, 255, 255, 0);
      } else {
        textFont(Silom, 20);
        text("Press the arrow keys to move around", 210, 235);
        textFont(Silom, 60);
        text("Catch the cup!", 180, 200);
      }
    }
  }

  void mousePressed() {
    if (mouseX>buttonA && mouseX<buttonA+buttonC && mouseY>buttonB && mouseY<buttonB+buttonC)
      buttonpressed = true;
  }
}

trying to use minim to trigger animation when input sound level exeeds a certain height

$
0
0

I've just started a short class for processing, have a simple script for an array of ellipses moving around the screen what I want is for the ellipses to flash when sound exceeds a certain height and to go back to white when input comes below this level. so far Ive not been able to stitch together what I've grasped. please help. Its already 7am and after hours of tutorials I'm no further. Should an if statement go in, or should I be using true/false to switch on or off this reaction

all advice welcome


Apply PeasyCam on PGraphics3D

$
0
0

At the moment I am working on a multi-pass rendering in processing. There I have to use a new PGraphics3D canvas and I can not use the default g object. After the rendering and shading, I'm just going to "print" it on to the g object again as texture:

cam.beginHUD();
image(canvas, 0, 0);
cam.endHUD();

Now I have the problem that things like peasycam do not work anymore because they are attached to the original g and do not transform the camera matrix of my canvas.

So I tried to use the camera matrix of the original graphics and copy it to my canvas:

PGraphics3D p = (PGraphics3D)this.g;
canvas.camera = p.camera;

This did not work, maybe because peasycam is doing something special and it does not change the original camera matrix. So my next idea was to use the static apply method from peasy cam. I had to copy the function out of the original code and make it public:

import peasy.org.apache.commons.math.geometry.Rotation;
import peasy.org.apache.commons.math.geometry.Vector3D;

Vector3D positionVec = new Vector3D(cam.getPosition()[0], cam.getPosition()[1], cam.getPosition()[2]);
Vector3D rotationVec = new Vector3D(cam.getRotations()[0], cam.getRotations()[1], cam.getRotations()[2]);
apply(canvas, positionVec, new Rotation(rotationVec, 0), cam.getDistance());

Here the apply method:

void apply(final PGraphics g, final Vector3D center, final Rotation rotation,
  final double distance) {
  final Vector3D pos = rotation.applyTo(Vector3D.plusK).scalarMultiply(distance).add(center);
  final Vector3D rup = rotation.applyTo(Vector3D.plusJ);
  g.camera((float)pos.getX(), (float)pos.getY(), (float)pos.getZ(), //
    (float)center.getX(), (float)center.getY(), (float)center.getZ(), //
    (float)rup.getX(), (float)rup.getY(), (float)rup.getZ());
}

There I always have a zero norm for rotation (Arithmetic Exception). So my final idea was to just copy all the rotations and translation to my camera matrix:

canvas.beginCamera();
canvas.camera();

canvas.rotateX(cam.getRotations()[0]);
canvas.rotateY(cam.getRotations()[1]);
canvas.rotateZ(cam.getRotations()[2]);

canvas.translate(
  cam.getPosition()[0],
  cam.getPosition()[1],
  cam.getPosition()[2]);

canvas.endCamera();

So now I could rotate my cube, but it was not accurate and I think there is something wrong with some axis.

I would like to ask if someone has done this before and if there is a simple method to do this?

How to incorporate a countdown into game? Help!

$
0
0

Hi,

I have this game into which I would like to incorporate a timer. However, I've been having difficulty implementing it with my menu and pause function. The timer should only run once the menu has been cleared (mouse has been pressed) and should not run when there is a pause. Although TfGuy44 gave me an amazing response, as a person very new to programming, I am having difficulty implementing his idea. So I was wondering if anyone would be able to help me out? I can;t post the entire code, because it is very large, but I will just post the setup and draw functions. It is quite self explanatory the way menu and pause works, and the timer should not run when those are activated.

Here is my code:

void setup ()
{
  minim = new Minim(this);
  cue_stick_hit = minim.loadSnippet("stick_cue_hit.wav");
  ball_wall_collision = minim.loadSnippet("ball_wall_collision.wav");
  game_over=minim.loadSnippet("game_over.wav");
  size(900, 600);//size of processing display window
  frameRate(60); //Sets refresh rate of processing window
  cue.rad = 31.0;//diameter
  cue.col = #e2e9f0;//colour of cue ball
  ball = new Ball [number_of_balls];

  ball();
  coordinate1 = new PVector (ball[0].center.x, ball[0].center.y);
}

void draw ()
{

 if(menu_condition)
  {
    table ();
    ball();
    menu();
    cue();
    clock();

    if(mousePressed)
    {
     menu_condition = false;
    }
  }
   else if(pause)
    {
    table();
    cue();
    ball();
    pause();
    clock();

    textSize(40);
    fill(255);
    text("PAUSED",width/2.5,height/2);
    }
  else
  {
  table();
  cue();
  stick();
  position.add(velocity_cue);
  coordinate1.add(ball1_velocity);
 checkBoundaryCollision();
 velocity_cue.mult(friction_factor);
 ball1_velocity.mult(friction_factor);
 velocity_check();
 cue_in_pocket = pocket();
  ball();
 pause();
 clock();
 collisionBetweenBalls();


 if(cue_in_pocket)
 {
  textSize(45);
  fill(255);
  text("GAME OVER",width/2.75,height/2);
  game_over.play();
  game_over.rewind();
  noLoop();
 }
 textSize(14);
 fill(text_color_r,text_color_g,text_color_b);
 text("POWER:"+power_percentage+"%", 100,100);
  }
  println(ball1_velocity.x);
  println(ball1_velocity.y);

}

Here is TfGuy44's response, which I think suits my application very well:

int time_left = 12000;
color bg;
boolean running;
int last_millis;

void setup() {
  size(400, 400);
  bg = rcolor();
  last_millis = millis();
  running = true;
}

void draw() {
  background(bg);
  fill(255);
  text("Click to pause/unpause.", 20, 20);
  if (running) {
    time_left -= ( millis() - last_millis );
  } else {
    text("PAUSED!", 20, 100);
  }
  last_millis = millis();
  text(time_left, 20, 60);
  if(time_left < 0 ){
    bg = rcolor();
    time_left = int(random(60000));
  }
}

void mousePressed(){
  running = !running;
}

color rcolor(){
  return( color( random(128),random(128),random(128)) );
}

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

Blob Detection in a bright area

$
0
0

Hello! I have a blob detection code, but in my work area is a window that lets in a lot of light and at that point the blob detection doesnt work I want to know how to keep detecting in this area. This is a part of my code, Im using 0.4f brightness

import processing.video.*; import blobDetection.*;

import java.awt.Color;

import oscP5.*; import netP5.*;

Capture cam; BlobDetection theBlobDetection; PImage img; boolean newFrame=false; color trackColor; float threshold = 20; float distThreshold = 75; // double lum = Luminance.lum(color); ArrayList puntos;

OscP5 oscP5; NetAddress myRemoteLocation; NetAddress supercollider;

// ================================================== // setup() // ================================================== void setup() { // Size of applet size(640, 480); // Capture cam = new Capture(this, 640, 480, 30); // Comment the following line if you use Processing 1.5 cam.start();

// BlobDetection
// img which will be sent to detection (a smaller copy of the cam frame);
img = new PImage(80,60);
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(true);
theBlobDetection.setThreshold(0.4f);// will detect bright areas whose luminosity > 0.2f;

ellipseMode(CENTER);

puntos = new ArrayList();

oscP5 = new OscP5(this,12001); myRemoteLocation = new NetAddress("127.0.0.1",12000); supercollider = new NetAddress("127.0.0.1",12000); }

How to make the game end?

$
0
0

Once the white ellipse reaches the green ellipse i would like to make a message come across the screen that says "Congratulations you won!", however, I have been looking at other references but I can't seem to find a way to have the game end with the white ellipse colliding with the green ellipse.

Viewing all 2896 articles
Browse latest View live