Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Serial.list() question

$
0
0
Is it possible to use Serial.list() for something other than printing to screen?
I have two serial devices that need to connect to my processing sketch.  Is there a way to check for the two serial ports within the sketch so that it does not continue until they are both connected?

save a single frame from Webcam

$
0
0
Not sure why I am having a difficult time finding this out. I just need to save a webcam frame to my desktop.

Re : XMLElement Problem in Processing 2.0b7

$
0
0
Perhaps add this line at the start of your sketch:
import processing.data.XMLElement;
You rightfully posted in the Core Library section, and these libraries need an explicit import.

Note that the XMLElement usage as greatly changed since 1.5.1. You need to adapt whatever code parsing XML to the new way.

Re : issue with integer division of zero padded integers

$
0
0
Funny, because you used exactly the digits making it work (in some cases, you will get a compilation error!).
Java inherited from the C language a bizarre syntax: we can specify number in octal notation. It is nearly never used (GoToLoop found out an original usage with color shifting), but it is here.
If you prefix an integer number (with digits between 0 and 7) with a zero, you automatically trigger this octal notation.
So 031 is actually 25.
println(031 == 25); // Shows true
Making the old joke that Halloween is the same than Christmas:
Oct 31 == Dec 25
(octal vs. decimal)

Re : Serial.list() question

$
0
0
"for something other than printing to screen?"
Well, usually, I see it used to get the names of the ports to open...
I don't know Serial enough to answer the other question.

Re : XMLElement Problem in Processing 2.0b7

Re : issue with integer division of zero padded integers

$
0
0
@PhiLho

Thank you for your answer; I should have thought of octal notation but was doing something totally different, whence my surprise.
cheers,

Re : XMLElement Problem in Processing 2.0b7


Re : XMLElement Problem in Processing 2.0b7

$
0
0
Thanks PhiLho for your help but the new Processing 2.0b7 don't have any XMLElement class.

Re : Do you know whether it is possible or not to put minim and video together in one sketch?

$
0
0
Ok, your attempts show improvement. So that's good!

Some suggestions:
  • Set the number of objects in the array.
  • Initialize the array in setup (this was causing your null pointer exception).
  • Everything minim-related can be done ONCE. Each object can use the global result via dampedVolume.
Adapted Code
  1. import ddf.minim.*;
  2. import ddf.minim.analysis.*;
  3.  
  4. int numBalloons = 10;
  5. Balloon[] balloons = new Balloon[numBalloons];
  6.  
  7. Minim minim;
  8. AudioInput voice;
  9. FFT fft;
  10.  
  11. float dampedVolume;
  12. float damping = 0.6;
  13. float filtering = 100;
  14.  
  15. void setup() {
  16.   size(600, 600);
  17.   smooth();
  18.  
  19.   minim = new Minim(this);
  20.   voice = minim.getLineIn(Minim.STEREO, 2048);
  21.   fft = new FFT(voice.bufferSize(), voice.sampleRate());
  22.  
  23.   for (int i=0; i<numBalloons; i++) {
  24.     balloons[i] = new Balloon(random(width), random(height));
  25.   }
  26. }
  27.  
  28. void draw() {
  29.   background(255);
  30.   analyseSound(); // done once, end result = new dampedVolume value
  31.   for (int i=0; i<balloons.length; i++) {
  32.     balloons[i].display();
  33.   }
  34. }
  35.  
  36. void analyseSound() {
  37.   fft.forward(voice.mix);
  38.   float volume = 0;
  39.   for (int i=0; i<filtering; i++) {
  40.     volume += fft.getBand(i);
  41.   }
  42.   volume *= 0.025;
  43.   dampedVolume = dampedVolume + (volume - dampedVolume)*damping;
  44. }
  45.  
  46. void stop() {
  47.   voice.close();
  48.   minim.stop();
  49.   super.stop();
  50. }
  51.  
  52. class Balloon {
  53.   float x, y;
  54.   color c;
  55.   float scaler;
  56.  
  57.   Balloon(float x, float y) {
  58.     this.x = x;
  59.     this.y = y;
  60.     c = color(random(255), random(255), random(255));
  61.     scaler = random(0.5, 2);
  62.   }
  63.  
  64.   void display() {
  65.     fill(c);
  66.     ellipse(x, y, dampedVolume*scaler, dampedVolume*scaler);
  67.   }
  68. }

Re : Processing 2 and OpenGL Frame Buffer Objects (FBO)

$
0
0
Thanks andres for fixing this. I would love to read a tutorial about FBOs in Processing :)

How to reset a PGraphics ?

$
0
0
Hello !

I would like to animate something inside a PGraphics (with a transparent background) but I don't find any way to reset totally a PGraphics instance. I would like to apply a transparentBackground that erase all the content I have inside the PGraphics.

The only way I found is to create a new PGraphics for each frame, but it take immediatly too much memory and crashes.

Do you think it's possible to add the "reset-feature" in the next release ? It could be very helpful.

Thanks ! 

Re : How to reset a PGraphics ?

$
0
0
This can already be done, both in Processing 1.5.1. and 2.0b7 with the line:
  1.   pg.background(0, 0); // where pg is the PGraphics instance

Re : Serial.list() question

$
0
0
That how in using it in my sketch it gets the list of serial ports and displays them but ideally if like to be able to use it to check is com ports are active before I go and try to access a port that Is not online and have it error out my sketch... That would be a great thing to add to processing of it isn't here already

Re : XMLElement Problem in Processing 2.0b7


Re : How to reset a PGraphics ?

$
0
0
Oh my God ! It works !

Thanks a lot !
I 'm so happy !


Youhou !!!

Re : How to reset a PGraphics ?

$
0
0
Actually it works as expected when there is something already drawn inside the PGraphics, but it send me an error message when I apply a 'background(0,0)' directly after creating the PGraphics.

It's not really a big problem , but it's a good thing to know 
(My poor solution is to add a beginDraw-beginShape-endShape-endDraw directly after the creation of the PGraphics instance, just to be certain that there is something to erase ; and it works perfectly)

Re : Do you know whether it is possible or not to put minim and video together in one sketch?

$
0
0
Thank you very much!!

Someday I really want to help you if there is any chance  kk

With your adapted code, I made this

- applying the First code to pixels on the (P)Image-

It is...



  1. import ddf.minim.*;
  2. import ddf.minim.analysis.*;

  3.  
  4. int numBalloons = 160*120;
  5. Balloon[] balloons = new Balloon[numBalloons];


  6. Minim minim;
  7. AudioInput voice;
  8. FFT fft;


  9. float dampedVolume;
  10. float damping = 0.1;
  11. float filtering = 100;


  12. PImage pic2;


  13. void setup() {
  14.   size(640, 480);
  15.   smooth();
  16.   
  17.   minim = new Minim(this);
  18.   voice = minim.getLineIn(Minim.STEREO, 2048);
  19.   fft = new FFT(voice.bufferSize(), voice.sampleRate());


  20.   for (int i=0; i<numBalloons; i++) {
  21.     balloons[i] = new Balloon( i , i  );
  22.   }

  23.   pic2 = loadImage("pic2.JPG");
  24.   
  25. }



  26. void draw() {
  27.   
  28.   background(255);
  29.   analyseSound(); // done once, end result = new dampedVolume value
  30.   for (int i=0; i<balloons.length; i++) {
  31.     balloons[i].display();
  32.   }
  33. }

  34.  
  35.  
  36. void analyseSound() {
  37.   
  38.   fft.forward(voice.mix);
  39.   float volume = 0;
  40.   for (int i=0; i<filtering; i++) {
  41.     volume += fft.getBand(i);
  42.   }
  43.   
  44.   volume *= 0.25;
  45.   dampedVolume = dampedVolume + (volume - dampedVolume)*damping;

  46. }

  47.  

  48. void stop() {
  49.   
  50.   voice.close();
  51.   minim.stop();
  52.   super.stop();
  53.   
  54. }

  55.  

  56. class Balloon {

  57.   float x, y;
  58.   color c;
  59.   float scaler;

  60.   
  61.   Balloon(float x, float y) {
  62.     this.x = x;
  63.     this.y = y;

  64.     scaler = random(0.5, 2);
  65.   }

  66.   

  67.   void display() {
  68.  
  69.     noStroke();
  70.     
  71.     for (int x=1; x<160; x++) {
  72.     for (int y=1; y<120; y++) {
  73.       noStroke();
  74.       int imageColor = pic2.width*y+x;
  75.       fill(pic2.pixels[imageColor],30);
  76.       ellipse(x*4, y*4, dampedVolume*scaler, dampedVolume*scaler);
  77.       
  78.     }
  79.   }
  80.     
  81.   }
  82. }








from your adapted code, I just changed and added some things to
match the color and to array to be shown as picture. 
however, It doesn't work too.. -d-
please would you help me for last chance...;;?






PGL getting started

$
0
0
Hello everyone,

I want to get start using OPENGL in P5.
I am not sure how to start it and I can't find any tutorial on the
subject. 
I want to start drawing a gradiant traingle so I found this for
JOGL.  

  1.                  gl.glBegin(GL.GL_POLYGON);
  2. //We want to draw triangle in gradient color
  3. //So setting the color of first vertex as red
  4. gl.glColor4f(1, 0, 0, 1);
  5. gl.glVertex2d(100, 100);
  6. //Setting the color of second vertex as green
  7. gl.glColor4f(0, 1, 0, 1);
  8. gl.glVertex2d(100, 200);
  9. //Setting the color of third vertex as blue
  10. gl.glColor4f(0, 0, 1, 1);
  11. gl.glVertex2d(200, 200);
  12. //Our polygon ends here
  13. gl.glEnd();
  14. gl.glFlush();
from
http://wiki.tankaar.com/index.php?title=Drawing_First_2D_Graphics_in_JOGL

but I don't know how to reproduce those line in P5 as I even can't find
a class (I don't know the purpose and difference between PGL, GL,...)
that has the glBegin function.

Can someone give me a hint how to start.
Thanks in advance.
ra

Re : PGL getting started

$
0
0
For Processing 2.0xx there have been many changes, so I don't know. Even the example on the wiki seems to work no longer. So only andres knows.

For Processing 1.5.1 that would be:
  1. import javax.media.opengl.*;
  2. import processing.opengl.*;
  3.  
  4. void setup() {
  5.   size(800, 600, OPENGL);
  6. }
  7.  
  8. void draw() {
  9.   background(0);
  10.  
  11.   PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
  12.   GL gl = pgl.beginGL();
  13.  
  14.   gl.glBegin(GL.GL_POLYGON);
  15.   gl.glColor4f(1, 0, 0, 1);
  16.   gl.glVertex2d(100, 100);
  17.   gl.glColor4f(0, 1, 0, 1);
  18.   gl.glVertex2d(100, 200);
  19.   gl.glColor4f(0, 0, 1, 1);
  20.   gl.glVertex2d(200, 200);
  21.   gl.glEnd();
  22.   gl.glFlush();
  23.  
  24.   pgl.endGL();
  25. }
For full clarity. Of course the same shape could be drawn through the Processing API (but I assume you want to use low-level OpenGL calls for a reason):
  1. import processing.opengl.*;
  2.  
  3. void setup() {
  4.   size(800, 600, OPENGL);
  5. }
  6.  
  7. void draw() {
  8.   background(0);
  9.  
  10.   beginShape();
  11.   fill(255, 0, 0);
  12.   vertex(100, 100);
  13.   fill(0, 255, 0);
  14.   vertex(100, 200);
  15.   fill(0, 0, 255);
  16.   vertex(200, 200);
  17.   endShape();
  18. }
Viewing all 1768 articles
Browse latest View live