Loading...
Logo
Processing Forum
My sketch runs fine from the PDE and from the exported jar. When I upload it to openprocessing however, the background() method works and fills the entire sketch, but the particles that are being drawn seem to only fill a small rectangle within the sketch. Here are some screenshots to illustrate the difference:

This is from present mode in the PDE:


And this is what happens when I upload the sketch to openprocessing. It's a bit hard to see, but the particles are pinkish and only fill a small rectangle in a corner of the sketch. Within the small rectangle, the behavior seems to be right, so it's almost like my sketch is getting cropped. 


Not really sure why this would happen, but I get errors when running the index.html so I suspect something is happening with my code. 

Here is the main class: 

Copy code
  1. int emergenceInterval = int(random(75, 100));
  2. float a, freq = 0.05;
  3. float alphDelta, alphAccel, alphSpringing = 0.0009, alphDamping = 0.98, alphX, maxAlph;
  4. int pAmt = int(random(2000, 4000));
  5. Particle p[] = new Particle[pAmt]; 

  6. void setup() {
  7.   background(0);
  8.   size(1000, 500); 
  9.   for (int i = 0; i < pAmt; i++) {
  10.     p[i] = new Particle(random(width), random(height), i);
  11.   }
  12. }

  13. void draw() {
  14.   if(frameCount % emergenceInterval == 0) {
  15.    if(maxAlph == .05) maxAlph = 1;
  16.    else maxAlph = .05; 
  17.   }
  18.   a += freq;
  19.   fill(50, findAlpha() * 255);
  20.   rect(0, 0, width, height);
  21.   runParticles();
  22. }

  23. void runParticles() {
  24.   for (Particle _p : p) {
  25.     Particle lastP = _p;
  26.     if (_p.index != 0) lastP = p[_p.index - 1];
  27.     _p.update(450, lastP.pos, abs(pow(sin(radians(a)), 3)));
  28.     point(_p.pos.x, _p.pos.y);
  29.     _p.vel.x = 1;
  30.   }
  31. }

  32. float findAlpha() {
  33.   if (!(alphAccel < 0)) alphDelta = width - alphX;
  34.   else alphDelta = 0 - alphX;
  35.   alphDelta *= alphSpringing;
  36.   alphAccel += alphDelta;
  37.   alphAccel *= alphDamping;
  38.   alphX += alphAccel;
  39.   float alph = (alphX * (maxAlph * abs(pow(sin(radians(a)), 2))))/width;
  40.   
  41.   if(alphX > width) alphAccel *= -1;
  42.   else if(alphX < 0) alphAccel *= -1;
  43.   return alph;
  44. }
And this is the Particle class:

Copy code
  1. class Particle {

  2.   int index;
  3.   float theta;
  4.   float stride;
  5.   float maxSpeed = 5;
  6.   float maxChaos = 10;
  7.   PVector accel, vel, pos;


  8.   Particle(float startX, float startY, int index) {
  9.     this.index = index;
  10.     accel = new PVector(0, 0);
  11.     vel = new PVector(0, 0);
  12.     pos = new PVector(startX, startY);
  13.   } 

  14.   void update(float stride, PVector target, float chaos) {
  15.     this.stride = stride;
  16.     stroke(50*(noise(pos.x)),0,50*(noise(pos.x)), noise(pos.x, pos.y) * 255);
  17.     accel = noiseDir(chaos);
  18.     accel.add(followDir(target));
  19.     if (pos.x > width) pos.x = 0;
  20.     if (pos.y > height) pos.y = 0;
  21.     if (pos.y < 0) pos.y = height;
  22.     vel.add(accel);
  23.     float speed = noise(pos.x, pos.y) * maxSpeed;
  24.     vel.limit(speed);
  25.     pos.add(vel);
  26.   }

  27.   PVector noiseDir(float chaos) {
  28.     theta = abs(noise(pos.x, pos.y)) * 180;
  29.     float x = pos.x + stride * cos(theta);
  30.     float y = pos.y + stride * sin(theta);
  31.     PVector dir = new PVector(x - pos.x, y - pos.y);
  32.     dir.normalize();
  33.     dir.mult(chaos * maxChaos);
  34.     return dir;
  35.   }

  36.   PVector followDir(PVector target) {
  37.     PVector dir = new PVector(target.x - pos.x, target.y - pos.y);
  38.     dir.normalize();
  39.     dir.mult(5);
  40.     return dir;
  41.   }
  42. }
Please let me know if I can clarify anything

Thanks            

Replies(6)

Note that size() call should be the first of setup(). Beside that (I doubt it will change much), at a quick glance, I don't see anything wrong, you don't seem to use exotic libraries, not even OpenGL.
I did not know this, thank you. 

Unfortunately I uploaded the applet again with no change.
 
Hi
I got the openprocessing effect when I ran your code. I've had a play with this:
 
- after commenting nearly everything out, I think that the line that is causing it is

stroke(50*(noise(pos.x)),0,50*(noise(pos.x)), noise(pos.x, pos.y) * 255);

If I set the stroke to just (50) (or (255) so that I could see better what was happening), I had happy little particles all over the screen
 
- by drawing lines, I found that with the stroke set to (255, noise(pos.x, pos.y) * 255), the bounds of visibility were as shown here
 
 
- I tried to println the values found for your stroke's alpha and - gee thanks - my machine froze. It was interesting that even before then, I couldn't println anything. I couldn't save the code, but grabbed the image.
 
 
I'm stopping now!
 
 
" and from the exported jar"
Running in the same browser?
Ie. is that OpenProcessing specific, or applet specific? Do you have the same issue in a different browser? Different computer?
Perhaps you should give the OpenProcessing URL of your sketch.
Thank you so much allonestring! I just gave every particle the same alpha value in the line you pointed out. 

Here is the working sketch on openprocessing.

@phi.lho, it might have been the same issue but before when I opened the applet's index.html in the browser the Java applet said to click for details on the errors. 
You're welcome. I just wish that I could've included the code. If something is going wrong, comment out as much as possible,  print out values as you pass them to functions, and give everything bland neutral values until you find out what's causing it.