Skip to content
microsim-add-icons logo

MicroSim Add Icons

microsim-add-icons

Add clickable Creative Commons license and fullscreen icons to an existing MicroSim's control region. Use this skill when enhancing a MicroSim with navigation icons in the lower right corner. Adds approximately 40 lines of code for icon functionality.

SKILL.md

Full skill instructions

MicroSim Add Icons

Overview

Add clickable Creative Commons license and fullscreen navigation icons to the control region of an existing p5.js MicroSim. The icons appear in the lower right corner and use distance-based click detection. This adds approximately 40 lines of code to the simulation.

When to Use This Skill

Use this skill when:

  • Adding license information access to a MicroSim
  • Enabling fullscreen mode via an icon
  • Enhancing a MicroSim with clickable UI elements
  • Following the icons demo pattern from the MicroSims repository

Workflow

Step 1: Identify the Target MicroSim

Ask the user which MicroSim JavaScript file to modify, or identify it from context. The file should be a p5.js MicroSim following the standard pattern with:

  • Global variables section
  • setup() function
  • draw() function
  • windowResized() function

Step 2: Read the Existing File

Read the entire JavaScript file to understand its structure and identify where to add the icon code.

Step 3: Add Icon Variables

Add the following variables to the global variables section, after the existing slider variables:

// Icon variables
let iconSize = 24;
let iconMargin = 5;
let ccIconX, ccIconY;  // Creative Commons icon position
let fsIconX, fsIconY;  // Fullscreen icon position

Also add or update the sliderRightMargin variable:

let sliderRightMargin = 70;

This reserves space on the right side of sliders for the icons.

Step 4: Add drawIcons() Function

Add the complete drawIcons() function after the draw() function:

function drawIcons() {
  // Calculate icon positions (right to left)
  fsIconX = canvasWidth - iconMargin - iconSize/​2;
  fsIconY = drawHeight + controlHeight/​2;

  ccIconX = fsIconX - iconSize - iconMargin;
  ccIconY = fsIconY;

  // Draw Creative Commons icon
  fill('black');
  noStroke();
  textAlign(CENTER, CENTER);
  textSize(20);
  text('ⓒ', ccIconX, ccIconY);
  // Draw Fullscreen icon
  text('⛶', fsIconX, fsIconY);
}

Step 5: Call drawIcons() in draw()

Add the following code at the end of the draw() function, just before the closing brace:

  // Draw icons in lower right corner of control region
  drawIcons();
}

Step 6: Add mousePressed() Function

Add the complete mousePressed() function after the drawIcons() function:

function mousePressed() {
  // Check if Creative Commons icon was clicked
  let distCC = dist(mouseX, mouseY, ccIconX, ccIconY);
  if (distCC < iconSize/​2) {
    // Get the base URL (remove '/​sims/​icons/​main.html' from current URL)
    let baseUrl = window.location.href.split('/​sims/')[0];
    window.open(baseUrl + '/​license/', '_blank');
    return;
  }

  // Check if Fullscreen icon was clicked
  let distFS = dist(mouseX, mouseY, fsIconX, fsIconY);
  if (distFS < iconSize/​2) {
    // Open main.html in a new window/​tab (same behavior as the fullscreen button)
    window.open('main.html', '_blank');
    return;
  }
}

Step 7: Update windowResized() Function

Update the windowResized() function to use sliderRightMargin when resizing sliders:

function windowResized() {
  // Update canvas size when the container resizes
  updateCanvasSize();
  resizeCanvas(containerWidth, containerHeight);
  // resize the speed slider and any other sliders here
  speedSlider.size(canvasWidth - sliderLeftMargin - sliderRightMargin);
  redraw();
}

If there are multiple sliders, update all slider size calculations to use sliderRightMargin.

Step 8: Update setup() Function

If the slider size is set in setup(), update it to use sliderRightMargin:

speedSlider.size(canvasWidth - sliderLeftMargin - sliderRightMargin);

Step 9: Verify and Test

After making all changes:

  1. Verify that all edits were successful
  2. Inform the user that the icons have been added
  3. Note that approximately 40 lines of code were added
  4. Suggest testing the icons by opening the MicroSim

Code Size Impact

Adding icons increases the JavaScript file size by approximately 40 lines:

  • 6 lines for icon variables
  • 1 line to call drawIcons()
  • 18 lines for the drawIcons() function
  • 19 lines for the mousePressed() function
  • Additional spacing and comments

The icons can be omitted from minimal MicroSims to reduce file size.

Icon Functionality

Creative Commons Icon (ⓒ):

  • Positioned second from the right in the control region
  • Clicking opens /​license/ page in a new tab
  • Uses relative URL calculation to work in any deployment

Fullscreen Icon (⛶):

  • Positioned at the far right of the control region
  • Clicking opens main.html in a new window/​tab
  • Provides full-page viewing experience

Both icons use distance-based click detection with dist() function, creating circular clickable regions with a radius of iconSize/​2 (12 pixels).

Common Variations

Different Icon Symbols: Replace the Unicode characters ⓒ and ⛶ with other symbols as needed:

  • License: ⓒ, ©, 🅭
  • Fullscreen: ⛶, ⤢, ⛶
  • Help: ?, ⓘ, ❓
  • Settings: ⚙, ⚙️

Additional Icons: To add more icons, follow the same pattern:

  1. Add position variables (e.g., helpIconX, helpIconY)
  2. Calculate position in drawIcons() (move left by iconSize + iconMargin)
  3. Draw the icon in drawIcons()
  4. Add click detection in mousePressed()
  5. Increase sliderRightMargin by 30 pixels per additional icon

Custom Actions: Modify the mousePressed() function to perform different actions:

  • Open different URLs
  • Toggle simulation features
  • Display help overlays
  • Share via social media

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
Imagica logo
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View