In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

Phosphorus Player

SandCastleIcon.png This page has links to outside of the Scratch website and Wikipedia. Always remember to stay safe when using the internet since we can't guarantee the safety of other sites.
The Phosphorus Player playing a project

phosphorus is an alternative player used to run scratch projects. It has the same aim as the Scratch HTML5 Player, but is still being actively developed. The player runs in JavaScript and uses the HTML5 canvas to display scratch projects. Due to its use of JavaScript, it is widely known to make projects that use heavy or intense calculations run much faster than in the widely used Flash Player.

Often more advanced users leave add a link in their project description leading directly to their project in phosphorus. This can be seen especially often in pen projects.

The Sulfurous Player is a modification of the Phosphorus Player, and was designed to perform better and deliver more features. Some long standing bugs of the Phosphorus Player were also fixed.

Users are known to use Phosphorus to view other users' unshared projects and give their feedback on the projects.[1]

Usage

To view a project in phosphorus, simply paste the url of your project on the Scratch webpage in the input box. Your project should be loaded and will run automatically. Pasting the ID of your project will also suffice. Dragging a local .sb2 file into the page is also supported, allowing users to test their projects locally before potentially uploading or sharing them on the Scratch website.

If you want to include a link to your project in the player, simply include the phosphorus url appended with a hashtag and your project ID in your project notes, or wherever you want it. Such a URL could look like this: https://phosphorus.github.io/#000000000

Background Information

phosphorus was created by Nathan Dinsmore in collaboration with Truman Kilen. The phosphorus page credits state:

phosphorus was created by Nathan. Its CPS-style compilation and overall design was inspired by Rhys's sb2.js. It would have more bugs if not for Truman and Tim. It uses the JSZip library, created by Stuart Knightley, David Duponchel, Franz Buchinger, and António Afonso, to read .sb2 files and compressed projects, and the canvg library, created by Gabe Lerner, to render SVGs in <canvas> elements.

– phosphorus Credits[2]

phosphorus is an open source program, and the code can be found on github. The phosphorus page also includes options for packaging and embedding projects on third party websites. The user can customize the appearance of the embedded project to some extent, such enabling or disabling controls.

Differences to the default flash player

  • There's an option to pause all of the scripts and then rerun it.
  • Projects usually run much faster in phosphorus, especially Pen projects or those using heavy processing.
  • Projects will run on any device using a browser with HTML5 canvas support; this includes most mobile devices which don't have flash support. However, keyboard commands cannot be used on most mobile devices.
  • Unshared projects can be viewed if the project code is known to the user, even if it is in the user's trash. This issue (or feature) is known to the Scratch Team, but it is not likely to be fixed soon.[3]
  • phosphorus does not have the Flash Player's clone limit of 301 clones, thus it is possible to have infinite clones and cause some more lag.
  • Some small bugs where phosphorus behaves differently to the Scratch Flash Player.

Detecting phosphorus

Since phosphorus and the Flash Player differ slightly, a project can detect which player is running it.

The Flash Player supports boolean values and stores them as their own type. The number 1 is not equal to the string true, but it is equal to the boolean true. In phosphorus, 1 and the boolean true are not equal.

The script

when gf clicked
if <[1] = <[1] = [1]>> then
say [You are in the Flash Player]
else
say [You are in phosphorus]
end

This leads to a quirk in Scratch that shows that the equals operator isn't always transitive

<<[1] = [1]> = [true]> // true
<<[1] = [1]> = [1]> // true
<[true] = [1]> // false

thus, in the Flash Player, the equality operator is not always transitive

Another difference between Flash and phosphorus is that phosphorus will set it's costume number to (1) if an invalid costume name or number is entered in the "switch to costume" block, whereas Flash does not do anything. The following script can be used to detect phosphorus using this technique:

when flag clicked
switch costume to [costume 2 v]
switch costume to (join [hello][world])
if <(costume #) = [1]> then
  say [phosphorus]
else
  say [Flash]
end

Since only phosphorus will switch the costume to (1), the script can detect what player you are using.

References

  1. https://scratch.mit.edu/users/jromagnoli/#comments-35351729
  2. https://phosphorus.github.io/
  3. https://scratch.mit.edu/discuss/topic/64428/
  • This page was last modified on 6 September 2017, at 18:10.