/** * Course Number: 22491 for Eng * Assignment Number: 5 * Question Number: * Sketch description * @author Ignas Jauneika, G00247692 * 08/03/2009 */ int xpos, ypos; int xspeed = 1; int yspeed = 2; int xdirection = 1; int ydirection = 1; void setup () { size ( 300, 300 ); smooth (); frameRate(30); } void draw () { background (255); rectMode(CENTER); fill (distanceFromMouse(0,0)); rect ( 150, 150, 50, 50); rectMode(CORNER); drawRect ( 0, 0, 300, color(mouseX,38,mouseY,140)); drawRect ( 0,150,300, color(100,mouseX,0,140)); int tsize = int(dist(xpos,ypos,mouseX,mouseY)/2); drawCircle ( xpos, ypos,tsize, color (xpos,ypos)); move(); bounce(); } void drawRect (int x, int y, int thesize, color c) { noStroke (); fill (c); rect ( x, y, thesize, thesize/2); } void drawCircle ( int xpos, int ypos, int circlesize, color c) { noStroke(); fill(c); ellipse ( xpos, ypos, circlesize, circlesize); } void move () { xpos = xpos + ( xspeed * xdirection ); ypos = ypos + ( yspeed * ydirection ); } void bounce () { if (xpos > width || xpos < 0) { xdirection *= -1; } if (ypos > height || ypos < 0) { ydirection *= -1; } } float distanceFromMouse(int f, int i) { float dx = f-mouseX; float dy = i-mouseY; float d = sqrt(dx*dx + dy*dy); return d; }