ArrayList list = new ArrayList();
color[] swatch = {color(109, 223, 51), color(204, 255, 0), color(255, 0, 255), color(229, 75, 41)};
void setup() {
size(500, 500);
//Cria uma lista de olhos que não se sobrepõem + Olho central de 50 de raio
list.add(new PVector(width/2, height/2, 50));
for (int i = int(random(40, 70)); i <= width-40; i+=15) {
for (int j = 40; j <= height-40; j+=15 ) {
boolean test = true;
int r = int(random(15, 40));
for (PVector circle : list) {
if (dis(circle.x, circle.y, i, j) < r + circle.z + 30) {
test = false;
}
}
if (test) {
list.add(new PVector(i, j, r));
}
}
}
}
void draw() {
background(0);
//desenha todos os olhos da lista
for (PVector circle : list) {
olho(circle.x, circle.y, circle.z);
}
}
void olho(float x, float y, float r) {
//A parte que interessa: O cálculo dos catetos e da tangente
float w = x - mouseX;
float h = y - mouseY;
float t = atan(h/w);
if (w >= 0) t += PI;
stroke(0);
//Escolhe uma cor para a esclera dentro da lista inicial e a desenha
fill(swatch[int(noise(x,y)*swatch.length)]);
strokeWeight(5);
ellipse(x, y, 2*r, 2*r);
fill(0);
//Limita a íris negra dentro da órbita ocular
float iX, iY = 0;
if (dis(x, y, mouseX, mouseY) < r*0.7) {
iX = mouseX;
iY = mouseY;
} else {
iX = x+cos(t)*0.7*r;
iY = y+sin(t)*0.7*r;
}
//Desenha íris e um reflexo pra ficar bonitinho
noStroke();
ellipse(iX, iY, r/2, r/2);
fill(255);
ellipse(iX+r/12, iY-r/12, r/6, r/6);
//Desenha pálpebras pra dar um ar de mistério (Excepto pelo olho central)
if (r != 50){
fill(0);
//Pálpebra de cima
beginShape();
vertex(x-r, y);
bezierVertex(x-r, y-r*1.27, x+r, y-r*1.27, x+r, y);
bezierVertex(x+r, y-r*constrain(map(dis(x, y, mouseX, mouseY), r, 3*r, 1.27, 0), 0, 1.27),
x-r, y-r*constrain(map(dis(x, y, mouseX, mouseY), r, 3*r, 1.27, 0), 0, 1.27), x-r, y);
endShape();
//Pálpebra de baixo
beginShape();
vertex(x-r, y);
bezierVertex(x-r, y+r*1.27, x+r, y+r*1.27, x+r, y);
bezierVertex(x+r, y+r*constrain(map(dis(x, y, mouseX, mouseY), r, 3*r, 1.27, 0), 0, 1.27),
x-r, y+r*constrain(map(dis(x, y, mouseX, mouseY), r, 3*r, 1.27, 0), 0, 1.27), x-r, y);
endShape();
}
}
//Calcula distâncias
float dis(float x1, float y1, float x2, float y2) {
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
Nenhum comentário:
Postar um comentário
Pode falar, eu não mordo... Pelo menos não através da internet
Nenhum comentário:
Postar um comentário
Pode falar, eu não mordo... Pelo menos não através da internet