API: P5 (AB)

API Version Uses canvas Graphics libraries AB framework Worlds using this API Starter Worlds
P5 (AB) 1.0 Yes P5 Yes 33 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.

  • Automatically creates a canvas in a div in the run window.
  • The author can use P5 functions to create graphics on the canvas.
  • 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


Examples

Examples of Worlds that use this API:


P5 Mouse tracker
158 runs ♦ 1 like
By Starter user  
Created: 4 Jul 2018
Modified: 12 Dec 2019
Example of P5 World integrated with AB framework. Desktop: Draw ellipse wherever the mouse hover...
Scare the Fishes!
101 runs ♦ 0 likes
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 Game of Life
272 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 ! ...

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.