Best way to load 100 of the same image (and effect each independently!)
in
Programming Questions
•
4 months ago
Hi Everyone,
I want to create an interactive projection with objects that move or disappear when triggered by motion;
I come from a max/msp background and still learning processing so I'm struggling a little,
What I need to know is the best way to approach this;
I need to load 100 images,
each image must be able to be effected independently of the other, (e.g if mouse over the object shrinks, grows, disappears etc but the other remain unchanged)
But obviously writing code to load 100 individual PImages etc is the wrong way to go about it!
Im thinking i need to write a
class and use an
array but I am struggling to get my head round how to do it.
If someone could post a little code or point me to a tutorial Id really appreciate it!!
Regards,
Oli
Heres my class but it need extending to fit my needs described above;
int numBalls = 6;
Ball [] balls = new Ball[numBalls];
void setup() {
size(500, 500);
smooth();
ellipseMode(RADIUS);
for (int i = 0; i < balls.length; i++) {
float x = random(width);
float y = random(height);
int diameter = int(random(100));
balls[i] = new Ball(x, y, diameter);
}
}
void draw() {
for (int i = 0; i <balls.length; i++) {
balls[i].display();
balls[i].hit();
}
}
class Ball {
float x;
float y;
float d = dist(mouseX, mouseY, x, y);
int diameter;
Ball(float tempX, float tempY, int tempDiameter) {
x =tempX;
y = tempY;
diameter = tempDiameter;
}
void display() {
ellipse(x, y, diameter, diameter);
}
void hit() {
if (mousePressed) {
diameter++;
}
}
}
1