Drag the background!

API: P5 (r3)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
P5 (r3) Yes P5 No 21 Worlds Starter Worlds


This API is for P5 Worlds. It has no Ancient Brain framework. Anything written in P5 should run using this API without change.

This API has the following features:

  • Includes P5 graphics library, release 1.3.1.
  • Includes jQuery 3.6.0.
  • Loads up minimal CSS that should not conflict with user CSS.

  • No Ancient Brain framework.
  • World has to do everything. It has to create its own canvas. It has to do its own camera control.
  • World author writes normal P5 code, with setup() and draw().
  • Run header on RHS. Many P5 worlds use fixed small dimension canvas, which will go in top LHS. So this API puts run header on RHS.
  • If World uses Minds, World author must call the Mind themselves inside the draw function:
     AB.mind.getAction ( state );  

  • If you turn canvas off ("noCanvas") the API uses the html2canvas library to build a screenshot of your page.
  • If you are using "noCanvas", note the html2canvas library has some limitations and may not be able to accurately screenshot your page.

Optional: The "ABWorld" object

This API defines the following "ABWorld" global variable. World authors can ignore the existence of ABWorld entirely.
 

	ABWorld;                 // instance of class ABWorldClass  
 
// Data and methods of ABWorld:
 
	ABWorld.canvas;          // to point to the canvas  		
 
	// useful functions for creating/resizing canvas:

	ABWorld.fullwidth();     // return full width of window on desktop / screen on mobile 
	ABWorld.fullheight();    // return full height of window on desktop / screen on mobile

World code can normally createCanvas() and ignore return. The created canvas should display in the run window. The AB system will find the canvas automatically (e.g. when it needs to do a screenshot). If the canvas does not display normally, or if the AB system fails to find the canvas, you can help it out by creating the canvas as follows:
 

	var canvas = createCanvas ( ... );		 

	ABWorld.setCanvas ( canvas );           // tell the AB system where the canvas is 



Templates


Examples

Examples of Worlds that use this API:


P5 chase World
138 runs ♦ 0 likes
By Starter user  
Created: 4 Aug 2018
Modified: 18 Apr 2021
Example of World with Mind on P5 plain API. No AB framework. Have to call Mind yourself. Mind mo...
P5 Particle System
144 runs ♦ 0 likes
By Starter user  
Created: 4 Aug 2018
Modified: 18 Apr 2021
Port of P5 site's "Particle System" example with almost no change. P5 plain API. No AB framework...
One Cube World (P5)
788 runs ♦ 0 likes
By Starter user  
Created: 10 Nov 2018
Modified: 21 Apr 2021
Simple starter World (P5 version). No camera control. So cube rotates to show 3D.

The background is a program, showing the JavaScript graphics used on this site.
The globes light up when you log in.
 
Font:

Website copyright Ancient Brain. 2018-2021.
Users retain ownership of user content.

Platforms      Stats      The name      Terms and conditions

Call for partners      Contact

Call for partners!
If you are interested in writing a programming course, textbook or tutorial videos, Ancient Brain is looking for partners. We will work with you, and integrate your course into the site. This is an opportunity for someone looking to develop a course or textbook to partner with a site to support it and promote it.