WeirdGuy (Class)
A class is a blueprint for creating objects. Each WeirdGuy stores its own position, size, colors, and animation state. When you create a new WeirdGuy, the constructor runs once to set up all these properties.
class WeirdGuy {
constructor(x, y, size) {
this.x = x;
this.y = y;
this.size = size;
this.color1 = color(random(100, 255), random(50, 150), random(150, 255));
this.color2 = color(random(50, 150), random(150, 255), random(100, 255));
this.detail = random(5, 20);
this.offset = random(1000);
this.pulse = 0;
}
}
Line-by-line explanation (8 lines)
🔧 Subcomponents:
this.color1 = color(random(100, 255), random(50, 150), random(150, 255));
Creates two unique random colors for each character—the body outline and facial features—ensuring visual variety across all instances
this.detail = random(5, 20);
Determines how many segments make up the character's body outline, affecting how wiggly or angular the shape looks
this.x = x;- Stores the character's horizontal position on the canvas so display() knows where to draw it
this.y = y;- Stores the character's vertical position on the canvas
this.size = size;- Stores the character's scale factor; all body parts, eyes, and mouth scale proportionally to this value
this.color1 = color(random(100, 255), random(50, 150), random(150, 255));- Generates a random RGB color for the body outline; random() picks a value in each channel range to ensure bright but not white colors
this.color2 = color(random(50, 150), random(150, 255), random(100, 255));- Generates a second random color for the eyes' pupils and mouth; note the different ranges to create visual contrast with color1
this.detail = random(5, 20);- Sets how many segments form the body outline; more segments = smoother curves, fewer = pointier shapes
this.offset = random(1000);- Stores a unique random starting point for Perlin noise so each character's wiggly body outline looks different
this.pulse = 0;- Initializes the pulse animation value to 0; when a character is tapped, this becomes 0.05 and lerp() animates it back down