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

inflating model mesh


ColorWheel and Snapshot in ControlP5

$
0
0

Hi there,

Have been struggling with this bit of code from the examples. I combined two sets of code from the ControlP5 examples but I can't seem to make this work.

I'm trying to learn about the Snapshot function that will help remember values. It works for all the parameters and even saves the JSON file correctly to call back when required.

It's just the ColorWheel that doesn't respond. Could anyone help me understand what I'm doing wrong here? Thanks!

import controlP5.*;
ControlP5 cp5;

float n = 50;
float s = 10;
float k = 100;
int c = color(100);//this variable does not get stored in the JSON file on pressing 'i' key

void setup() {
  size(400, 600);
  smooth();
  cp5 = new ControlP5(this);

  cp5.addNumberbox("n")
    .setPosition(10, 10)
      .setSize(42, 16)
        .setMultiplier(0.1)
          .setRange(10, 60)
            .setValue(20)
              ;

  cp5.addSlider("s")
    .setPosition(10, 100)
      .setSize(100, 20)
        .setScrollSensitivity(0.01)
          .setRange(60, 140)
            .setValue(100)
              ;


  cp5.addKnob("k")
    .setPosition(200, 100)
      .setRadius(50)
        .setScrollSensitivity(0.001)
          .setMin(60)
            .setMax(140)
              .setDisplayStyle(Controller.ARC)
                ;

  cp5.addRange("r")
    .setPosition(10, 200)
      .setSize(100, 20)
        .setRange(0, 200)
          .setRangeValues(50, 100)
            ;

  //snapshot does not seem to act in the same way for ColorWheel. Why is that?
  cp5.addColorWheel("c", 10, 250, 200 ).
    setRGB(color(128, 0, 255))
    ;
}


void draw() {
  background(0);
}


void keyPressed() {
  switch(key) {
    case('1'):
    cp5.getProperties().setSnapshot("hello1");
    break;

    case('a'):
    cp5.getProperties().getSnapshot("hello1");
    break;


    case('z'):
    cp5.getProperties().removeSnapshot("hello1");
    break;


    case('i'):
    cp5.getProperties().saveSnapshot("hello1");
    break;

    case('o'):
    cp5.getProperties().load("hello1.json");
    break;
  }

  println(cp5.getProperties().getSnapshotIndices());
}

Data Viz and MousePressed()

$
0
0

Hey everybody,

I'm working on my first data viz project based on chapter 3 of Ben Fry's Visualizing Data book.

I have a map of the US states with different sized ellipses drawn for data in each state.

I am trying to figure out how when the mouse is pressed I can change the size and colour of the ellipses and also introduce some audio.

For this I have I have my sketch followed by void mousePressed(). This allows me to generate a duplicate image and also change the colour of the ellipses.

My problem at the moment is that I can't get the second image to 'stay' on the screen.I've tried with a global boolean variable but just can't get the code right!

And also although I am able to change the colour of the ellipses I am unable to make them expand over time.

Here is what I have so far, and suggestions appreciated

boolean button = false;
PImage mapImage;
PImage mapImage2;
Table locationTable;
int rowCount;
float index = 0;
Table dataTable;
float dataMin = MAX_FLOAT;
float dataMax = MIN_FLOAT;

void setup() {
  size(1280, 800);
  frameRate(10);
  //noLoop();
  mapImage = loadImage("bigmap.png");
  mapImage2 = loadImage("bigmap2.png");//


  // Make a data table from a file that contains
  // the coordinates of each state.
  locationTable = new Table("locations.tsv");

  // The row count will be used a lot, store it locally.
  rowCount = locationTable.getRowCount();//this reads each locations x,y valuses

  //read the data Table
  dataTable = new Table("random2.tsv");

  //find the minimum and maximum values
  for (int row = 0; row< rowCount; row++) {
    float value =dataTable.getFloat(row, 1);
    if (value>dataMax) {
      dataMax = value;
    }
    if (value< dataMin) {
      dataMin = value;
    }
  }
}

void draw() {
  background(0);
  image(mapImage, 0, 0);


  // Drawing attributes for the ellipses
  smooth();
  fill(255, 0, 0);
  noStroke();

  // Loop through the rows of the locations file and draw the points
  for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);  // column 1
    float x  = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);  // column 2
    drawData (x, y, abbrev);
  }
}

//map the size of the elloipse to the data value
void drawData(float x, float y, String abbrev) {
  //get data value for state
  index = index+1;
  float value = dataTable.getFloat(abbrev, 1);
  //re-map the value to a number between 2 and 40
  float mapped = map(value, dataMin, dataMax, 4, 80);
  //draw and ellipse for this item


  ellipse(x*2, y*2, mapped, mapped);

  String s = " the murder rate of";
  String i = "is";
  //println(abbrev + value);
  println(s, abbrev, i, value);
}

void mousePressed() {

  button =! button;//not working
  image(mapImage2, 0, 0);
  println("image2works");


  // Drawing attributes for the ellipses
  smooth();
  fill( 0, 255, 0);
  noStroke();

  // Loop through the rows of the locations file and draw the points
  for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);  // column 1
    float x  = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);  // column 2
    drawData2 (x, y, abbrev);
  }
}

//map the size of the ellipse to the data value
void drawData2(float x, float y, String abbrev) {
  //get data value for state
  float value2 = dataTable.getFloat(abbrev, 1);
  //re-map the value to a number between 2 and 40
  float mapped2 = map(value2, dataMin, dataMax, 4, 80);
  //draw and ellipse for this item
  mapped2= mapped2+ 1;
  // an attempt to make ellipses expand that doesn't work
  ellipse(x*2, y*2, mapped2, mapped2);
  println("duplicate works");
}

How can I change the sprite in S4P during the game?

$
0
0

I want to change the image loaded in an instance of a sprite in S4P, just as in Pacman when the image of a ghost changes. I cannot find any method in the library to do this. Shall I create an instance for each sprite, hide a sprite and show the other one at the same place when needed? Any thoughts appreciated.

Fill() and Transform

$
0
0

Hi,why the fill and transform and rotate goes to next shape,although i used popMatrix and pushMatrix?

import peasy.*;
import saito.objloader.*;
import spout.*;

//PrintWriter output;
OBJModel model ;
OBJModel Smodel ;
OBJModel tmpmodel ;

Spout spout;


PeasyCam cam;

float z=0;
float easing = 0.005;
float r;
float k;
int VertCount;
PVector[] Verts;
PVector[] locas;
PVector Mouse;
PVector Mouse2;

int VECS = 600;


void setup()
{
  size(800, 800, P3D);
  frameRate(30);
  noStroke();

  model = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  model.enableDebug();
  model.scale(200);
  model.translateToCenter();


  Smodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  Smodel.enableDebug();
  Smodel.scale(200);
  Smodel.translateToCenter();


  tmpmodel = new OBJModel(this, "Model2.obj", "absolute", TRIANGLES);
  tmpmodel.enableDebug();
  tmpmodel.scale(200);
  tmpmodel.translateToCenter();

  //output = createWriter("positions.txt");

  cam = new PeasyCam(this, width/2, height/2, 0, 1600);

  spout = new Spout(this);

  spout.createSender("Self");
}



void draw()
{
  background(0);
  lights();



  int VertCount = model.getVertexCount ();
  Verts = new PVector[VertCount];
  locas = new PVector[VertCount];
  r =100;
  k = k + 0.01;


PVector psVerts[] = new PVector[VECS];
PVector psVerts2[]= new PVector[VECS];


  cam.setMouseControlled(false);


  Mouse = new PVector(mouseX-width/2, mouseY-height/2, z);
  Mouse2 = new PVector(width/2 -height/2, z);





  //println(frameCount);
  pushMatrix();




  translate(width/2, height/2, 0);
  rotateY(k);


  for (int i = 0; i < VertCount; i++) {
    //PVector orgv = model.getVertex(i);

    locas[i]= model.getVertex(i);
    Verts[i]= Smodel.getVertex(i);


    //PVector tmpv = new PVector();


    if (frameCount> 100) {



      float randX = noise(randomGaussian());
      float randY = noise(randomGaussian());
      float randZ = noise(randomGaussian());

      PVector Ran = new PVector(randX, randY, randZ);

      //float norX = abs(cos(k)) * randX;
      //float norY = abs(cos(k)) * randY;
      //float norZ = abs(cos(k)) * randZ;









      if ((Verts[i].y > Mouse.y  - r/2 && Verts[i].y < Mouse.y  + r/2 && Verts[i].x > Mouse.x  - r/2 && Verts[i].x < Mouse.x  + r/2 && Verts[i].z > Mouse.z  - 1920/2 && Verts[i].z <  Mouse.z  + 1920/2)||(Verts[i].y > Mouse2.y  - r/2 && Verts[i].y < Mouse2.y  + r/2 && Verts[i].x > Mouse2.x  - r/2 && Verts[i].x < Mouse2.x  + r/2 && Verts[i].z > Mouse2.z  - 1920/2 && Verts[i].z <  Mouse2.z  + 1920/2)) {
        tmpmodel.setVertex(i, locas[i].x, locas[i].y, locas[i].z);
      } else {



        Verts[i].x+=Ran.x;
        Verts[i].y+=Ran.y;
        Verts[i].z+=Ran.z;

        if (Verts[i].x > width/2 ) {
          Verts[i].x=-width/2;
        } else if (Verts[i].x < -width/2) {
          Verts[i].x=width/2;
        }
        if (Verts[i].y > height/2 ) {
          Verts[i].y=-height/2;
        } else if (Verts[i].y < -height/2) {
          Verts[i].y=height/2;
        }

        if (Verts[i].z < -800/2 ) {
          Verts[i].z=800/2;
        } else if ( Verts[i].z > 800/2) {
          Verts[i].z=-800/2;
        }
        tmpmodel.setVertex(i, Verts[i].x, Verts[i].y, Verts[i].z);
      }
    }
    // output.println("Verts " + Verts[i] + " locas " +locas[i]);
  }

  pushMatrix();
  rotateY(-k); //-----------------HERE
  //translate(0, 0, 0);
  //rotateY(k); //
  fill(26, 59, 45);
  noStroke();
  beginShape();

  for (int i=0; i < VECS; i+=30 ) {

    psVerts[i] = new PVector (Mouse.x, Mouse.y,Mouse.z);
   psVerts2[i] = new PVector(Mouse2.x, Mouse2.y,Mouse2.z);



  vertex(psVerts[i].x, psVerts[i].y, psVerts[i].z);
  vertex(psVerts2[i].x, psVerts2[i].y, psVerts2[i].z);
  vertex(noise(-width/2,+width/2),noise(-height/2,+height/2),noise(-width/2,+width/2));
  }
  endShape();
  popMatrix();


  pushMatrix();
  rotateY(-k); //-----------------HERE

  translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
  rotateY(k); //-------------AND HERE

  fill(255, 0, 0);

  ellipse(0, 0, 10, 10);
  popMatrix();




  pushMatrix();
  rotateY(-k); //-----------------HERE
  fill(255, 0, 0);
  translate(Mouse2.x, Mouse2.y, Mouse2.z+width/2);
  rotateY(k); //-------------AND HERE


  ellipse(0, 0, 10, 10);
  popMatrix();


  noStroke();

  tmpmodel.draw();

  popMatrix();



  pushMatrix();
  translate(width/2, height/2, 0);
  rotateY(k);
  noFill();

  stroke(255);
  strokeWeight(7);
  box(width, height, 800);
  popMatrix();
  //output.flush(); // Writes the remaining data to the file
  //output.close(); // Finishes the file
  //saveFrame();
  println(z);

  spout.sendTexture();
}

void keyPressed() {
  if (keyCode == UP) {
    z++;
  }
  if (keyCode == DOWN) {
    z--;
  }
}

G4P image toggle button being replaced

$
0
0

o/

Severe beginner question here:

I'm using G4P to create a second window. I have 3 GImageToggleButtons in that second window. During the sketch I scan a folder looking for incoming images and have a preview displayed above the toggles. Sometimes the incoming image preview replaces the off state of the toggle button.

I cant reproduce i consistently, sometimes it replaces the 2nd toggle, sometimes the third. Its not always the same image.

Thanks in advance.

Declared in setup()

btnToggle0 = new GImageToggleButton(controlWindow, 20, controlPanelSizeY-120, "GUI/btn.png", 2); btnToggle0.tag = "large screen button"; btnToggle1 = new GImageToggleButton(controlWindow, 100, controlPanelSizeY-120, "GUI/btn.png", 2); btnToggle1.tag = "small screen"; btnToggle2 = new GImageToggleButton(controlWindow, 180, controlPanelSizeY-120, "GUI/btn.png", 2); btnToggle2.tag = "face";

code that calls the preview image in the control window

if (getImage.endsWith("JPG")) { currentPreview = null; currentPreview = loadImage(getImage); currentPreview.resize(previewSizeX, previewSizeY); } } app.image(currentPreview, 20, 20);

Multiple USB Cameras, USB Hubs and USB ports

$
0
0

Hello!

Long story short - I use processing for performance art. I use USB microscopes and use the code to display multiple live feeds on what the scopes show. I am now getting to the point when I have scopes with the same device name and I have more scopes than there are USB ports.

I am having trouble with using a USB Hub (also with an extra power source) to display more live feeds. Does processing have a problem with USB hubs or is it just a tech issue?

Also because some of my microscopes have the identical device name, I cant select the specific device by (this, w, h, "name", fps); as processing will only select one of the cameras to display and now both. I wondered whether I can write some code to select devices by addressing the specific USB ports on my laptop. Or is there some way I can hack the device to change it's name?_(I have got my code to print list all available cameras, but because im using so many and they list all the appropriate resolutions of camera size, ive got over 100 values to count through! (Not ideal))

Apologies, lots of questions but I have a performance soon and need to get my code sorted! Many thanks,

EmRod

Loading a sound file causes my sketch not to run

$
0
0

terminate called after throwing an instance of 'std::runtime_error' what(): RtApiAlsa::probeDeviceOpen: pcm device (hw:0,3) won't open for input. Could not run the sketch (Target VM failed to initialize).

Removing this function allows the code to run.

music = new SoundFile(this,"herbert.wav");

I believe this is a compatibility issue with Linux. I'm using Processing 3.2.1, the latest sound library, and Ubuntu 16.04.

I hope someone knows hows to solve this.

Thank you.


Processing SQL library removed?

$
0
0

I recently started learning sql and I have an SQLite file. I saw the beizerSQL library but I couldn't download it! I'm using processing 3.2.1 please help.

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?

G4P imagebuttons setZ method protected

$
0
0

I'm using G4P ver4.0 library in processing 3.0.
I want to have labels/imagetogglebuttons displayed over top of other imagetogglebuttons.
I have tried creating the buttons in various order, but I cannot seem to control which one appears "on top".
I found the method setZ in the GAbstractControl, but it is a protected function.

How can I set the Z-order/depth of various GUI elements in G4P ?

Thanks,
Dan

@quark

Can I set a video as my background();

$
0
0

Hello,

Here is what I;m trying to do. I would like to set a looping video as my background() image in my processing sketch. Then I want to import an OBJ and be able to rotate it in 3D space with my mouse. What I have so far is the video and the OBJ in the sketch but both acting as one piece. Here is my code so far. Any ideas?

import peasy.*; import processing.video.*;

PShape s;

String PATH = "/Users/brendanwilson/Desktop/Vidoe_Processing/video/data/comp.mov"; Movie mov;

PeasyCam cam;

void setup() { size(800, 800, P3D); smooth(); s = loadShape("rise.obj"); frameRate(30); mov = new Movie(this, PATH); mov.loop();

//CAMERA Click & Drag for rotation - Command & Drag for panning cam = new PeasyCam(this, 0, 0, 0, 50); cam.setMinimumDistance(0); cam.setMaximumDistance(1800);

}

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

}

void draw() {

directionalLight(126, 126, 126, 0, 0, -1); ambientLight(102, 102, 102); background(0); pushMatrix(); shape(s, 10, 10, 80, 80); popMatrix(); image(mov, 0, 0, width, height); }

Can you set up your PeasyCam to ignore specific objects in your draw?

$
0
0

Here is what I am trying to do:

Have a video playing as my background on loop. Check.

Import a custom OBJ object into my 3DP environment. Check.

Set up a camera system (in this case peasy cam) to orbit and move around the OBJ object BUT NOT the video background.

The code I have below I feel like I'm getting close but I'm running into issues trying to get the peasy cam to ignore the video.

Try running this program and see what you end up with. Things get funky when you add the peasy cam.

THANKS

import peasy.*;
import processing.video.*;


PShape s;


String PATH = "/Users/brendanwilson/Desktop/Vidoe_Processing/video/data/comp.mov";
Movie mov;

PeasyCam cam;

void setup() {
  size(800, 800, P3D);
  smooth();
  s = loadShape("rise.obj");
  frameRate(30);
  mov = new Movie(this, PATH);
  mov.loop();

   //CAMERA Click & Drag for rotation - Command & Drag for panning
  cam = new PeasyCam(this, 100);
  cam.setMinimumDistance(0);
  cam.setMaximumDistance(1800);
}

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

void draw() {
  lights();
  pushMatrix();
  translate(-50, -50, -80);
  image(mov, 0, 0, width+100, height+100);
  popMatrix();
  pushMatrix();
  translate(280,380);
  shape(s, 10, 10, 180, -180);
  popMatrix();
}

Java VM crashing on exit when not using FFT object - is it just me?

$
0
0

Hi there,

I figured before I go through the long process of reporting a bug, I'd ask here whether anybody else here is able to reproduce the problem on their machine. When I execute the code below, I get an EXCEPTION_ACCESS_VIOLATION on closing the window.

import processing.sound.*;

FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];

void setup() {
  size(512, 360);
  background(255);

  // Create an Input stream which is routed into the Amplitude analyzer
  fft = new FFT(this, bands);
}

void draw() {
  background(255, 0, 0);
}

Check whether an audio input is done initializing?

$
0
0

Often when I execute the following code, I'll get a crash. "Java Platform SE binary has stopped working" (Windows 7)

But at the point of the crash, a couple of max values were already printed in the console. All of them being 0.0.

import processing.sound.*;

FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];

void setup() {
  size(512, 360);
  background(255);

  // Create an Input stream which is routed into the Amplitude analyzer
  fft = new FFT(this, bands);
  in = new AudioIn(this, 0);

  // start the Audio Input
  in.start();

  // patch the AudioIn
  fft.input(in);
}

void draw() {
  background(255, 0, 0);

  // have to check somehow whether this is ready
  fft.analyze(spectrum);

  float max = 0;
  for(int i = 0; i < bands; i++){
    // The result of the FFT is normalized
    // draw the line for frequency band i scaling it up by 5 to get more amplitude.
    line( i, height, i, height - spectrum[i]*height*50 );
    if(spectrum[i]*50 > max)
      max = spectrum[i];
  }

  print(max + "\n");
}

How to compile a library from source

$
0
0

I recently upgraded to the new version of processing version 3 and the control p5 library no longer works. On the author's site there is a link to the old version but apparently there is a new version that works with processing 3 but is only available through github as a source code. I also tried contacting the author but the email address bounces back. I am not very familiar with java or how to compile it to be usable in processing. I followed several tutorials but the errors that eclipse throws are incomprehensible and not very helpful. Any help would be appreciated.

Post image to Website using PHP

$
0
0

Hi,

I trying to upload a picture from Processing to a website server. I used to use http://libraries.seltar.org/postToWeb/ but this library is not working anymore in Processing 3

My question is: is there library that works well with Processing 3? If not can you recommend me how to do it by myself.

Salutations, Gonzalo

Hype Framework HCanvas Bug

$
0
0

Hello,

I'm currently taking the Joshua Davis tutorials from GumRoad. So much fun recommend them to everyone. I'm currently running into issues with my HCanvas class. I can't seam to run any sketch (neither my code from scratch or examples from hype) with the HCanvas class in it. If I go through and comment out the elements with HCanvas it runs but once I try to add them it just gives me a spinning wheel that never finishes.

Has anyone run into issues like this? Is it possible they have update the Hype Framework and I'm juts using old classes?

Any help would be greatly appreciated.

Thanks

get vertex from an obj file.

$
0
0

hello guys...i've a question. you can access the vertex of an obj file ?

i try with this...but it doesn't work.

import peasy.*; PShape shp; PeasyCam cam; void setup() { size(1000, 1000, P3D); shp=loadShape("face.obj"); println(shp.getVertexCount()); cam = new PeasyCam(this, 100); cam.setMinimumDistance(50); cam.setMaximumDistance(500); } void draw() { lights(); directionalLight(255, 150, 200, -1, 0, 0); background(0); shape(shp); }

the result of println(shp.getVertexCount()) is 0. thank you!! :)

ControlP5 ColorPicker size adjusting

$
0
0

Hi all,

I am implementing a GUI which has an accordion and a colorPicker inside of one of its groups. I am setting the size of colorPicker with setSize(), but the color bars (R,G,B) does not change with this command. How can I change color bars size to fit the color area?

This is the code to implement colorPicker:

cp5.addColorPicker("Color Background") .setPosition(dw, 9 * dh) .setSize(13*dw, 6*dh) .setColorValue(color(255)) .moveTo(g6);

Thank you!

Viewing all 2896 articles
Browse latest View live