Class CanvasContext

The CanvasContext provides static access to information and methods for the running p5.js sketch canvas.

Constructors

Accessors

  • get defaultStroke(): number
  • The default stroke of the sketch. Equivalent to a stroke of 1 in a 500x500 sketch.

    Returns number

  • get isWebGL(): boolean
  • Is the canvas rendering mode set to WebGL?

    Returns boolean

  • get lockedCanvas(): boolean
  • When true, buildCanvas will not create a new canvas.

    Returns boolean

Methods

  • Build a p5 canvas with the given aspect ratio, resolution, and canvas type. If lockedCanvas is true, no canvas will be built.

    Parameters

    • aspectRatio: AspectRatio
    • resolution: number
    • OptionalcanvasType: string

      Can be WEBGL ("webgl") or P2D ("p2d").

    • OptionallockCanvas: boolean

      When true, the canvas will be locked after it has been created.

    Returns void

  • Locks the canvas. After this is called, buildCanvas will not create a new canvas.

    Returns void

  • Resizes the canvas and decorates the canvas with the appropriate updated attributes.

    Returns void

  • Unlocks the canvas. After this is called, buildCanvas will create a new canvas.

    Returns void

  • Update the current aspect ratio of the canvas to the given aspect ratio. This method will resize the canvas and decorate it with the appropriate updated attributes.

    Parameters

    Returns void

  • Update the current resolution of the canvas to the given resolution. This method will resize the canvas and decorate it with the appropriate updated attributes.

    Parameters

    • resolution: number

    Returns void