🔬 This loop traces a distorted circle by plotting ~63 vertices around the center. What happens if you change 'i += 0.1' to 'i += 0.05'—doubling the number of vertices and making the blob outline smoother?
for (let i = 0; i < TWO_PI; i += 0.1) {
let r = map(noise(cos(i) * 0.5, sin(i) * 0.5, frameCount * 0.01), 0, 1, width * 0.1, width * 0.3);
let x = width / 2 + r * cos(i);
let y = height / 2 + r * sin(i);
vertex(x, y);
}
🔬 These lines make the pupil follow your mouse by mapping your position to an offset. What happens if you change the second 'mouseX' to 'width - mouseX'—inverting the pupil tracking?
let pupilX = map(mouseX, 0, width, -eye.size * eye.pupilSize * 0.5, eye.size * eye.pupilSize * 0.5);
let pupilY = map(mouseY, 0, height, -eye.size * eye.pupilSize * 0.5, eye.size * eye.pupilSize * 0.5);
ellipse(eye.x + pupilX, eye.y + pupilY, eye.size * eye.pupilSize);
function draw() {
background(20); // Very dark background
// --- Draw the scary entity's body ---
noStroke();
fill(entityColor);
beginShape();
// Use noise() to create a distorted, organic blob shape
for (let i = 0; i < TWO_PI; i += 0.1) {
let r = map(noise(cos(i) * 0.5, sin(i) * 0.5, frameCount * 0.01), 0, 1, width * 0.1, width * 0.3);
let x = width / 2 + r * cos(i);
let y = height / 2 + r * sin(i);
vertex(x, y);
}
endShape(CLOSE);
// --- Draw the glowing eyes that follow the mouse ---
for (let eye of eyes) {
fill(eye.eyeColor);
ellipse(eye.x, eye.y, eye.size); // The main glowing part of the eye
fill(eye.pupilColor);
// Calculate pupil position based on mouseX and mouseY
let pupilX = map(mouseX, 0, width, -eye.size * eye.pupilSize * 0.5, eye.size * eye.pupilSize * 0.5);
let pupilY = map(mouseY, 0, height, -eye.size * eye.pupilSize * 0.5, eye.size * eye.pupilSize * 0.5);
ellipse(eye.x + pupilX, eye.y + pupilY, eye.size * eye.pupilSize); // The pupil
}
// --- "Coming out of its game" effects ---
// 1. Draw shapes partially outside the canvas boundaries
// These semi-transparent red bars appear at the edges, suggesting something lurking beyond.
fill(100, 0, 0, 150); // Semi-transparent red
rect(-50, height / 3, 100, height / 3); // Left edge
rect(width - 50, height / 3, 100, height / 3); // Right edge
// 2. Manipulate DOM elements (e.g., change body background for a glitchy effect)
// This uses p5.js's select() function to access the HTML body and change its style.
if (frameCount % 60 === 0) { // Every second (60 frames)
let r = random(10, 50);
let g = random(0, 10);
let b = random(0, 10);
select('body').style('background-color', `rgb(${r}, ${g}, ${b})`); // Glitchy dark background
}
// The cursor is already hidden via style.css, which is another "out of game" effect.
}