Sketch runs as intended in the exported jar but has issues in openprocessing
in
Integration and Hardware
•
2 years ago
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:
- int emergenceInterval = int(random(75, 100));
- float a, freq = 0.05;
- float alphDelta, alphAccel, alphSpringing = 0.0009, alphDamping = 0.98, alphX, maxAlph;
- int pAmt = int(random(2000, 4000));
- Particle p[] = new Particle[pAmt];
- void setup() {
- background(0);
- size(1000, 500);
- for (int i = 0; i < pAmt; i++) {
- p[i] = new Particle(random(width), random(height), i);
- }
- }
- void draw() {
- if(frameCount % emergenceInterval == 0) {
- if(maxAlph == .05) maxAlph = 1;
- else maxAlph = .05;
- }
- a += freq;
- fill(50, findAlpha() * 255);
- rect(0, 0, width, height);
- runParticles();
- }
- void runParticles() {
- for (Particle _p : p) {
- Particle lastP = _p;
- if (_p.index != 0) lastP = p[_p.index - 1];
- _p.update(450, lastP.pos, abs(pow(sin(radians(a)), 3)));
- point(_p.pos.x, _p.pos.y);
- _p.vel.x = 1;
- }
- }
- float findAlpha() {
- if (!(alphAccel < 0)) alphDelta = width - alphX;
- else alphDelta = 0 - alphX;
- alphDelta *= alphSpringing;
- alphAccel += alphDelta;
- alphAccel *= alphDamping;
- alphX += alphAccel;
- float alph = (alphX * (maxAlph * abs(pow(sin(radians(a)), 2))))/width;
- if(alphX > width) alphAccel *= -1;
- else if(alphX < 0) alphAccel *= -1;
- return alph;
- }
- class Particle {
- int index;
- float theta;
- float stride;
- float maxSpeed = 5;
- float maxChaos = 10;
- PVector accel, vel, pos;
- Particle(float startX, float startY, int index) {
- this.index = index;
- accel = new PVector(0, 0);
- vel = new PVector(0, 0);
- pos = new PVector(startX, startY);
- }
- void update(float stride, PVector target, float chaos) {
- this.stride = stride;
- stroke(50*(noise(pos.x)),0,50*(noise(pos.x)), noise(pos.x, pos.y) * 255);
- accel = noiseDir(chaos);
- accel.add(followDir(target));
- if (pos.x > width) pos.x = 0;
- if (pos.y > height) pos.y = 0;
- if (pos.y < 0) pos.y = height;
- vel.add(accel);
- float speed = noise(pos.x, pos.y) * maxSpeed;
- vel.limit(speed);
- pos.add(vel);
- }
- PVector noiseDir(float chaos) {
- theta = abs(noise(pos.x, pos.y)) * 180;
- float x = pos.x + stride * cos(theta);
- float y = pos.y + stride * sin(theta);
- PVector dir = new PVector(x - pos.x, y - pos.y);
- dir.normalize();
- dir.mult(chaos * maxChaos);
- return dir;
- }
- PVector followDir(PVector target) {
- PVector dir = new PVector(target.x - pos.x, target.y - pos.y);
- dir.normalize();
- dir.mult(5);
- return dir;
- }
- }
Thanks
1