Friday, 17 December 2010

getting started with the code

After spending some time generating my idea I have now gotten to work on the code. I have taken the basis of an example Seb made, where particles on the screen move when movement is detected by the camera.

One of my first changes was to make the particles into an image I wanted. One of my ideas was to cover the screen in images, with Processing choosing a random number of different images to display, making it look less uniform. After a bit of searching on the web I came across some code on a Processing forum (here) which allowed me to do this:

// DECLARE YOUR GLOBAL VARIABLES HERE.
PImage fragment;
int rand;

void setup() {
size(800, 600);
rand = int(random(0,4)); //HERE YOU CHOOSE BETWEEN 10 DIFFERENT IMAGES
takerandomimage("frag_" + nf(rand, 3) + ".jpg"); //CALL YOUR FUNCTION 'takerandomimage'
//REMEMBER TO NAME YOUR IMAGES "frag_000.jpg"
}
// THIS IS THE FUNCTION
void takerandomimage(String fn) {
fragment = loadImage(fn); //LOAD RANDOM IMAGE
image(fragment,0,0);//DISPLAY RANDOM IMAGE
}


However, applying this code into my sketch makes it run very slowly, not a particularly desirable result!

Therefore I will continue working with just one image to duplicate over the screen.

No comments:

Post a Comment