Tuesday 10 November 2009

Processing - Homework 1

Yesterday, I missed a workshop on Processing so I tried to catch up today. I got from Pierre the snippets we ran in the class and tried to understand them. I found the whole library which is used in Processing here and that made things easier.

Then I moved on to do our homework for Thursday which is:

Modify the code below to play the animation forward / backward:
    
    int numFrames=6;
    int frame=0;
    PImage[] images = new PImage[numFrames];
    
    void setup() {
    
    size(600, 600);
    frameRate(10);
    images[0] = loadImage("b1.jpg"); 
    images[1] = loadImage("b2.jpg"); 
    images[2] = loadImage("b3.jpg"); 
    images[3] = loadImage("b4.jpg"); 
    images[4] = loadImage("b5.jpg"); 
    images[5] = loadImage("b6.jpg"); 
    }
    
    void draw() {
    if (mouseY > 20 && mouseY < 300) {
    frameRate(mouseY/10);
    }
    frame++;
    if (frame == numFrames) {
    frame=0;
    }
    image(images[frame], 0, 0);
    }

My changes (the .pde file) along with the pictures it uses, are available below:


Code (click to enlarge):



Firstly I removed the part with the mouse (added it later on again) and slowed the frame rate so I could see if my animation was working when I was trying several ways to do the exercise. For the forward / backward animation we use a boolean variable which declares if the counter (frame index) should be ascending or descending. When ascending if the counter reaches 5 (counting starts at zero) we change the value of the boolean variable from asceding to descending, and vice versa in the case of descending when the frame index reaches 0.



When it comes to random pictures, I cannot image.Google.com something else than Roger Federer =)

No comments:

Post a Comment