/** * Non-orthogonal Reflection * by Ira Greenberg. * * Based on the equation (R = 2N(N*L)-L) where R is the * reflection vector, N is the normal, and L is the incident * vector. */ PVector base1; PVector base2; float baseLength; PVector[] coords; PVector position; float r = 6; PVector direction; float speed = 3.5; PVector velocity; void setup() { size(640, 360); fill(128); base1 = new PVector(0, height-150); base2 = new PVector(width, height); createGround(); // start ellipse at middle top of screen position = new PVector(width/2, 0); // calculate initial random direction direction = PVector.random2D(); velocity = new PVector(); } void draw() { // draw background fill(0, 12); noStroke(); rect(0, 0, width, height); for (int i=0; i width-r) { position.x = width-r; direction.x *= -1; } // left if (position.x < r) { position.x = r; direction.x *= -1; } // top if (position.y < r) { position.y = r; direction.y *= -1; // randomize base top base1.y = random(height-100, height); base2.y = random(height-100, height); createGround(); } } void createGround() { // calculate length of base top baseLength = PVector.dist(base1, base2); // fill base top coordinate array coords = new PVector[ceil(baseLength)]; for (int i=0; i