Drag the background!

API: P5 (r1)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
P5 (r1) Yes P5 No 2979 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.
  • Loads up lots of CSS - all the CSS used on the AB login pages. At the risk of conflict with user CSS. (Later APIs load up minimal 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 



Examples of Worlds that use this API:

Tutorial 7.8
105 runs ♦ 1 like
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!
Tutorial 7.8 variant
335 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
375 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 2.1
483 runs ♦ 1 like
By "Coding Train" p...  
Created: 4 Sep 2018
Modified: 4 Sep 2018
Variables in p5.js (mouseX, mouseY)
Tutorial 18.4
102 runs ♦ 0 likes
By "Coding Train" p...  
Created: 9 Sep 2018
Modified: 9 Sep 2018

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

Users retain ownership of user content.

Platforms      Stats      The name      Terms and conditions

Call for partners      Contact

Call for partners!
Ancient Brain is looking for partners. In particular, we seek a partner in writing a JavaScript coding book for schools, to be used worldwide. We will integrate your course into the Ancient Brain site. This is an opportunity for someone looking to develop a course and textbook to partner with a site to promote it. Read more.