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

code to randomise whether to mute or unmute song playing.

$
0
0

Hi there,

I've been trying to work out how to do what the title says.

Basically, I have 4 instruments playing at the same time that make a song when played together, each instrument is played through a different song, so I can control each instrument individually. I want it so, when the user clicks there mouse, the instruments randomly mute or stay playing, or if they are already not playing, they either keep not playing, or become unmuted.

Any help would be greatly appreciated.

Thanks.


How to play a video from a URL?

$
0
0

Hello all, it has been some time since I last posted, glad to see that the website is doing well (as usual :D). Anyways, I was wondering if someone could give me some guidance about my aforementioned topic. I was wanting to build a program where you can watch videos online through Processing. Now I don't even know if that is possible or not, but in my previous attempts, I tried directly using the URL, a way that someone who wants to use a URL of a picture. Next I tried being more specific when I put in the name of the video, and instead of putting a name like "movie.mov" I put the URL of the video. Now I have searched online and I have found some people with similar questions, and I know it has been asked. And in those inquiries I understand that the end of the link has to end in ".mov" or ".mp4"? I am not so sure about that. But I also wanted to get it to the point at where I can watch videos from a YouTube (or Dailymotion or any other video network) site.

Thank you all for reading

How to get receiving an RTSP stream to work

$
0
0

Hello,

after several days of trial&error and googling, I still can't figure out how to get RTSP streaming to work in Processing3. I found several ways that seem possible, but I didn't find enough detail on each so that I could get it to work.

1) I found this post [1] that uses GSPipeline, however I don't know what to import as the GSPipeline object can't be found (I am using Processing 3 which seems to be based upon GSVideo)

2) Use VLCs ability to open the stream and then recode it to another format, but I couldn't find out what which format could be then opened by Processing.

3) Using Syphon, however there doesn't seem to be a VLC plugin, so another way to capture the stream would be necessary.

4) Java Clients, I am sure that there are Java libraries handling the RTSP stream, can such be used?

As there are multiple ways, I am confused at the moment and would kindly ask anyone who already has a working example of displaying a RTSP stream in Processing for sharing their experiences on the topic.

Best

[1] https://forum.processing.org/one/topic/capturing-video-stream-into-processing-from-a-security-system-via-ethernet.html

Video Movie Library - RTP / RTSP Stream from VLC to processing

$
0
0

Hello everybody I would like to view my VLC videos into processing I saw that no spout plugin is existing for VLC so I'm trying to use network

I tried to open rtp and rtsp with the Movie class, but, impossible to make it works

I tried to add it in the valid protocols, but still not this is my code

`import processing.video.*;

class Mov2 extends Movie

{

Mov2(PApplet main, String url)

{

super(main, url);

supportedProtocols[1] = "rtsp";

supportedProtocols[2] = "rtp";

}

}

Mov2 movie;

void setup() {

size(640, 360);

background(0);

try

{

movie = new Mov2(this, "rtp://127.0.0.1:1234/");

}

catch (Exception e)

{

}

movie.loop();

}

void movieEvent(Movie m) {

m.read();

}

void draw()

{

image(movie, 0, 0, width, height);

}`

Does anybody knows how can I do ?

Thanks a lot !

IPCapture (No video)

$
0
0

My code seems fine. But when i compile the code, only grey screen shows up. No error message in the console.

import ipcapture.*;

IPCapture cam;

void setup() {
  size(320,240);
  cam = new IPCapture(this, "http://10.1.1.1:5502", "root", "admin");
  cam.start();

}

void draw() {
  if (cam.isAvailable()) {
    cam.read();
    image(cam,0,0);
  }
}

void keyPressed() {
  if (key == ' ') {
    if (cam.isAlive()) cam.stop();
    else cam.start();
  }
}

Toxiclibs - creating particles that connect to eachother using springs within certain distance

$
0
0

Hi there!

I've been working through examples and any tutorials I can find and still can't wrap my head around how I can do what I'd like to do. I'm pretty new to processing.

Aim: I want to make 300 slowly floating particles inside my bounding box/sketch that connect to eachother via a spring when they float within a certain distance of one another. It would achieve a similar affect to this: https://vimeo.com/73233807

I'm not sure how to: 1) add 300 particles to my sketch to start with. I'd like to make a Particle class and then call that class 300 times. Does that make sense? How do I do this? Do I need to use arrays or arraylists?

2) Make a string connect between 2 particles when they come within say - a 20 pixel radius of one another. Like the video I've linked, I'd like that string to become a permanent flexible connection and for particles to have multiple strings between one another.

Sorry if this doesn't make great sense - I appreciate any help I can get. Thank you!

PGraphics::scale() not exporting in P3D

$
0
0

When exporting a PGraphicss P3D object, save() doesn't reflect calls to scale(). Consider the example, taken from https://forum.processing.org/two/discussion/3227/high-resolution-export-p3d: (note that endRecord() and PGpx.scale() had to be changed in order for the original example to work):

boolean record;
int scalePG = 2;

void setup() {
    size(600, 600, P3D);
    smooth();
}

void draw() {
    if(!record)
        background(#ffffff);
    translate(width/2, height/2);
    fill(#ff0000);
    rotateX(60);
    rotateZ(60);
    box(100);
}
void keyPressed() {
    save("lowres.png");

    if(keyCode == ENTER) {
        PGraphics PGpx = createGraphics(width * scalePG, height * scalePG, P3D);
        record = true;
        beginRecord(PGpx);
        PGpx.background(#ffffff, 0); // Clear the offscreen canvas (make it transparent)
        PGpx.scale(scalePG);
        draw();
        endRecord(); // originally was AFTER call to save() in next line - but didn't save anything.
        PGpx.save("highres.png"); // Save image as PNG (JPGs can't have an alpha channel) and save it before endRecord()

        record = false;
    }
}

I posted some pictures about this in this post: https://forum.processing.org/two/discussion/17162/high-resolution-output-for-p3d

Does anyone know how to fix this?

How to get the sketch to play sound from videos on Ubuntu 16.04 LTS, 64 bits

$
0
0

Hello

I am using Processing 3 on a 64-bit Ubuntu distribution. When I load videos, using the Movie class from the Video library, there is no sound. I set 'video.volume(1);', and still there is no sound. On Windows 10, the video loads correctly, with sound, but I would like to use Linux, because I was unable to get Android mode to work on Windows and I got it to work on Linux. Please note that the sketch loads and plays the video on Linux, the only problem is the sound is not loaded.

Thanks.


control of function running with the Checkbox.

$
0
0

Hello friends, I am trying to control the code to display with checkbox, I have two function

void render() and display ()

which i call in event control and with if else statement I want to display this. but it is not show. and when i put it event handler function in run() function its give error that variables are not declared. could you please point our my mistake.

I created checkbox with G4P GUI Builder.

my code is here.

` // Create all the GUI controls. // autogenerated do not edit public void createGUI(){ G4P.messagesEnabled(false); G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME); G4P.setCursor(ARROW); surface.setTitle("Sketch Window"); chkBox = new GCheckbox(this, 4, 8, 123, 31); chkBox.setTextAlign(GAlign.LEFT, GAlign.MIDDLE); chkBox.setText("Display Nuclus ID"); chkBox.setTextBold(); chkBox.setOpaque(false); chkBox.addEventHandler(this, "chkNucleus"); }

// Variable declarations // autogenerated do not edit GCheckbox chkBox; //nucleus is the centre of the niche

class Nucleus {

int id; PVector pos; PVector nucleus = new PVector(); boolean frozen; /............................................................................................./ Nucleus(int identity, boolean hunger, PVector loc) { id = identity;

    pos = loc.get();

} /............................................................................................./

void run() { updatePos(); //render(); // display(); //chkNucleus(GCheckbox source, GEvent event);
}

void updatePos() { // println(id, "current pos", pos); nucleus = new PVector(); for (int i=0; i<space.length; i++) { if (space[i].ref == id) { for (int j=0; j<space[i].nodes.length; j++) { nucleus.add(space[i].nodes[j].pos);

    }
  }
}
nucleus.div(numNodes);

// println("current nucleus", nucleus); // float d = pos.dist(nucleus); // if (d == 0) { // frozen = true; // println("FROZEN .........!!!!!!!!!!!!!!!"); // } pos = nucleus; // println(id, "new pos", pos); }

public void chkNucleus(GCheckbox source, GEvent event) { //CODE:chkBox:929344: //println("chkBox - GCheckbox >> GEvent." + event + " @ " + millis()); //println(event);

if(chkBox.isSelected()){ println("ok"); display(); } else{ println("no"); render();

} }

void render() { stroke(200, 70); // stroke(250, 50); noFill(); ellipse(pos.x, pos.y, 8, 8); stroke(10); point(pos.x, pos.y); }

void display(){ // to display number. stroke(200, 70); // stroke(250, 50); noFill(); ellipse(pos.x, pos.y, 8, 8); stroke(10); point(pos.x, pos.y); fill(200, 155, 0); textAlign(CENTER, CENTER);

text(id, pos.x, pos.y);
}

}

`

Many thanks

Cannot find a class or type named "XXX" (Gif)

$
0
0

Hello,

I'm playing a little bit with a code for a game but I'm having some problems with a class. Its says: Cannot find a class or type named "Class XXX". Do you know what I'm doing wrong?

restrict PImage draw to a single ControlP5 Tab

$
0
0

Think I'm missing something basic here...

I have multiple controlP5 Tabs in a GUI, one tab has numerous Scrollable Lists, these scrollable lists are generated on the fly after the user first sets how many lists they want. When the user then chooses an item from a Scrollable List an Image is drawn depicting their choice.

This all works fine, But the image is drawn across ALL tabs, how can I restrict the images to just the relevant tab ? My function that draws & updates(triggered by the scrollable list being active) these images is in the main draw loop..... and maybe this is the problem ?

Cheers, mala

Disposing of a previous call to beginRaw()

$
0
0

I want to save the current frame as PDF, but only if a button has been pressed in that frame as well. The examples (e.g. the "PDF Files from 3D Geometry (With Screen Display)" from https://processing.org/reference/libraries/pdf/ appear to do something similar, but are essentially different: they use a variable to then save the NEXT frame.

I'd like to do something like the sample from https://processing.org/reference/beginRaw_.html (below) - to call beginRaw() every frame, and call endRaw() only if a key was pressed - but if no key was pressed at the end of draw(), i'd like to dispose of the recording of the current frame. Since there is not call to something like "disposeRaw()", beginRaw() creates a new PDF file each frame.

import processing.pdf.*;

Boolean saveFrame = false;
void setup() {
  size(400, 400, P2D);
}

void draw() {
  beginRaw(PDF, "raw"+frameCount+".pdf");
  line(pmouseX, pmouseY, mouseX, mouseY);
  if (saveFrame == true) endRaw();
  else // disposeRaw();
}

void keyPressed() {
  if (key == ' ') {
    saveFrame = true;
  }
}

How would I dispose of PDF file creation for frames which already called beginRaw()?

textbox (G4P GUI BUILDER)

$
0
0

hello guys.

I am trying to save the value of textbox in a variable, I created textbox with the help of "G4P GUI BUILDER", so how can I store the typed value in variable.

/** =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.

 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
     // It is safe to enter your event code here
 } //_CODE_:button1:12356:

 * Do not rename this tab!
 * =========================================================
 */

public void textfield1_change1(GTextField source, GEvent event) { //_CODE_:txtName:280460:
  println("txtName - GTextField >> GEvent." + event + " @ " + millis());
} //_CODE_:txtName:280460:

// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  txtName = new GTextField(this, 148, 145, 160, 30, G4P.SCROLLBARS_NONE);
  txtName.setOpaque(true);
  txtName.addEventHandler(this, "textfield1_change1");
}

// Variable declarations
// autogenerated do not edit
GTextField txtName;

thanks

Add SQLite

$
0
0

Hi,
Does anyone know how to add sqlite database to a processing project?
Thanks in advance.

How to make igeo and toxiclibs work with Processing 3.1.

$
0
0

Hi, the title says it all.

For igeo I get the error ' bad operand etc...: import processing.opengl.* import igeo.*; size (480, 360, IG.GL);

IVec vec = new IVec(20,10,0);

double xvalue = vec.x();

IG.p("x value is "+xvalue);

double yvalue = vec.y();

IG.p("y value is "+yvalue);

double zvalue = vec.z();

IG.p("z value is "+zvalue);

Similar issue for toxiclibs. I assume the issue for Toxiclibs is that it has not been updated in five years; nevertheless, Daniel Shiffman seems to be using them in his tutorials.

I have installed them correctly in the libraries folder as my other libraries work fine (which are up to date).

Thanks.


setCaptionLabel on top of setImage in controlP5

$
0
0

Hi all,

I am using controlp5 for buttons in an interface. In previous versions, I've been loading in my own images for the buttons, including a title - text added in photoshop. Since I have a lot of buttons that are similar in shape and colour, I am now trying to load in a few general button-images, and repeat the use of this image, while adding a seperate label on top of it. However, I can't get the label to be displayed.

The buttons on the right is what how the title should be placed (but this is done in photoshop), and for the dark blue buttons on the left I've been trying to reach the same with a title/label set in processing.

Screenshot 2014-03-07 11.20.15

The construction of my code may be a bit weird, because I lock the buttons at certain points, and then change the image according to whether they're looked or not. In this piece, meshToggle is the name of the upperleft button, short_inactive, short_tr_active, short_tr_hover, and short_tr_static are the PImages representing the button in different states, and font1 is a Pfont that I use as well in a different part of the code, where it is working.

This happens in void setup():

    createControls();
    autoDraw(false);

This happens in void draw():

    if(meshToggle.isLock())  {
        meshToggle.setImage(short_inactive);
        meshToggle.getCaptionLabel().align(ControlP5.LEFT, ControlP5.CENTER).setPaddingX(20).setFont(font1);
    } else {
        meshToggle.setImages(short_tr_active,short_tr_hover,short_tr_static);
        meshToggle.getCaptionLabel().align(ControlP5.LEFT, ControlP5.CENTER).setPaddingX(20).setFont(font1).setColor(255);
    }

    gui();

This happens in void gui():

void gui() {
    hint(DISABLE_DEPTH_TEST);
    cam.beginHUD();
    cp5.draw();
    cam.endHUD();
    hint(ENABLE_DEPTH_TEST);
}

This happens in void createControls():

void createControls() {
    cp5 = new ControlP5(this);

    meshToggle =  cp5.addButton("mesh_toggle")
      .setPosition(20, 20)
      .setSize(150,30)
      .setCaptionLabel("mesh setup")
      .setLock(false)
      .setSwitch(true);

     }

Hope that is enough information, and that someone can help me!

Save/Load JSON based Cameras in Proscene

$
0
0

https://www.dropbox.com/sh/2riljmpqfywibaa/AADseXkl0ms0WOYcjPSjKow7a?dl=0

^ that's a link to my code

Someone else was apparently able to save/load cameras in proscene from a file: https://forum.processing.org/one/topic/proscene-saving-loading-camera-settings-to-from-file-what-are-the-key-settings-of-a-camera.html

But I'm having trouble implementing their code. I have a feeling it's a basic problem that I just don't understand. When I run this:

import processing.data.JSONObject;

//this is how you save the camera, theoretically;
//save a Proscene scene current camera settings in as a JSON string in a file
void saveCamera(Scene scene, String fileName ) {
  processing.data.JSONObject json = new JSONObject();
  json.setFloat("fov", scene.camera().fieldOfView() );
  setVector(json, "position", scene.camera().position() );
  setVector(json, "viewdirection", scene.camera().viewDirection() );
  setVector(json, "upvector", scene.camera().upVector() );
  saveJSONObject(json, fileName);
}
//Add a PVector as a string representation of a float array to a JSON object
void setVector(JSONObject json, String attributeName, Vec v) {
  json.setString( attributeName, Arrays.toString( new float[]{ v.x, v.y, v.z} ) );
}

//#####this is how you load the camera, theoretically;
void loadCamera(Scene scene, String fileName) {
  JSONObject json = loadJSONObject(fileName);
  scene.camera().setFieldOfView( json.getFloat("fov") );
  scene.camera().setUpVector( getVector(json, "upvector") );
  scene.camera().setViewDirection( getVector(json, "viewdirection") );
  scene.camera().setPosition( getVector(json, "position") );
}
//Parse a PVector from its string representation as an array of float in a JSON object
PVector getVector(JSONObject json, String attributeName) {
  String o =  json.getString(attributeName);
  String[] arr = o.substring(1, o.length()-1).split(", ");
  float[] f = new float[arr.length];
  int i = 0;
  for (String s : arr) {
    f[i] = Float.parseFloat(s);
    i++;
  }
  return new PVector(f[0], f[1], f[2]);
}

"Arrays" isn't pointing to anything, and I'm not sure what to do about it?

controlP5 shading

$
0
0

Hi, I'm new to controlP5 and am trying to figure out why my slider is only adjusting greyscale and not the color I have inputted. I assume I will have to use the color sliders for this implementation? Thanks

import controlP5.*;

ControlP5 cp5;

int sliderValue2 = 100;
color sliderValue = color(255, 0, 255);
Slider abc;

void setup() {
  size(700, 400);
  noStroke();
  cp5 = new ControlP5(this);

  cp5.addSlider("sliderValue2")
    .setPosition(width/2 - 100, 50)
    .setSize(200, 20)
    .setRange(0, 255)
    .setNumberOfTickMarks(5)
    .setSliderMode(Slider.FLEXIBLE)
    ;

  cp5.addSlider("sliderValue")
    .setPosition(width/2 - 100, 150)
    .setSize(200, 20)
    .setRange(0, 255)
    .setNumberOfTickMarks(5)
    .setSliderMode(Slider.FLEXIBLE)
    ;
}

void draw() {
  background(sliderValue);

  fill(sliderValue2);
  rect(0, 0, width, 100);

}

Peasy Cam rotation

$
0
0

Hi, I'm trying to create a button that rotates my object perfectly 90 degrees to the left from it's initiate state.

I made a button that when it is triggered, it will execute the following code.

cam.reset(); // Resets the camera so that the object is in its initial state.
cam.rotateY(-PI/2); // cam.rotateX(-PI/2);

However, every time I press the button, cam.reset() will be executed but not rotateX(). And when I execute rotateX() by itself, it works. Hence, I think that it is the cam.reset() that nullifies the rotateX() that comes after it.

Does anyone know a way to prevent this from happening? Or does anyone know how to reset the 3d object to its initial position without using cam.reset()?

Thank you so much, Jerry

Question about the TTSLib

$
0
0

Hello,

Is there a way to use the TTSLib (Text to speech) library in Dutch? I couldn't find anything about it, but if I use Dutch words with standard (English) TTS file, I get very strange words :D

Regards, Daantje

Viewing all 2896 articles
Browse latest View live