mirror of
https://github.com/dyne/FreeJ.git
synced 2026-02-08 13:59:54 +01:00
processing-js 0.4 has been merged in some relevant parts basic and topic scripts added for test color handling fixed, more scripts show up now
42 lines
922 B
Plaintext
42 lines
922 B
Plaintext
int wsize = 60; // Width of the shape
|
|
float xpos, ypos; // Starting position of shape
|
|
|
|
float xspeed = 2.8; // Speed of the shape
|
|
float yspeed = 2.2; // Speed of the shape
|
|
|
|
int xdirection = 1; // Left or Right
|
|
int ydirection = 1; // Top to Bottom
|
|
|
|
|
|
void setup()
|
|
{
|
|
size(200, 200);
|
|
noStroke();
|
|
frameRate(30);
|
|
smooth();
|
|
// Set the starting position of the shape
|
|
xpos = width/2;
|
|
ypos = height/2;
|
|
}
|
|
|
|
void draw()
|
|
{
|
|
background(102);
|
|
|
|
// Update the position of the shape
|
|
xpos = xpos + ( xspeed * xdirection );
|
|
ypos = ypos + ( yspeed * ydirection );
|
|
|
|
// Test to see if the shape exceeds the boundaries of the screen
|
|
// If it does, reverse its direction by multiplying by -1
|
|
if (xpos > width-wsize || xpos < 0) {
|
|
xdirection *= -1;
|
|
}
|
|
if (ypos > height-wsize || ypos < 0) {
|
|
ydirection *= -1;
|
|
}
|
|
|
|
// Draw the shape
|
|
ellipse(xpos+wsize/2, ypos+wsize/2, wsize, wsize);
|
|
}
|