xxxxxxxxxx
104
let cellsize;
let mx, my;
let sunX, sunY, sunR;
let eye;
let imgs;
let indx = 0;
function preload() {
eye = loadImage("eye.png");
eyeup = loadImage("eye-up.png");
}
function setup() {
createCanvas(1000, 1000);
cellsize = width / 3;
stroke(20);
fill(color(255, 0, 255, 20));
mx = 0;
my = 0;
sunX = width / 2;
sunY = height / 2;
sunR = width / 2;
frameRate(30);
imgs = [eye, eyeup];
}
function draw() {
background(220);
stroke(20);
fill(color(255, 0, 255, 20));
line(cellsize, 0, cellsize, height);
line(width - cellsize, 0, width - cellsize, height);
line(0, cellsize, width, cellsize);
line(0, height - cellsize, width, height - cellsize);
noStroke();
rect(mx, my, cellsize, cellsize);
drawSun();
imageMode(CENTER);
}
function drawSun() {
noStroke();
let r = 245;
let g = 140;
let a = 20;
for (let rad = sunR * 2; rad > sunR / 2; rad -= 40) {
fill(color(r, g, 0, a));
circle(sunX, sunY, rad);
a += 10;
a = constrain(a, 0, 255);
r -= 1;
r = constrain(r, 0, 255);
g -= 10;
g = constrain(g, 0, 255);
}
image(imgs[indx], sunX, sunY);
}
function mouseMoved() {
if (mouseX < cellsize && mouseY < cellsize) {
mx = 0;
my = 0;
indx = 0;
} else if (mouseX < width - cellsize && mouseY < cellsize) {
mx = cellsize;
my = 0;
indx = 1;
} else if (mouseX < width && mouseY < cellsize) {
mx = width - cellsize;
my = 0;
indx = 0;
} else if (mouseX < cellsize && mouseY < height - cellsize) {
mx = 0;
my = cellsize;
indx = 0;
} else if (mouseX < width - cellsize && mouseY < height - cellsize) {
mx = cellsize;
my = cellsize;
indx = 0;
} else if (mouseX < width && mouseY < height - cellsize) {
mx = width - cellsize;
my = cellsize;
indx = 0;
} else if (mouseX < cellsize) {
mx = 0;
my = height - cellsize;
indx = 0;
} else if (mouseX < width - cellsize) {
mx = cellsize;
my = height - cellsize;
indx = 0;
} else if (mouseX < width) {
mx = width - cellsize;
my = height - cellsize;
indx = 0;
} else {
mx = cellsize;
my = cellsize;
indx = 0;
}
}