/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.$bgL9o70B7n/rev.1331
*
* authors:
* Kevin Crouch
* Gregg Blanchard
* Andrzej Koper
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// Global variables
float radius = 30;
float ball_dir = 1;
float dy = 0;
// Direction
int ball_X, ball_Y;
int ball_nX, ball_nY;
int delay = 3;
// Setup the Processing Canvas
void
setup(){
size
( 400, 400 );
frameRate( 30 );
ball_X = width / 2;
ball_Y = height / 2;
ball_nX = X;
ball_nY = Y;
}
// Main draw loop
// If the ball is touching top or bottom edge, reverse direction
void
draw
(){
// Track circle to new destination
ball_X+=(ball_nX-ball_X)/delay;
ball_Y+=(ball_nY-ball_Y)/delay;
if
(ball_nY <= 10) {
ball_nY = 200;
ball_nX = 200;
}
if
(ball_nY >= 390) {
ball_nY = 200;
ball_nX = 200;
}
if
(ball_nX >= 390) {
ball_nX = 200;
ball_nY = 200;
}
if
(ball_nX <= 10) {
ball_nX = 200;
ball_nY = 200;
}
// Fill canvas black
background
( 0 );
// Set fill-color to blue
fill
( 0, 130, 184 );
// Draw circle
ellipse
( ball_X, ball_Y, radius, radius );
}
// Set circle's next destination
void mouseMoved(){
ball_nX = mouseX;
ball_nY = mouseY;
}