// Copyright © 2011 Mark F. Russo // Bryn Mawr College, Department of Computer Science // Permission is granted to copy and distribute provided // this entire copyright notice is reproduced in all copies. int positionX = 250; int positionY = 250; int deltaX = 0; int deltaY = 0; void setup() { size(500, 500); smooth(); } void draw() { background(255); // Increment position and clip value positionX = positionX + deltaX; positionY = positionY + deltaY; // Clip values if (positionX < 0) positionX = 0; if (positionX > width) positionX = width; if (positionY < 0) positionY = 0; if (positionY > height) positionY = height; // Draw ellipse ellipse(positionX, positionY, 50*( sin(0.1*positionX)+2), 50*( cos(0.1*positionY)+2) ); } void keyPressed() { // Change direction based on key code switch (keyCode) { case 37: deltaX = -2; deltaY = 0; break; case 39: deltaX = 2; deltaY = 0; break; case 38: deltaY = -2; deltaX = 0; break; case 40: deltaY = 2; deltaX = 0; break; case 32: deltaX = 0; deltaY = 0; break; } }