Skip to content

Transformations on a p5.Renderer created by createGraphics are cumulative between draw()s #5297

Open
@KeyboardSounds

Description

@KeyboardSounds

Most appropriate sub-area of p5.js?

  • Accessibility (Web Accessibility)
  • Build tools and processes
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Friendly error system
  • Image
  • IO (Input/Output)
  • Localization
  • Math
  • Unit Testing
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

Details about the bug:

  • p5.js version:
  • Web browser and version:
    • Chrome: 91.0.4472.77
    • Firefox: 89.0
  • Operating System: Windows 10
  • Steps to reproduce this:
let pg;
function setup() {
  createCanvas(100, 100);
  pg = createGraphics(100, 100, WEBGL);
  pg.scale(0.5);
}

function draw() {
  pg.translate(-1, -1);
  background(200);
  pg.fill("blue");
  pg.background(100);
  pg.noStroke();
  pg.ellipse(pg.width / 50, pg.height / 50, 50, 50);
  image(pg, 50, 50);
  image(pg, 0, 0, 50, 50);
}

Expected behaviour:
From the docs

If scale() is called within draw(), the transformation is reset when the loop begins again.

Actual behavior:
The transformation is not reset when the loop begins again. Repeated transformations across multiple draw calls accumulate.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions