Drag the background!

API: ML5 (AB) (r1)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
ML5 (AB) (r1) Yes P5, ML5 Yes 18 Worlds Starter Worlds

This API is for P5 Worlds using ML5. It comes with an Ancient Brain framework to make writing Worlds easier. This would require changes to existing ML5 worlds. So this is really for writing new ML5 Worlds for this platform.

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.

  • Automatically creates a canvas in a div in the run window.
  • The author can use P5 functions to create graphics on the canvas.
  • Creates canvas for 2D graphics by default. To do 3D graphics see below.
  • The Ancient Brain framework ("newRun" and "nextStep") conflicts with the P5 way of doing things ("setup" and "draw"). So this is really for writing new P5/ML5 Worlds for this platform.
  • For run control, the author can use either P5 framework or Ancient Brain framework. See below.
  • No built-in user camera control.

Global variables

This API defines the following global variables:

 ABWorld;       // instance of class ABWorldClass - basic functionality for this API

The "ABWorld" object

The public variables and methods of "ABWorld" are as follows:

  // define graphics mode (2D or 3D)
  // 2D is default
  // for 3D do this:  
    ABWorld.webgl = true;   
  // create canvas with some background color	
  // this defines a setup() function and calls P5's createCanvas() function
	ABWorld.init ( color );             

  // The object returned by P5's createCanvas() function


 // The object corresponding to p5canvas.canvas 

Important: Do not define a setup() function

P5 uses global functions setup() and draw(). This API defines its own setup() function internally to create the canvas. Hence in your World:

  1. Do not define a setup() function.
  2. The World can define optional beforesetup() and aftersetup() functions for code it wants run just before canvas creation and just after canvas creation.

The draw() function is optional. This API uses nextStep() or takeAction() to do the run loop, so you can put the code in there, or in a draw() function.



Examples of Worlds that use this API:

Recognise any image
148 runs ♦ 0 likes
By Starter user  
Created: 10 Jun 2021
Modified: 4 Jul 2021
Try to recognise any image with ML5 and MobileNet. Enter any image URL at runtime.

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.