int r = 10; float x0 = r, y0 = r; float g = 9.8; float v0 = 30; float theta = PI/8; float t = 0; float x = x0; float y = y0; void setup() { size(300,300); colorMode(RGB,255,255,255,100); ellipseMode(RADIUS); background(0,0,0); frameRate(50); } void draw() { stroke( 0, 0, 0, 1 ); fill( 0, 0, 0, 1 ); rect( 0, 0, width, height ); x = x0 + v0*cos(theta)*t; y = y0 + v0*sin(theta)*t+g*t*t/2.0; stroke( 0, 0, 100, 100 ); fill( 0, 200, 255, 100 ); ellipse( x, y, 10, 10 ); t = t + 0.1; if( y > height-r ) { float vx0 = v0*cos(theta); float vy0 = v0*sin(theta)+g*t; vy0 = -vy0 * 0.8; v0 = sqrt( vx0*vx0 + vy0*vy0 ); theta = atan( vy0/vx0 ); if( vx0 < 0 ) theta = theta + PI; x0 = x; y0 = height-r; t = 0; } if( x > width-r ) { float vx0 = v0*cos(theta); float vy0 = v0*sin(theta)+g*t; v0 = sqrt( vx0*vx0 + vy0*vy0 ); theta = PI-atan( vy0/vx0 ); x0 = width-r; y0 = y; t = 0; } if( x < 0 ) { float vx0 = v0*cos(theta); float vy0 = v0*sin(theta)+g*t; v0 = sqrt( vx0*vx0 + vy0*vy0 ); theta = -atan( vy0/vx0 ); x0 = 0; y0 = y; t = 0; } }