xxxxxxxxxx
81
/*
'All Eyes on You' by KJ Ha
Link to blog: https://www.kyungjooha.com/post/mfa-final
- Move your mouse around the screen.
- Press the mouse button to see the hidden part!
*/
let a = 255;
let count;
let mods = [];
let spacing = 110;
function setup() {
createCanvas(6 * spacing, 5 * spacing);
var index = 0;
for (var xs = 0; xs < width / 80; xs++) {
for (var ys = 0; ys < height / 80; ys++) {
mods[index++] = new Module(int(xs) * spacing, int(ys) * spacing);
}
}
}
function draw() {
background(a);
for (var i = 0; i <= 60; i++) {
mods[i].update();
mods[i].eye();
mods[i].eyeball();
}
}
function Module(_x, _y) {
this.x = _x;
this.y = _y;
this.angle = 0;
this.xp = 14;
this.yp = 52;
this.h = 25;
}
Module.prototype.update = function() {
this.angle = atan2(mouseY - this.y, mouseX - this.x);
}
Module.prototype.eyeball = function() {
push();
translate(this.x + 55, this.y + 40);
rotate(this.angle);
fill(0);
ellipse(7, 0, 19);
pop();
}
Module.prototype.eye = function() {
push();
translate(this.x + 25, this.y + 20);
strokeWeight(1);
stroke(a);
var eyet = map(height - mouseY, 0, height, this.h, 100);
var eyeb = map(height - mouseY, 0, height, this.h, -40);
fill(255);
// fill(0);
curve(this.xp, eyet, this.xp, this.h, this.yp, this.h, this.yp, eyet);
curve(this.xp, eyeb, this.xp, this.h, this.yp, this.h, this.yp, eyeb);
pop();
}
// When mouse is pressed, change background color to brightness 0
function mousePressed() {
if (a === 255) {
a = 0;
} else {
a = 255;
}
}