API: P5

API Version Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
P5 1.0 Yes P5 No 1024 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 0.7.1.
  • Includes jQuery 3.3.1.

  • 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 ( width, height );		 

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



Templates


Examples

Examples of Worlds that use this API:


Tutorial 7.8
73 runs ♦ 0 likes
By "Coding Train" p...  
Created: 5 Sep 2018
Modified: 5 Sep 2018
Objects and Images. On Ancient Brain you can upload your own images. Try it!
One Cube World (P5)
459 runs ♦ 0 likes
By Starter user  
Created: 10 Nov 2018
Modified: 13 Dec 2019
Simple starter World (P5 version). No camera control. So cube rotates to show 3D.
Tutorial 7.8 variant
190 runs ♦ 0 likes
By "Coding Train" p...  
Created: 6 Sep 2018
Modified: 11 Sep 2018
Tutorial 7.8 with music and other uploaded images, including from other users. Click on the images.
Tutorial 18.7
270 runs ♦ 0 likes
By "Coding Train" p...  
Created: 9 Sep 2018
Modified: 11 Sep 2018
Tutorial 18.7 with full canvas, resized model, sound. Texture on box is image from another user.
Tutorial 18.4
63 runs ♦ 0 likes
By "Coding Train" p...  
Created: 9 Sep 2018
Modified: 9 Sep 2018
Texture
P5 chase World
105 runs ♦ 0 likes
By Starter user  
Created: 4 Aug 2018
Modified: 13 Dec 2019
Example of World with Mind on P5 plain API. No AB framework. Have to call Mind yourself. Mind mo...
Tutorial 2.1
214 runs ♦ 0 likes
By "Coding Train" p...  
Created: 4 Sep 2018
Modified: 4 Sep 2018
Variables in p5.js (mouseX, mouseY)
P5 Particle System
115 runs ♦ 0 likes
By Starter user  
Created: 4 Aug 2018
Modified: 13 Dec 2019
Port of P5 site's "Particle System" example with almost no change. P5 plain API. No AB framework...

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

© Ancient Brain Ltd. 2018-19. All rights reserved.

Ancient Brain ™ is a trademark of Ancient Brain Ltd.

Platforms      Stats      The name      Terms and conditions

Bug bounty      Classes in Dublin      Contact

Call for partners!
If you are interested in writing a programming course or textbook, 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.