Point p; float lastX, lastY; float x, y; float speedX, speedY; color c; void setup() { size(600, 600); colorMode(HSB, 360, 100, 100, 100); smooth(); x = random(width); y = random(height); p = new Point(1, 2); speedX = random(100); speedY = random(10); c = color(random(360), 30, 100); background(c); } void draw() { p = new Point(x, y); noStroke(); fill(c); c = color(random(360), 30, 100); ellipse((float)p.x, (float)p.y, 100, 100); x += speedX; y += speedY; if (x > width) { x = width; speedX *= -1; } if (y > height) { y = height; speedY *= -1; } if (x < 0) { x = 0; speedX *= -1; } if (y < 0) { y = 0; speedY *= -1; } } public final class Point { private final double x; // x-coordinate private final double y; // y-coordinate // random point public Point() { x = 0; y = 0; } // point initialized from parameters public Point(double x, double y) { this.x = x; this.y = y; } // accessor methods public double x() { return x; } public double y() { return y; } public double r() { return Math.sqrt(x*x + y*y); } public double theta() { return Math.atan2(y, x); } // Euclidean distance between this point and that point public double distanceTo(Point that) { double dx = this.x - that.x; double dy = this.y - that.y; return Math.sqrt(dx*dx + dy*dy); } // return a string representation of this point public String toString() { return "(" + x + ", " + y + ")"; } }