Thursday, 6 November 2008

A start

I've not yet got the book but after having a look at a few bits I decided to have a play and have come up with a really pointless little program.

This makes a black ball float across the screen diagonally up or down, left or right
when you click your mouse to the right of the pointer the screen changes colour randomly and the ball changes direction in the direction of the mouse pointer - Its just a bit of fun and a good little introduction for me.

I think I'll have a go at creating little navigation game so watch this space..

here is the code..

void setup()
{
size(400,400);
noStroke();
frameRate(100);
}

boolean rightLeft = true;
boolean topBottom = false;

float mover = 300;
float x = 1;
float y = 1;
float clicked = 0;
float c1,c2,c3 = 255;

void mousePressed()
{
clicked++;

c1 = random(255);
c2 = random(255);
c3 = random(255);

if(mouseX > x) rightLeft = true;
else rightLeft = false;

if(mouseY > y) topBottom = false;
else topBottom = true;

print("mouse x =" + mouseX + "mouse Y =" + mouseY);
print("pos x =" + x + "pos y =" + y);
}

void draw()
{

background(c1, c2, c3);
if(rightLeft) x = x + 1;
else x = x - 1;

if(topBottom) y = y - 1;
else y = y + 1;

if(y > 400) y = 0;
if(x > 400) x = 0;
if(y < 0) y = 400;
if(x < 0) x = 400;

fill(0);
ellipse(x, y, 10, 10);
}

No comments:

Post a Comment