question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set reference p5 examples to noLoop() on window.blur()

See original GitHub issue

Nature of issue?

  • Found a bug
  • Existing feature enhancement
  • New feature request

Most appropriate sub-area of p5.js?

  • Other (website documentation)

Which platform were you using when you encountered this?

  • Desktop/Laptop

Feature enhancement details:

I regularly notice that students like to have multiple p5.js reference tabs open (also p5 editor) while researching how things work. While great, one big problem is that each of these p5 instances are constantly running (loop()) in the background…! With just 1 or 2 tabs that quickly eats up a lot of browser resources, sometimes there’s 5+ tabs all running p5 instances.

In P5LIVE Eco Mode is set active by default, so p5 changes to noLoop() on window.blur() and back to loop() on window.focus(). I propose enabling this especially for the references and ideal (but more discussion needed) if also applied to the web editor.

A proposed snippet for the website (Q: what’s the array variable for storing each p5 instance??):

window.onblur = function () { 
  for (let i = 0; i < p5Instances.length; i++) {
    p5Instances[i].noLoop();
  }
}

window.onfocus = function () { 
  for (let i = 0; i < p5Instances.length; i++) {
    p5Instances[i].loop();
  }
}

If this gets a green light (especially for the reference pages), then perhaps someone from the website-team knows how/where to implement this quickly… otherwise if pointed in the right direction (which src file and the name of p5 instances array) I’d be happy to give it a go.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
limzykennethcommented, Nov 4, 2019

We can explore potentially implementing this on the website. I’ll move this issue over there. You can open one for web editor if you wish to proposed something similar there.

0reactions
limzykennethcommented, Nov 5, 2019

If you are interested in investigating the possibilities (or anyone else), the code for rendering reference example is here and the code for rendering example on examples page is here. Almost all the js files the website use can be found here if that’s useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reference | noLoop() - P5.js
Description. Stops p5.js from continuously executing the code within draw(). If loop() is called, the code in draw() begins to run continuously again....
Read more >
p5 Documentation - Read the Docs
The Reference provides a detailed overview of the complete p5 api. ... background() which sets a background color for the window.
Read more >
Javascript Window Blur() and Window Focus() Method
Javascript Window Blur() method is used to remove focus from the current window. i.e, It sends the new open Window to the background....
Read more >
p5js - pixelDensity() doesn't help on retina screens
There are two ways to make sure your "points" of color are square and completely fill the plane even when zoomed in: 1)...
Read more >
Team:Munich/backgroundGraphics/p5JS - iGEM 2019
It contains a set of glyphs and methods to draw text on a drawing context, ... addEventListener('writeend', function() { // Navigating to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found