I used constrain() function to constrain the location of the retinas inside the eye holes.
My source code is as below:
float mx, my; void setup() { size(1024, 768); smooth(); background(0, 220, 0); noStroke(); } void draw() { for (int i=100; i<800; i+=200) { for (int j=100; j<600; j+=200) { drawCell(i, j); } } } void drawCell(int i, int j) { float easing = 0.05; fill(230, 100, 30); ellipse(i, j, 200, 200); fill(0, 0, 255); ellipse(i, j, 200, 100); fill(0); if (abs(mouseX - i) > 0.1) { mx = mx + (mouseX - mx) * easing; } if (abs(mouseY - j) > 0.1) { my = my + (mouseY- my) * easing; } float mx1 = constrain(mx, i-50, i+50); float my1 = constrain(my, j-20, j+20); ellipse(mx1, my1, 50, 50); }

沒有留言:
張貼留言