🔬 This loop layers gradientSteps circles blended between pink and blue to fake a smooth radial gradient. What happens if you drop gradientSteps to 2? What if you push it to 30?
const gradientSteps = 8;
for (let i = gradientSteps; i > 0; i--) {
const stepR = map(i, 0, gradientSteps, 0, radius);
const col = lerpColor(
color(255, 0, 140),
color(120, 220, 255),
i / gradientSteps
);
col.setAlpha(220);
fill(col);
circle(this.x, this.y, stepR * 2);
}
class Player {
constructor() {
this.x = width / 2;
this.y = height / 2;
this.radius = PLAYER_BASE_RADIUS;
this.trail = [];
this.maxTrailLength = 15;
}
update() {
// Move toward mouse smoothly
let targetX = mouseX;
let targetY = mouseY;
// Before any mouse move, mouseX/mouseY can be NaN in some contexts
if (isNaN(targetX) || isNaN(targetY)) {
targetX = width / 2;
targetY = height / 2;
}
let dx = targetX - this.x;
let dy = targetY - this.y;
const distToMouse = sqrt(dx * dx + dy * dy);
if (distToMouse > 1) {
const speed = min(PLAYER_MAX_SPEED, distToMouse * 0.15);
dx = (dx / distToMouse) * speed;
dy = (dy / distToMouse) * speed;
this.x += dx;
this.y += dy;
}
// Keep inside screen
this.x = constrain(this.x, this.radius, width - this.radius);
this.y = constrain(this.y, this.radius, height - this.radius);
// Store trail
this.trail.push({ x: this.x, y: this.y });
if (this.trail.length > this.maxTrailLength) {
this.trail.shift();
}
}
draw() {
// Draw trail
noStroke();
for (let i = 0; i < this.trail.length; i++) {
const t = this.trail[i];
const alpha = map(i, 0, this.trail.length - 1, 10, 120);
const r = map(i, 0, this.trail.length - 1, 4, this.radius);
fill(255, 80, 160, alpha);
circle(t.x, t.y, r * 2);
}
// Main orb
noStroke();
const pulse = sin(frameCount * 0.15) * 3;
const radius = this.radius + pulse;
// Outer glow
for (let i = 0; i < 3; i++) {
const glowR = radius + i * 6;
fill(255, 100, 200, 40 - i * 8);
circle(this.x, this.y, glowR * 2);
}
// Core
const gradientSteps = 8;
for (let i = gradientSteps; i > 0; i--) {
const stepR = map(i, 0, gradientSteps, 0, radius);
const col = lerpColor(
color(255, 0, 140),
color(120, 220, 255),
i / gradientSteps
);
col.setAlpha(220);
fill(col);
circle(this.x, this.y, stepR * 2);
}
// Small highlight
fill(255, 255, 255, 220);
circle(this.x - radius * 0.3, this.y - radius * 0.3, radius * 0.5);
}
}