Stuck on a simple class
in
Programming Questions
•
1 year ago
Okay so this is what I want to do; I have some exported images that I want to display randomly. Clicking the mouse should "activate" a first random exported image, and then I just want it to expand until it is as big as the size of my screen. Then I want this Image to go away, and to be replaced by a new random image (that starts small again and then grows till it hits the size of the screen, and so on and on).
This may seem pretty easy but I don't think I have a clue of what I'm doing since I'm really a beginner at this.
So far...
And for the class:
So what this does (sort of): it adds a new random image when you click, but I don't know how to make it go away when it its width equals the windows width, since I'm pretty confused using the class and everything. Well, using Processing, generally.
The
, of course, is not working, the image resets to size 0, 0 but then just grows again.
This may seem pretty easy but I don't think I have a clue of what I'm doing since I'm really a beginner at this.
So far...
- ArrayList all;
void setup() {
size(700, 700);
all = new ArrayList();
}
void addClassInstance() {
export neimage = new export();
neimage.init();
all.add(neimage);
}
void draw() {
if (all.size()>20) {
all.remove(0);
}
for (int i=0;i<all.size();i++) {
export b = (export) all.get(i);
b.draw();
}
}
void mouseClicked() {
addClassInstance();
}
And for the class:
- class export {
PImage eimage;
float x, y;
float i = 0;
float w = 150;
float h = 150;
void init() {
imageMode(CENTER);
int number = int(random(1, 499));
eimage = loadImage("export-"+number+".png");
x = width/2;
y = height/2;
}
void draw() {
image(eimage, x, y, w + i, h + i);
i ++;
if(w + i > width + 100){
w = 0;
h = 0;
}
}
}
So what this does (sort of): it adds a new random image when you click, but I don't know how to make it go away when it its width equals the windows width, since I'm pretty confused using the class and everything. Well, using Processing, generally.
The
- if(w + i > width + 100){
w = 0;
h = 0;
}
, of course, is not working, the image resets to size 0, 0 but then just grows again.
1