Drag the background!

API: P5 (AB) (r2)

API Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
P5 (AB) (r2) Yes P5 Yes 3 Worlds None


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 1.3.1.
  • Includes jQuery 3.6.0.
  • 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

	ABWorld.p5canvas;	

	
 // The object corresponding to p5canvas.canvas 
 
	ABWorld.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.



Templates



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

Bug bounty      Classes      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.