API: Canvas 1.0

Do your own WebGL. No graphics library. jQuery 1.12.4.


This API has the following features:

  • No graphics library.
  • Creates a canvas in a div in the run window.
  • The author has to do their own 2D or WebGL rendering.

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:

 

  // A canvas that may be drawn on using getContext("2d") or getContext("webgl")

	ABWorld.canvas;		
		  
		
  // create canvas:		

	ABWorld.init ( color );   
		
		
  // get drawing context:
  
	ABWorld.getContext ( type );
		
See 2D rendering documentation and WebGL rendering documentation.


Optional: Customised drawing context

The function ABWorld.getContext calls ABWorld.canvas.getContext with default args to create a drawing context. It is used like:
 
 var ctx = ABWorld.getContext ( "2d" );
 var ctx = ABWorld.getContext ( "webgl" );

If you want a customised drawing context, call it directly:

 
 var ctx = ABWorld.canvas.getContext ( type, args );

Note if you are customising drawing context: To be able to generate World image screenshots, you need:

 
 var ctx = ABWorld.canvas.getContext ( type, { preserveDrawingBuffer: true } );	


Templates



Examples

Examples of Worlds that use this API:


canvas webgl
397 runs ♦ 2 likes
Starter user
Minimal starter World for "Canvas" API (no graphics library). Program using getContext("webgl")....
canvas 2d
240 runs ♦ 2 likes
Starter user
Minimal starter World for "Canvas" API (no graphics library). Program using getContext("2d"). Pa...

The background is a program, showing the JavaScript graphics used on this site.
 
Font:

© Ancient Brain Ltd. All rights reserved.

Ancient Brain ™ is a trademark of Ancient Brain Ltd.

Beta      Bug bounty      Contact      Stats      The name      Terms and conditions