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

Cube Mapping with OpenGL in Processing 2.07b

$
0
0
i came across this thead and wantto achiev the effekt in processing 2.0:

i wrote a small sketch demonstrating what should happen in in processing 1.5. it is basically the same functionality as in the working version of the thread above. this is what it looks like:


i want to achive the same effekt (cube mapping) with processing 2.0. and since the glgraphics library from of andres should be included mostly into processing 2.0 it should be no problem- i just dont know enough of the inner workings of processing with opengl in combiation with shaders to make it work. my status looks like this: (you can see the back strokes of the sphere that should have the reflections of the cube map on it):


maybe somebody can help me to get this to work. i zipped up both versions for you to debug here:

marcel

Simple Question About minim: MonitorInput

$
0
0
I'm new and confused.

There is a get() function in the code of MonitorInput and when i look what it does in the reference it says it relates to color and pixels. So why would they use this function in this manner

line( i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50 );

is it an abbreviated version of getLineIn() ? 

Re : Simple Question About minim: MonitorInput

$
0
0
I can see why you are confused.
Quite simply, the get() call you see above and the get() function described in the reference are two totally different functions.

A plain old call to get() returns information about the pixels currently drawn on the screen - either at a point or as an array of colors.

But what you're asking about is not a plain old call to get(). It's a member function of a object, possibly an AudioPlayer object. The "in.right." before the call to get() says "you know that input we have? You know the right channel of that input? Well I want to get() information about the right channel of that input."

I don't know what getLineIn() does, so I can't compare the two.

Interestingly enough, a plain old call to get() is also not really a plain old call to get(). It's a call to the PGraphics object g.get(), which is why it gets pixel information.

To know exactly what the call to in.right.get() is doing, you'd have to look at the reference for the member functions of the object type that your variable "in" is!

Does that help explain it?

Re : Help with Serial read

$
0
0
Can you make a example code for me??

Thanks!!!!

Cant get my processing sketch to wait for a response from the arduino

$
0
0
The code below, does exactly as i want in terms of processing the image, and converting it into a stream of values.
however i want it to
1) wait for an initial "ready" command from the ardunio
2) wait for a "ready" command from the arduino in between each and every number transmission.

the arduino is processing the numbers physically, and therefore takes time.

I have used "300" as my ready command because the sketch is dealing in shades between 0 and 255. I figure it it one less thing to worry about if i dont start chucking ascii in there too.
My "commands" can be 300, 301, 302 etc.

I THINK i have narrowed down the lines which need attention to lines 17 and 33. I pressume i need a "serial Event" void in there? but i am dont know what to do with it. All the tutorials i have read and watched (of which there are many) do different things with it, none of which i understand properly. I presume what is required here depends on the context?

Many thanks

Ol

  1. import processing.serial.* ;
  2. Serial myPort;
  3. int ready = 300; // greyscale is 0-255. decided to use 300+ as commands, to prevent from mixing ascii with numbers.
  4. PImage img1;
  5. int cellSize = 10; // size of cells into which the image is split, larger size = less cells
  6. int squareSize = 300; // size of the working frame
  7. float greyscale;
  8. void setup() {
  9.   size(squareSize, squareSize);
  10.   println(Serial.list());
  11.   String portName = Serial.list()[0];
  12.   myPort = new Serial(this, portName, 9600);
  13.   print("Port: ");
  14.   println(myPort);
  15.   myPort.clear();
  16.   myPort.read();
  17.   myPort.bufferUntil(ready); // ********this is SUPPOSED to wait for a "ready" signal from the arduino (sent on button press) It doesn’t, obviosuy
  18. }
  19. void draw() {
  20.   background(0);
  21.   img1 = loadImage("grad.jpg"); // image, 300 x 300
  22.   imageMode(CENTER);
  23.   image(img1, (squareSize/2), (squareSize/2)); // draws the image
  24.   for (int y = 0; y < squareSize; y = y + cellSize ) {
  25.     // "carrige return" instruction from processing to the arduino will go in here (probably)
  26.     for (int x = 0; x < squareSize; x = x + cellSize) {
  27.       color c = get(x + cellSize/2, y + cellSize/2);
  28.       float greyscale = brightness(c);  // Sets 'greyscale' to 255-0
  29.       println(greyscale); //show the greyscale
  30.       myPort.write(c);    // send it to the arduino
  31.       myPort.clear();     // clear the port
  32.       delay (300);        // delay for easy reading
  33.       myPort.bufferUntil(ready); // ***** this is SUPPOSED to WAIT until the arduino replies that it is ready.
  34.     }
  35.   }
  36. }
  37. void serialEvent (Serial myPort) {
  38.   myPort.read(); // ******* Not really sure what is needed here., or if serial Event is needed at all?
  39. }

Re : frameRate() can crash 2.0b7

$
0
0
I can notice the jerkiness you are referring to in your sketch (https://dl.dropbox.com/u/95395455/sphereofpoints6.zip, I'm testing it on a MacBook Pro with OS X 10.8.2 and a Radeon HD 6490M). My guess at this moment is that is due to the particular way you are rendering your geometry. 

Consider this other sketch (just a slightly modified version of the Esfera example that comes with Processing):
  1. int cuantos = 20000;
  2. Pelo[] lista ;
  3. float radio = 200;
  4. float rx = 0;
  5. float ry =0;

  6. int fcount, lastm;
  7. float frate;
  8. int fint = 3;

  9. void setup() {
  10.   size(1280, 800, P3D);

  11.   radio = height/3.5;

  12.   lista = new Pelo[cuantos];
  13.   for (int i = 0; i < lista.length; i++) {
  14.     lista[i] = new Pelo();
  15.   }
  16.   noiseDetail(3);
  17. }

  18. void draw() {
  19.   background(0);
  20.   
  21. //  float rxp = (mouseX-(width/2)) * 0.005;
  22. //  float ryp = (mouseY-(height/2)) * 0.005;
  23. //  rx = rx*0.9 + rxp*0.1;
  24. //  ry = ry*0.9 + ryp*0.1;
  25.   ry += 0.01;
  26.   
  27.   translate(width/2, height/2);
  28.   rotateY(ry);
  29. //  rotateX(rx);
  30.   fill(0);
  31.   noStroke();
  32.   sphere(radio);

  33.   for (int i = 0; i < lista.length; i++) {
  34.     lista[i].dibujar();
  35.   }

  36.   fcount += 1;
  37.   int m = millis();
  38.   if (m - lastm > 1000 * fint) {
  39.     frate = float(fcount) / fint;
  40.     fcount = 0;
  41.     lastm = m;
  42.     println("fps: " + frate); 
  43.   } 
  44. }

  45. class Pelo
  46. {
  47.   float z = random(-radio, radio);
  48.   float phi = random(TWO_PI);
  49.   float largo = random(1.15, 1.2);
  50.   float theta = asin(z/radio);

  51.   Pelo() { // what's wrong with a constructor here
  52.     z = random(-radio, radio);
  53.     phi = random(TWO_PI);
  54.     largo = random(1.15, 1.2);
  55.     theta = asin(z/radio);
  56.   }

  57.   void dibujar() {

  58.     //float off = (noise(millis() * 0.0005, sin(phi))-0.5) * 0.3;
  59.     //float offb = (noise(millis() * 0.0007, sin(z) * 0.01)-0.5) * 0.3;
  60.     float off = 0;
  61.     float offb = 0;

  62.     float thetaff = theta+off;
  63.     float phff = phi+offb;
  64.     float x = radio * cos(theta) * cos(phi);
  65.     float y = radio * cos(theta) * sin(phi);
  66.     float z = radio * sin(theta);

  67.     float xo = radio * cos(thetaff) * cos(phff);
  68.     float yo = radio * cos(thetaff) * sin(phff);
  69.     float zo = radio * sin(thetaff);

  70.     float xb = xo * largo;
  71.     float yb = yo * largo;
  72.     float zb = zo * largo;

  73.     strokeWeight(1);
  74.     beginShape(LINES);
  75.     stroke(0);
  76.     vertex(x, y, z);
  77.     stroke(200, 150);
  78.     vertex(xb, yb, zb);
  79.     endShape();
  80.   }
  81. }
I find the animation to be quite smooth in this case, and I'd say that the complexity of the geometry is comparable to your sketch. Maybe I can notice one or two bumps right at the beginning, but it might be due to the GC kicking in and disposing some temporary objects used during initialization (just guessing).

If I disable the point rendering in you sketch, the jerkiness seems to disappear. Specifically, by commenting out:
  1.   gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, nodes_vbo[0]);
  2.   gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
  3.   gl.glDrawArrays(GL2.GL_POINTS, 0, nodecount);
  4.   gl.glBindBuffer( GL2.GL_ARRAY_BUFFER, 0);
What I found problematic about the way you render points is that you use gl_PointSize in your shader, and my impression (not 100% sure though) is that by doing so you are loosing the performance advantage of the VBOs because for each point center, the gpu needs in each frame to tessellate and rasterize the rest of the circle. I think it would be a better idea to use triangles to represent each point explicitly as a strip. The vertex count would be higher, but you can store all the vertices beforehand inside the VBO.

Re : frameRate() can crash 2.0b7

$
0
0
If that were the case and it was the rendering of points, I would expect to see the same jerkiness in Processing 1.x since it would be a GPU bottleneck, but I don't.  It runs perfectly fine in prior versions. 

I'm not sure how much needs to go on, as it's not rendering a circle point, but a sprite tied to a vertex.  I even turn off the smoothing, so its just a square sprite.  I would think processing triple the vertex count, triple the color buffer (not applicable in this example I think), along with billboard rotation would cost more than adjusting the point size.  At least, in my prior tests when comparing textured quads to point sprites, the sprites were way faster.

Re : error, disabling serialEvent() for //./COM3

$
0
0
Hi 
Thank you for your reply...
You were right,  code crashed before reaching this line
  1. println(inByte);

I am sending data from arduino by this method
  1.  Serial.println(average*10/1023);
and getting in processing by 
  1.  void serialEvent (Serial myPort) {
  2.  String inString = myPort.readStringUntil('\n');
  3.  float inByte = float(inString);
problem in this section.
I don't know how to send data from arduino to get as a string in processing.
Need your valuable suggestion.
thanking you in anticipation

Serial Library and Arduino

$
0
0
Hi to everyone.
So, I'm using Processing to communicate with an Arduino through a Bluetooth serial port.
I'm trying to understand why when I write bytes to the Serial port, it's very slow.
Here's an example to understand:
  1. import processing.serial.*;
  2. Serial myPort;
  3. byte arr[] = {0,1,2,3,4,5,6,7,8,9,
  4.               0,1,2,3,4,5,6,7,8,9,
  5.               0,1,2,3,4,5,6,7,8,9,
  6.               0,1,2,3,4,5,6,7,8,9,
  7.               0,1,2,3,4,5,6,7,8,9};

  8. void setup() 
  9. {
  10.   size(400, 600);
  11.   myPort = new Serial(this, "/dev/tty.HC-05-DevB", 57600);
  12. }

  13. void draw()
  14. {
  15.  myPort.write(arr); 
  16.  //myPort.write((byte)1);
  17.  println(millis());
  18. }
This gives me the following output:
  1. 3183
  2. 3200
  3. 3401
  4. 3652
  5. 3902
  6. 4152
  7. 4402
  8. 4652
  9. 4902
  10. 5152
  11. 5402
  12. 5655
  13. 5902
  14. 6152
  15. ..
So I'm sending a 'frame' of 50bytes 4 times a second. But the STRANGE thing is that if I send, instead of a 50bytes frame, just a single byte (uncommenting the 18th line and commenting the 17th), the result is EXACTLY the same.
How can this be possible? If the max speed is 4 bytes per second, how it comes that i can send 4 frames of 50 bytes in one second?

Thank you for the help, I've also tried looking in the Processing source code to understand how this works but no luck..

Re : frameRate() can crash 2.0b7

$
0
0
I removed the point size in the shader and it didn't make it any faster that I could tell.. It was still jerky.  Commenting out the section you mentioned (which is in there twice) would seem to defeat the entire sketch, as that is what renders the 60,000 textures.  Otherwise, you're just rending a skybox.  I still don't see how it would be a GPU bottleneck if it works perfectly fine in 1.5 using the exact same shader and opengl code.

Re : frameRate() can crash 2.0b7

$
0
0
ok, not sure at this point what could be the reason... I will look at it a bit more and let you know what I find.

High resolution frames from an animation

$
0
0
Hi. 
This is my first attempt at Processing, sorry for the silly questions.
I need to save frames at 300 dpi minimum for professional printing. 
I tried to use a frame 4 times the size of my monitor, but I really need to see what's happening when I record so it does not work for me.
Instead I tried to use the PDF library but I only save 'blank' frame, I don't understand why.
Is there a better way of saving at high resolution, if not, can you tell me what's wrong with my code?
Thank you for your help!

import processing.pdf.*;

boolean record;

 
int num = 60;
int colorL=255,k = 0,j=100,i=200;
 
float x,y,z;
float r,th=0,step=.1,epi=200;
float m = 1,n1=-1,n2=0,n3=0;
float b=1,a=1;
int counter1=0, counter2=0;
 
 
void setup() 
{
  size(1800,1100);
  background(0);
  frameRate(50);
  smooth();
}
 
void draw() {
 if (record) {
    // #### will be replaced with the frame number. 
    beginRecord(PDF, "frame-####.pdf");
    }
{
   
  fill(0,5);
  rect(-5, -5, 1805, 1105);
  counter1++;
  if (counter1 == 75) {
    m=int(random(3,60));
    n1=random(2);
    n2=random(2);
    n3=random(.1);
    epi=random(50,200);
    step=random(.01,10);
    counter1 = 0;
  }
  translate(mouseX, mouseY-100);
  stroke(colorL,35);
  noFill();
  beginShape();
  for(int i=1; i < num; i++) {
    r = epi*pow(((pow(abs(cos(m*th/5)/a),n2))+(pow(abs(sin(m*th/5)/b),n3))),(-1/n1)) * random(10000)/random(1000); 
    th = th + step;
    x = r*cos(th);
    y = r*sin(th);
    curveVertex(x,y);
  }
  endShape();
  
  if (record) {
  endRecord();
  record = false;
  }
 
}
}
 // Use a keypress so thousands of files aren't created
void mousePressed() {
  record = true;


Re : High resolution frames from an animation

$
0
0
You draw white lines on the default PDF background which is white...
A solution is to do:
 if (record) {
    // #### will be replaced with the frame number.
    beginRecord(PDF, "H:/Temp/frame-####.pdf");
    background(0);
    }
but it probably won't record what you expect.
A PDF recorder must record drawing orders from the start, if you want a kind of "screenshot" effect.

Re : High resolution frames from an animation

$
0
0
Hey, thanks for the super fast response!

"A PDF recorder must record drawing orders from the start, if you want a kind of "screenshot" effect."
So I should put a recorder in my void set up? (sorry to waste your time, I'm really new to this).

Also, I tried the code you proposed before, but I have this error message when I call the background(0):  


Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
at processing.core.PApplet.runSketch(PApplet.java:9660)
at processing.core.PApplet.main(PApplet.java:9469)
Caused by: java.lang.NullPointerException
at processing.core.PApplet.fill(PApplet.java:13500)
at test_pdf.<init>(test_pdf.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:310)
at processing.core.PApplet.runSketch(PApplet.java:9658)
... 1 more

Re : Serial Library and Arduino

$
0
0
I think it seems exactly the same because it is exactly the same. Think about what might cause that. You may have demonstrated a valuable lesson if this is what I think it is. The draw loop executes at a fixed speed over and over. Apparently it looks like the array transmits faster than the draw loop cycle speed. Therefore the single byte and the array transmission time "seem" to be the same. Look into the draw loop speed settings. 

Re : Serial Library and Arduino

$
0
0
Yes, I thought that too but.. if I use a while(true) {code} loop the result is exactly the same. 

serial problem in reading a string

$
0
0
I am trying to send a string from arduino to processing but that didn't work for me.

I am sending data from arduino by this method
  1.  Serial.println(average*10/1023);
and getting in processing by 
  1.  void serialEvent (Serial myPort) {
  2.  String inString = myPort.readStringUntil('\n');
  3.  float inByte = float(inString);
I am getting this error......

error, disabling serialEvent() for //./COM3
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)

I don't know how to send data from arduino to get as a string in processing.
Need your valuable suggestion.
thanking you in anticipation

Re : High resolution frames from an animation

$
0
0
Don't use my path in the beginRecord() line, I added it because I don't save most sketches I try from the forum.
You probably don't have a H drive... I forgot to remove the path.
Just add the background call.

How do I make the white square stay over the webcam?

$
0
0
Hi everyone!! Anyone who could help me out with this? I am trying to make the trail of the white square stay over the webcam's image. How can i do that??

this is the code I have written so far....


import processing.video.*;
Capture cam;

void setup() {
  size(640, 536, P2D);
 
  cam = new Capture(this,width, height);
    cam.start();
}
void draw() {

  // draw grey rectrangle
  stroke(255);
  fill(255);
  rectMode(CENTER);
  rect(mouseX,mouseY,50,50);
      if (cam.available() == true) {
  cam.read ();
  image(cam,0,0);
    }
}



Thank you very much!

Re : How do I make the white square stay over the webcam?

$
0
0
Just draw the cam image before drawing the rectangle.
Viewing all 1768 articles
Browse latest View live