Wednesday, 26 September 2012

Googly Eyes

The following is a code that I found and have addapted slightly, I plan to incorporate something similar into my final code so that many eyeballs can have moving pupils.

float x, y;
float easing = .5;
PVector circle = new PVector(250, 250);
int radius = 200;

void setup() {
  size(500, 500);
  x = y = width/2;
  noStroke();
  smooth();
}

void draw () {
  background(51);
  fill(255);
  ellipse(circle.x, circle.y, radius+50, radius+50);

  PVector m = new PVector(mouseX, mouseY);
  if (dist(m.x, m.y, circle.x, circle.y) > radius/2) {
    m.sub(circle);
    m.normalize();
    m.mult(radius/2);
    m.add(circle);
  }

  fill(0, 0, 255);
  ellipse(m.x, m.y, 0, 0);

  x = x + (m.x - x) * easing;
  y = y + (m.y - y) * easing;

  fill(0, 0, 0); 
  ellipse(x, y, 60, 60);
}



Some static images of the program:



No comments:

Post a Comment