Nov 8th Intermediate Older Group Class Code

November 8, 2014 by Uncategorized No Comments
// position of the ball
var x = 20;
// how far the ball moves every time
var speed = 3;
var colour = 66;
var direction = ‘right’;
var draw = function() {
    background(202, 255, 97);
    if (direction === ‘right’) {
        colour = 66;
    }
    else {
        colour = 255;
    }
    fill(colour, colour, colour);
    ellipse(x, 200, 50, 50);
    if (x > 375) {
        direction = ‘left’;
        speed = -3;
    }
    if (x < 25) {
        direction = ‘right’;
        speed = 3;
    }
    // move the ball
    x = x + speed;
};