Hey I want to call a public function in a public class in the same class in processing (JAVA mode).
The Error:
Here is the complete code:
ParticleSystem ps;
PImage imageShape;
float deltaTime = 0;
void setup() {
//fullScreen();
size(600, 600);
//(float x, float y, float tx, float ty, float s, color c_
imageShape = loadImage(sketchPath("img.jpg"));
imageShape.resize(100, 100);
ps = new ParticleSystem(imageShape, width/2, height/2, 30);
}
void draw() {
deltaTime = 1 / frameRate;
background(0);
ps.update();
}
class Particle {
PVector pos;
PVector target;
float maxSpeed = 500;
float dist;
float size;
color c;
Particle(PVector p, PVector t, float s, color c_) {
pos = p.copy();
target = t.copy();
size = s;
c = c_;
dist = PVector.dist(pos, target);
}
void show() {
fill(c);
noStroke();
ellipse(pos.x, pos.y, size, size);
}
void move() {
float currentDist = PVector.dist(pos, target);
float speed = map(currentDist, 0, dist, 0, maxSpeed);
PVector vel = PVector.sub(target, pos);
vel.normalize();
vel.mult(speed);
vel.mult(deltaTime);
pos.add(vel);
}
}
class ParticleSystem {
ArrayList<Particle> particles;
PImage image;
PVector startPos;
float particleSize = 30;
int count;
ParticleSystem(PImage img, float x, float y, int c) {
super();
particles = new ArrayList<Particle>();
image = img.copy();
startPos = new PVector(x, y);
count = c;
thread("spawnParticles");
}
public void spawnParticles() {
image.loadPixels();
for (int i = 0; i < image.width; i++) {
for (int j = 0; j < image.height; j++) {
int index = i + j * image.width;
color c = image.pixels[index];
if (brightness(c) <= 40) {
PVector targetPos = new PVector(map(i, 0, image.width, 0, width), map(j, 0, image.height, 0, height));
Particle p = new Particle(startPos, targetPos, particleSize, color(255));
particles.add(p);
delay(50);
}
}
}
image.updatePixels();
}
void update() {
for (Particle p : particles) {
p.show();
p.move();
}
}
}