processing / processing/p5.js

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

Open
#5,297 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Documentation
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided createGraphics(100, 100, WEBGL) reproduction and compare the renderer's transformations across successive draw() calls. Trace how pg.scale() and pg.translate() are reset between frames; done means repeated transformations no longer accumulate, while the documented scale() behavior is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.