Sketch 2026-03-06 17:30

This sketch creates an interactive clicking game where players rapidly click on a red target that appears randomly on the canvas. A mod menu accessible via an image button in the top-left corner lets players adjust game speed, pause/resume, add score, and activate god mode.

🧪 Try This!

Experiment with the code by making these changes:

  1. Make the game harder by shrinking the target — A smaller target is harder to click quickly—this teaches how visual changes affect gameplay difficulty
  2. Speed up the target by lowering game speed — Lower gameSpeed values make the target jump to a new location more frequently, forcing faster reflexes
  3. Award more points for each click — Change the score increment to make the game feel more rewarding and reach goal scores faster
  4. Make the menu button bigger and easier to find — A larger button is more discoverable—this teaches how UI affordances affect user experience
  5. Change the game background color — A different background color changes the contrast and makes the red target more or less visible
Prefer the full editor? Open it there →

📖 About This Sketch

This sketch is a fully playable clicking game: a red circle appears randomly on the canvas, you click it to score points, and it teleports to a new location. What makes it interesting is the hidden mod menu accessible via a small image button in the top-left corner—revealing a dark overlay with sliders and buttons that let you cheat. The code uses p5.js event handling (mousePressed), collision detection (dist), and DOM elements (createDiv, createButton, createSlider) to build a game with debugging tools baked in.

The sketch is organized into a preload() that loads an image, a setup() that initializes the game state and builds the mod menu UI, and a draw() function that switches between game mode and menu mode. You will learn how to detect mouse clicks on specific regions, how to create interactive HTML elements that float above your canvas, and how game state variables like gamePaused and modMenuOpen control what the player sees and does.

⚙️ How It Works

  1. When the sketch loads, preload() fetches an image file, and setup() creates a full-screen canvas, initializes the game score to 0, and builds an invisible mod menu containing a slider, four buttons, and styled text.
  2. Every frame, draw() checks if the mod menu is open. If it is, the canvas fills with the image. If not, the background clears to gray and the score displays in the top-left.
  3. If the game is not paused, a red circular target appears at a random position on the canvas. After gameSpeed frames (default 60), the target jumps to a new random location.
  4. The small image button in the top-left corner is always drawn with a border. Clicking it toggles the mod menu visibility and changes the border color from black to white.
  5. If the player clicks on the red target while the game is unpaused, the game calculates the distance from the click to the target center using dist(). If the distance is less than the target radius, the score increases by 10 and the target vanishes, ready to reappear after gameSpeed frames.
  6. The mod menu contains four interactive controls: a slider that adjusts gameSpeed, a button to pause/resume (toggling both gamePaused and the button label), a button to add 100 points, and a god mode button that sets the score to 1000 and closes the menu.

🎓 Concepts You'll Learn

Event handling (mousePressed)Collision detection (dist function)Game state managementDOM manipulation (createDiv, createButton, createSlider)Conditional rendering based on stateWindow resizing

📝 Code Breakdown

preload()

preload() runs before setup() and is the right place to load images, sounds, or other files. p5.js waits for all preload tasks to finish before moving to setup().

function preload() {
  // Load your uploaded image
  // The name 'images (19).jpeg' is taken from your project files list.
  // Ensure this file is present in your project.
  img = loadImage('images (19).jpeg');
}
Line-by-line explanation (1 lines)
img = loadImage('images (19).jpeg');
Loads the image file from your project and stores it in the img variable so it's ready to use in setup() and draw()

setup()

setup() runs once at the start. It creates your canvas, initializes all variables, and builds any interactive elements. Think of it as the 'game boot sequence.'

🔬 The random() function ensures the target spawns within safe bounds. What happens if you remove the clickAreaSize + offset and just use random(targetSize, width - targetSize)? Where might the target hide?

  targetX = random(clickAreaSize + targetSize, width - targetSize);
  targetY = random(clickAreaSize + targetSize, height - targetSize);
function setup() {
  createCanvas(windowWidth, windowHeight);
  // Tip: Use windowWidth/windowHeight for responsive canvas

  gameScore = 0;
  modMenuOpen = false;
  gamePaused = false; // Initialize game as unpaused
  
  // Initialize target position
  // Ensure target doesn't spawn under the mod menu trigger image
  targetX = random(clickAreaSize + targetSize, width - targetSize);
  targetY = random(clickAreaSize + targetSize, height - targetSize);

  // --- MOD MENU UI ---
  // Create a div element for the mod menu
  // p5.createDiv automatically assigns an ID based on the variable name (e.g., "modMenuDiv")
  modMenuDiv = createDiv('<h2>Mod Menu</h2>');
  modMenuDiv.position(50, 50); // Position the menu
  modMenuDiv.style('z-index', '1000'); // Ensure it's on top of the canvas
  modMenuDiv.style('display', 'none'); // Hidden initially

  // Add game speed slider
  createP('Game Speed: (Higher value = Slower game)').parent(modMenuDiv);
  speedSlider = createSlider(10, 120, gameSpeed, 10); // Min, Max, Initial, Step
  speedSlider.parent(modMenuDiv);
  speedSlider.input(updateGameSpeed); // Call updateGameSpeed when slider changes

  // Add "Pause/Resume Game" button
  pauseButton = createButton(gamePaused ? 'Resume Game' : 'Pause Game');
  pauseButton.parent(modMenuDiv);
  pauseButton.mousePressed(toggleGamePause); // Call toggleGamePause when button is pressed

  // Add "Add Score" button
  scoreButton = createButton('Add 100 Score');
  scoreButton.parent(modMenuDiv);
  scoreButton.mousePressed(addScore); // Call addScore when button is pressed

  // Add "God Mode" button
  godModeButton = createButton('God Mode (Set Score to 1000)');
  godModeButton.parent(modMenuDiv);
  godModeButton.mousePressed(activateGodMode); // Call activateGodMode when button is pressed
  // --- END MOD MENU UI ---
}
Line-by-line explanation (14 lines)

🔧 Subcomponents:

calculation Canvas setup createCanvas(windowWidth, windowHeight);

Creates a full-screen canvas that matches the browser window size

calculation Game state initialization gameScore = 0; modMenuOpen = false; gamePaused = false;

Resets all game state variables to their starting values

calculation Initial target spawn targetX = random(clickAreaSize + targetSize, width - targetSize); targetY = random(clickAreaSize + targetSize, height - targetSize);

Places the target at a random location, avoiding the top-left corner where the menu button is

calculation Mod menu UI construction modMenuDiv = createDiv('<h2>Mod Menu</h2>'); modMenuDiv.position(50, 50); modMenuDiv.style('z-index', '1000'); modMenuDiv.style('display', 'none');

Creates an HTML div element, positions it, layers it above the canvas, and hides it initially

createCanvas(windowWidth, windowHeight);
Creates a canvas that fills the entire browser window—responsive design so it works on any screen size
gameScore = 0;
Resets the score to 0 when the sketch starts, ensuring a fresh game
modMenuOpen = false;
Sets the menu as closed initially, so players see only the game, not the controls
gamePaused = false; // Initialize game as unpaused
The game is running by default—targets will spawn and move unless the player pauses it
targetX = random(clickAreaSize + targetSize, width - targetSize);
Picks a random x position for the target, ensuring it doesn't spawn hidden under the menu button or off-screen
targetY = random(clickAreaSize + targetSize, height - targetSize);
Picks a random y position for the target with the same safety margins
modMenuDiv = createDiv('<h2>Mod Menu</h2>');
Creates an HTML div element and puts a heading inside it—this becomes the container for all mod menu controls
modMenuDiv.position(50, 50);
Places the mod menu at pixel coordinates (50, 50) on the page
modMenuDiv.style('z-index', '1000');
Ensures the menu floats on top of the canvas (higher z-index = on top)
modMenuDiv.style('display', 'none');
Hides the menu initially by setting its CSS display to none—it appears only when the button is clicked
speedSlider = createSlider(10, 120, gameSpeed, 10);
Creates a slider with min value 10, max value 120, starting value gameSpeed, and step size 10
speedSlider.input(updateGameSpeed);
Connects the slider to the updateGameSpeed function so the game speed changes instantly as you drag
pauseButton = createButton(gamePaused ? 'Resume Game' : 'Pause Game');
Creates a button with text that depends on the current game state: 'Resume Game' if paused, 'Pause Game' if running
pauseButton.mousePressed(toggleGamePause);
Wires the pause button to call toggleGamePause whenever the player clicks it

draw()

draw() runs 60 times per second (by default). It's where you update animations, redraw everything on screen, and check game logic. The order matters: clear the background first, then draw the game, then draw UI elements on top.

🔬 This code moves the target every gameSpeed frames. What happens if you change > to >= or to a smaller number like gameSpeed / 2? Will the target move more or less often?

      if (frameCount - lastTargetTime > gameSpeed) {
        targetX = random(clickAreaSize + targetSize, width - targetSize);
        targetY = random(clickAreaSize + targetSize, height - targetSize);
        lastTargetTime = frameCount;
      }
function draw() {
  // 1. Draw the main background or zoomed image based on modMenuOpen state
  if (modMenuOpen) {
    // If mod menu is open, zoom in the image to fill the screen
    image(img, 0, 0, width, height);
  } else {
    // Otherwise, draw the default background for the game
    background(220);

    // 2. Game Logic (only if mod menu is closed)
    if (!gamePaused) { // Game updates only if mod menu is not open AND game is not paused
      // Display score
      textSize(24);
      fill(0);
      textAlign(LEFT, TOP);
      text('Score: ' + gameScore, 200, 20);

      // Make target appear/move randomly
      if (frameCount - lastTargetTime > gameSpeed) {
        targetX = random(clickAreaSize + targetSize, width - targetSize);
        targetY = random(clickAreaSize + targetSize, height - targetSize);
        lastTargetTime = frameCount;
      }
    } else {
      // If game is paused but mod menu is closed, display paused indicator
      textSize(24);
      fill(0);
      textAlign(LEFT, TOP);
      text('Score: ' + gameScore, 200, 20);
      textSize(36);
      fill(255, 0, 0);
      textAlign(CENTER, CENTER);
      text('GAME PAUSED', width / 2, height / 2);
    }

    // Draw target (red circle) - always draw, even if paused, but it won't move
    fill(255, 0, 0);
    noStroke();
    ellipse(targetX, targetY, targetSize, targetSize);
  }

  // 3. Draw the small mod menu trigger image (always visible and clickable)
  // Draw your uploaded image in the top-left corner
  image(img, 10, 10, clickAreaSize, clickAreaSize);

  // Draw a border around the image to make it look like a button
  noFill();
  stroke(modMenuOpen ? 255 : 0); // White border when menu is open, black otherwise
  strokeWeight(2);
  rect(10, 10, clickAreaSize, clickAreaSize);
}
Line-by-line explanation (14 lines)

🔧 Subcomponents:

conditional Pause state check if (!gamePaused) { // Game updates } else { // Paused display }

Decides whether to update the target position and show 'GAME PAUSED' text based on pause state

conditional Target respawn timer if (frameCount - lastTargetTime > gameSpeed) { targetX = random(clickAreaSize + targetSize, width - targetSize); targetY = random(clickAreaSize + targetSize, height - targetSize); lastTargetTime = frameCount; }

Moves the target to a new random location every gameSpeed frames (e.g., every 60 frames at 60 fps = once per second)

calculation Menu button border color stroke(modMenuOpen ? 255 : 0); // White border when menu is open, black otherwise

Changes the menu button border from black (closed) to white (open) to give visual feedback that it's active

if (modMenuOpen) {
Checks whether the mod menu is currently visible—controls what mode the game is in
image(img, 0, 0, width, height);
If the menu is open, fills the entire canvas with the loaded image, essentially replacing the game view
background(220);
If the menu is closed, clears the canvas with a light gray color (220 on a 0–255 grayscale), erasing the previous frame
if (!gamePaused) { // Game updates only if mod menu is not open AND game is not paused
Checks if the game is unpaused—only then do we update the target position and show the active score
textSize(24);
Sets the font size to 24 pixels for the score display
text('Score: ' + gameScore, 200, 20);
Draws the current score as text starting at pixel position (200, 20), updating every frame to show changes instantly
if (frameCount - lastTargetTime > gameSpeed) {
Compares how many frames have passed since the last target spawn (frameCount - lastTargetTime) to the gameSpeed threshold—when it exceeds gameSpeed, the target jumps
targetX = random(clickAreaSize + targetSize, width - targetSize);
Picks a new random x position for the target each time it respawns
lastTargetTime = frameCount;
Records the current frame number as the 'time' of this respawn, resetting the countdown timer for the next respawn
text('GAME PAUSED', width / 2, height / 2);
If the game is paused, displays 'GAME PAUSED' in large red text centered on the canvas
ellipse(targetX, targetY, targetSize, targetSize);
Draws a red circle (the clickable target) at the current targetX and targetY position with a diameter of targetSize
image(img, 10, 10, clickAreaSize, clickAreaSize);
Draws the small image in the top-left corner at position (10, 10) with width and height of clickAreaSize—this is the menu button
stroke(modMenuOpen ? 255 : 0); // White border when menu is open, black otherwise
Sets the stroke color to white (255) if the menu is open, or black (0) if it's closed, creating visual feedback on the button
rect(10, 10, clickAreaSize, clickAreaSize);
Draws a rectangle around the menu button to make it look like a clickable button

mousePressed()

mousePressed() is called automatically by p5.js every time the player clicks the mouse. It's where you detect user interactions like clicks on buttons or game objects. The return statement exits the function early, preventing unwanted side effects.

function mousePressed() {
  // Check if the mod menu trigger image was clicked
  if (mouseX > 10 && mouseX < 10 + clickAreaSize && mouseY > 10 && mouseY < 10 + clickAreaSize) {
    toggleModMenu();
    return; // Don't proceed with game clicks if menu button was pressed
  }

  // --- GAME CLICKS ---
  // Only allow game clicks if mod menu is not open AND game is not paused
  if (!modMenuOpen && !gamePaused) { 
    let d = dist(mouseX, mouseY, targetX, targetY);
    if (d < targetSize / 2) {
      gameScore += 10;
      // Make target disappear instantly and reappear after gameSpeed
      lastTargetTime = frameCount - gameSpeed;
    }
  }
  // --- END GAME CLICKS ---
}
Line-by-line explanation (8 lines)

🔧 Subcomponents:

conditional Game state gate if (!modMenuOpen && !gamePaused) {

Ensures game clicks are ignored when the menu is open or the game is paused

conditional Target collision detection let d = dist(mouseX, mouseY, targetX, targetY); if (d < targetSize / 2) {

Calculates the distance from the click to the target center and checks if it's inside the target radius

if (mouseX > 10 && mouseX < 10 + clickAreaSize && mouseY > 10 && mouseY < 10 + clickAreaSize) {
Checks if the mouse click happened inside a rectangular area: x between 10 and 10+clickAreaSize, y between 10 and 10+clickAreaSize. This is where the menu button image is drawn
toggleModMenu();
If the click hit the menu button, toggle the menu open/closed
return; // Don't proceed with game clicks if menu button was pressed
Stops the function here—prevents the code below from running, so clicking the menu button doesn't also click the game target
if (!modMenuOpen && !gamePaused) {
Only proceeds with game click logic if BOTH conditions are true: the menu is closed AND the game is not paused. The ! means 'NOT'
let d = dist(mouseX, mouseY, targetX, targetY);
Calculates the straight-line distance in pixels from the click point to the center of the target using the dist() function
if (d < targetSize / 2) {
If the distance is less than the target's radius (half its diameter), the click hit the target
gameScore += 10;
Adds 10 points to the score when the target is clicked
lastTargetTime = frameCount - gameSpeed;
Sets lastTargetTime to (frameCount - gameSpeed), which tricks the spawn logic into respawning the target instantly on the next frame—the target disappears and immediately reappears

toggleModMenu()

This function demonstrates the toggle pattern: a boolean variable tracks state, and the ! operator flips it. It's one of the most useful patterns in coding—used everywhere from light switches to visibility toggles.

function toggleModMenu() {
  modMenuOpen = !modMenuOpen;
  if (modMenuOpen) {
    modMenuDiv.show(); // Show the mod menu
    // When mod menu opens, implicitly pause the game to prevent accidental clicks
    // We don't change gamePaused here, just the draw/mousePressed logic handles it
  } else {
    modMenuDiv.hide(); // Hide the mod menu
  }
}
Line-by-line explanation (5 lines)

🔧 Subcomponents:

calculation Toggle menu state modMenuOpen = !modMenuOpen;

Flips modMenuOpen from true to false or false to true, switching the menu visibility

conditional Menu visibility if (modMenuOpen) { modMenuDiv.show(); } else { modMenuDiv.hide(); }

Shows the menu div if open, hides it if closed

modMenuOpen = !modMenuOpen;
The ! operator flips the boolean: if modMenuOpen is true, it becomes false; if false, it becomes true. This is how you toggle a switch
if (modMenuOpen) {
Checks if the menu is now open (after the flip)
modMenuDiv.show(); // Show the mod menu
The show() method displays the hidden div on screen by changing its CSS display property back to 'block'
} else {
If the menu is closed...
modMenuDiv.hide(); // Hide the mod menu
The hide() method hides the div by setting its CSS display to 'none', making it invisible and unclickable

toggleGamePause()

This function pairs a state flip (!gamePaused) with immediate UI feedback (updating the button text). This is a best practice: when state changes, update the visual representation instantly so the player knows what happened.

function toggleGamePause() {
  gamePaused = !gamePaused;
  pauseButton.html(gamePaused ? 'Resume Game' : 'Pause Game'); // Update button text
  console.log("Game Paused:", gamePaused);
}
Line-by-line explanation (3 lines)

🔧 Subcomponents:

calculation Pause state flip gamePaused = !gamePaused;

Flips the pause state from paused to unpaused or vice versa

calculation Dynamic button text pauseButton.html(gamePaused ? 'Resume Game' : 'Pause Game');

Updates the pause button's label to reflect the current game state

gamePaused = !gamePaused;
Flips the pause state—true becomes false (unpaused), false becomes true (paused)
pauseButton.html(gamePaused ? 'Resume Game' : 'Pause Game');
Uses the ternary operator (? :) to set the button text: if paused, show 'Resume Game'; if unpaused, show 'Pause Game'. This updates the button label immediately
console.log("Game Paused:", gamePaused);
Prints a message to the browser console for debugging, confirming the new pause state

updateGameSpeed()

This is a callback function—p5.js calls it automatically when the slider moves. You can hook any interaction (slider, button, text input) to a callback function this way using .input(), .mousePressed(), .change(), etc.

function updateGameSpeed() {
  gameSpeed = speedSlider.value();
}
Line-by-line explanation (1 lines)
gameSpeed = speedSlider.value();
Reads the current value from the speed slider and stores it in gameSpeed. p5.js calls this function automatically whenever the slider is moved

addScore()

This function demonstrates a mod menu feature: a button that cheats for you. In many games, debug or cheat options let you skip ahead or test mechanics faster.

function addScore() {
  gameScore += 100;
}
Line-by-line explanation (1 lines)
gameScore += 100;
Adds 100 points to the score instantly. This is the function called when the 'Add 100 Score' button is pressed

activateGodMode()

This function demonstrates a cheat code pattern: pressing a button triggers a major game state change (instant win). Game developers often include these for testing, streaming, or fun.

function activateGodMode() {
  gameScore = 1000; // Set score to a high value
  console.log("God Mode Activated! Score set to 1000.");
  toggleModMenu(); // Close menu after activating
}
Line-by-line explanation (3 lines)

🔧 Subcomponents:

calculation God mode score boost gameScore = 1000;

Instantly sets the score to 1000 instead of adding incrementally

gameScore = 1000; // Set score to a high value
Sets the score directly to 1000, bypassing the normal clicking gameplay—a classic cheat code
console.log("God Mode Activated! Score set to 1000.");
Prints a message to the browser console confirming the mode is activated
toggleModMenu(); // Close menu after activating
Automatically closes the mod menu after activating god mode, returning the player to the game view with the new high score

windowResized()

windowResized() is called automatically by p5.js whenever the browser window is resized. Use it to adapt your canvas and UI elements to the new screen size.

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
  // Re-position mod menu if necessary, or make it responsive
  modMenuDiv.position(50, 50); // Keep it fixed for simplicity
}
Line-by-line explanation (2 lines)
resizeCanvas(windowWidth, windowHeight);
Resizes the p5.js canvas to match the new browser window size when the window is resized
modMenuDiv.position(50, 50); // Keep it fixed for simplicity
Ensures the mod menu stays in the top-left area even after the window is resized

📦 Key Variables

gameScore number

Tracks the player's current score—incremented when the target is clicked or cheat buttons are pressed

let gameScore = 0;
modMenuOpen boolean

Stores whether the mod menu is currently visible (true) or hidden (false)—controls the game/menu display mode

let modMenuOpen = false;
gamePaused boolean

Stores whether the game is paused (true) or running (false)—controls whether the target spawns and moves

let gamePaused = false;
targetX number

The x (horizontal) pixel position of the red target circle on the canvas

let targetX = 200;
targetY number

The y (vertical) pixel position of the red target circle on the canvas

let targetY = 300;
targetSize number

The diameter of the red target circle in pixels—determines how big a target is to click

let targetSize = 40;
img p5.Image

Stores the loaded image used for the menu button and background overlay

let img; // Assigned in preload()
modMenuDiv p5.Renderer (HTML element)

The HTML div element that contains all mod menu controls—shown/hidden by toggleModMenu()

let modMenuDiv; // Created in setup()
speedSlider p5.Slider

The range slider in the mod menu that controls gameSpeed—allows players to adjust how fast the game is

let speedSlider; // Created in setup()
scoreButton p5.Renderer (HTML element)

The 'Add 100 Score' button in the mod menu that calls addScore() when clicked

let scoreButton; // Created in setup()
godModeButton p5.Renderer (HTML element)

The 'God Mode' button in the mod menu that calls activateGodMode() when clicked

let godModeButton; // Created in setup()
pauseButton p5.Renderer (HTML element)

The 'Pause/Resume Game' button in the mod menu that toggles game pause state

let pauseButton; // Created in setup()
gameSpeed number

The number of frames that must pass before the target respawns at a new location—higher values = slower game

let gameSpeed = 60;
lastTargetTime number

Stores the frameCount value when the target last spawned—used to calculate the delay until the next spawn

let lastTargetTime = 0;
clickAreaSize number

The width and height of the square menu button in the top-left corner

let clickAreaSize = 50;

🔧 Potential Improvements (6)

Here are some ways this code could be enhanced:

BUG mousePressed() - target hit detection

The collision check uses targetSize / 2 (radius), but ellipse() draws using the full diameter. If the target visually appears smaller than expected, the hit zone won't match visually

💡 Verify that the hit detection radius matches the visual radius of the drawn ellipse. Use targetSize / 2 consistently, or switch to drawing with radius mode: ellipseMode(RADIUS).

BUG draw() - target respawn logic

When a target is clicked, lastTargetTime is set to (frameCount - gameSpeed), which will respawn it on the NEXT frame. But if the player's click happens on frame 59 and gameSpeed is 60, the target will instantly respawn—feels jarring

💡 Add a small delay before respawning the target. For example, set lastTargetTime = frameCount to wait a full gameSpeed duration before the next spawn.

STYLE setup() - mod menu creation

The mod menu HTML structure is built imperatively with multiple parent() calls. It works, but it's hard to see the full menu structure at a glance

💡 Build the mod menu HTML as a single string and pass it to createDiv(), or organize the button/slider creation into a separate function for clarity.

FEATURE draw() - game over condition

There's no win/loss condition or end state. The game goes on forever or until the player manually stops

💡 Add a score threshold (e.g., 500 points to win) and display a 'You Win!' message. Or add a timer and create a survival mode.

PERFORMANCE draw()

The score text is recreated and positioned every frame using text(). For static UI, this is minor, but consider moving score display to a fixed position

💡 Use textAlign(LEFT, TOP) and position the text once, or cache frequently-updated elements in variables to reduce redundant calculations.

STYLE draw() - boundary checking

Target spawn coordinates use clickAreaSize + targetSize to avoid the menu button, but the menu button size (clickAreaSize) and spawn area are hardcoded. If clickAreaSize changes, the spawn logic might fail

💡 Define a safe spawn zone variable or function that dynamically accounts for UI elements. This makes the code more maintainable if UI elements change.

🔄 Code Flow

Code flow showing preload, setup, draw, mousepressed, togglemodmenu, togglegamepause, updategamespeed, addscore, activategodmode, windowresized

💡 Click on function names in the diagram to jump to their code

graph TD start[Start] --> setup[setup] setup --> canvas-creation[Canvas Creation] setup --> variable-initialization[Variable Initialization] setup --> target-position[Target Position] setup --> mod-menu-creation[Mod Menu Creation] setup --> draw[draw loop] click setup href "#fn-setup" click canvas-creation href "#sub-canvas-creation" click variable-initialization href "#sub-variable-initialization" click target-position href "#sub-target-position" click mod-menu-creation href "#sub-mod-menu-creation" draw --> menu-mode-switch[Menu Mode Switch] draw --> game-state-conditional[Game State Conditional] draw --> target-spawn-logic[Target Spawn Logic] click draw href "#fn-draw" click menu-mode-switch href "#sub-menu-mode-switch" click game-state-conditional href "#sub-game-state-conditional" click target-spawn-logic href "#sub-target-spawn-logic" game-state-conditional -->|if gamePaused| target-position game-state-conditional -->|else| target-spawn-logic target-spawn-logic --> target-position target-spawn-logic --> draw mousepressed[mousePressed] --> menu-button-hit[Menu Button Hit] mousepressed --> game-click-guard[Game Click Guard] mousepressed --> target-distance-check[Target Distance Check] click mousepressed href "#fn-mousepressed" click menu-button-hit href "#sub-menu-button-hit" click game-click-guard href "#sub-game-click-guard" click target-distance-check href "#sub-target-distance-check" menu-button-hit -->|if hit| state-flip[State Flip] menu-button-hit -->|else| game-click-guard game-click-guard -->|if not paused and menu closed| target-distance-check game-click-guard -->|else| draw target-distance-check -->|if hit| addscore[Add Score] target-distance-check -->|else| draw addscore --> draw togglemodmenu[toggleModMenu] --> state-flip click togglemodmenu href "#fn-togglemodmenu" togglegamepause[toggleGamePause] --> pause-toggle[Pause Toggle] togglegamepause --> button-label-update[Button Label Update] click togglegamepause href "#fn-togglegamepause" pause-toggle --> draw button-label-update --> draw activategodmode[Activate God Mode] --> score-set[Score Set] click activategodmode href "#fn-activategodmode" windowresized[windowResized] --> canvas-creation click windowresized href "#fn-windowresized"

❓ Frequently Asked Questions

What visual elements does the p5.js sketch Sketch 2026-03-06 17:30 generate?

This sketch creates an interactive canvas that displays a target image at random positions, challenging users to click on it while managing game speed and score.

How can users interact with the Sketch 2026-03-06 17:30?

Users can interact by clicking on the target image, adjusting the game speed with a slider, and using buttons to toggle game pause and enable features like 'God Mode'.

What creative coding concepts are showcased in this p5.js sketch?

The sketch demonstrates concepts of interactivity, user interface design, and game mechanics, including scoring and dynamic target generation.

Preview

Sketch 2026-03-06 17:30 - p5.js creative coding sketch preview
Sketch Preview
Code flow diagram showing the structure of Sketch 2026-03-06 17:30 - Code flow showing preload, setup, draw, mousepressed, togglemodmenu, togglegamepause, updategamespeed, addscore, activategodmode, windowresized
Code Flow Diagram