Drag the background!

API: P5 (AB) (r1)

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

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

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.)

  • 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.
  • 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 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:

  // 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:

The Game of Life
526 runs ♦ 0 likes
By Enhanced  
Created: 9 Jul 2018
Modified: 19 Jul 2018
The famous Game of Life. Click on the screen to place the initial cells and then click start ! ...
Scare the Fishes!
172 runs ♦ 1 like
By Enhanced  
Created: 2 Aug 2018
Modified: 2 Aug 2018
Scare the fishes with your mouse ! If you click they will flee even further away. Includes twea...

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

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.