Skip to content

loading.js uses canvas-based animations and sketch instances have their own indicator - #9119

Open
Jextic wants to merge 4 commits into
processing:mainfrom
Jextic:issue-8922
Open

loading.js uses canvas-based animations and sketch instances have their own indicator#9119
Jextic wants to merge 4 commits into
processing:mainfrom
Jextic:issue-8922

Conversation

@Jextic

@Jextic Jextic commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Resolves #8922

Changes:

  • Changed the CSS style loading indicator to a canvas-based loading indicator. It now uses a spinning p5 logo instead of a generic spinning circle. Thanks to Raphaël de Courville for the sketch code.
  • Changed _createLoadingIndicator() to _createLoadingOverlay. _createLoadingOverlay creates another canvas (which will contain the loading indicator) right on top of the user's canvas (or default canvas).
  • Helper functions _positionCanvas(), _removeLoadingOverlay(), and drawLoadingIndicator() were added to help center the loading indicator, remove it when it's no longer loading, and use draw the p5 logo using canvas functions.
  • Registered the decorator _handleLoadingIndicator() to intercept the canvas whenever canvas-related functions (createCanvas, resizeCanvas, and noCanvas) are called on.

Screenshots of the change:

Video of instance mode sketches:

instance-mode-loading.mp4

This uses the instance mode sketch provided in the issue comment thread plus a modified version of the issue's first sketch example to show that the loading indicator will resize itself respectively to when the canvas resizes.

PR Checklist

@p5-bot

p5-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: a6e57bc

Previous deployments

1c46bb1


This is an automated message.

@limzykenneth

Copy link
Copy Markdown
Member

@Jextic The test is failing because of https://github.com/processing/p5.js/blob/main/test/unit/core/loading.js#L9 passing null to the first argument of the loading addon function. You will need to pass in a mock, you can have a look at other test files on how to use the mock import { mockP5, mockP5Prototype } from '../../js/mocks';

@Jextic

Jextic commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@limzykenneth Thank you. I changed the test files to use mockP5 and mockP5Prototype so the setup should work correctly now. I ran the test and everything passed except for the typography one.

@limzykenneth limzykenneth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One inline and a couple related things:

  1. Is there a way for the user to opt out of having the default loading animation?
  2. Currently the loading animation will still draw on top of what the user already drawn in setup, is there an easy way to avoid it? eg.
async function setup() {
  createCanvas(400, 400);
  background(200);
  ellipse(width / 2, height / 2, 200);
  await new Promise((resolve) => setTimeout(resolve, 2000));
}

This will draw the loading animation on top of the background and ellipse which may not be ideal. Possibly the capability to disable this would be enough but if it can be done relatively manually it would be great as well.

Comment thread src/core/loading.js
Comment on lines +25 to +28
if (typeof window === 'undefined') {
return;
}

const canvasParent = this.canvas?.parentElement;
let container = this._userNode || canvasParent || document.body;

if (typeof container === 'string') {
container = document.getElementById(container) || document.body;
}

this._loadingIndicator = createLoadingIndicator(container);
this._isSketchLoading = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if this module explicitly expects to be running in the browser environment, rather than checking window here, it can instead be conditionally registered in main.js based on whether window is defined or not, so the decorator will never be registered if they are not needed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: Loading indication

2 participants