noob: image() function..
in
Programming Questions
•
3 years ago
I'm sending data from an audio application to Processing using OSC. I then use this data to place images on my sketch. After a while things start to get sluggish. My audio program does do quite a lot of fft analysis and so fort so I expect most of the CPU is being eaten by that. My question for the group is this, every time I lay an image onto my sketch does that somehow take up more and more memory? Is every instance of an image another layer for example? I've reduced my code to give you an idea of what I'm at.
void setup() {
a[0] = loadImage("concept03-01.png"); // Load the image into array
a[1] = loadImage("concept03-02.png"); // Load the image into array
a[2] = loadImage("concept03-03.png"); // Load the image into array
a[3] = loadImage("concept03-04.png"); // Load the image into array
a[4] = loadImage("concept03-05.png"); // Load the image into array
a[5] = loadImage("concept03-06.png"); // Load the image into array
a[6] = loadImage("concept03-07.png"); // Load the image into array
a[7] = loadImage("concept03-08.png"); // Load the image into array
a[8] = loadImage("concept03-09.png"); // Load the image into array
a[9] = loadImage("concept03-10.png"); // Load the image into array
size(640, 480);
frameRate(15);
}
void draw(){
float y = random(480);
float x = random(640);
int img = random(10);
image(a[img], x, y, a[img].width, a[img].height);
}
Is the above code about as efficient as it possibly can be? Sorry if this is a silly question, I've never done anything with graphics before.
void setup() {
a[0] = loadImage("concept03-01.png"); // Load the image into array
a[1] = loadImage("concept03-02.png"); // Load the image into array
a[2] = loadImage("concept03-03.png"); // Load the image into array
a[3] = loadImage("concept03-04.png"); // Load the image into array
a[4] = loadImage("concept03-05.png"); // Load the image into array
a[5] = loadImage("concept03-06.png"); // Load the image into array
a[6] = loadImage("concept03-07.png"); // Load the image into array
a[7] = loadImage("concept03-08.png"); // Load the image into array
a[8] = loadImage("concept03-09.png"); // Load the image into array
a[9] = loadImage("concept03-10.png"); // Load the image into array
size(640, 480);
frameRate(15);
}
void draw(){
float y = random(480);
float x = random(640);
int img = random(10);
image(a[img], x, y, a[img].width, a[img].height);
}
Is the above code about as efficient as it possibly can be? Sorry if this is a silly question, I've never done anything with graphics before.
1