Skip to content

Should P5.Graphics support set() with another P5.Graphics? #2984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
KevinWorkman opened this issue Jun 8, 2018 · 1 comment
Open
3 tasks done

Should P5.Graphics support set() with another P5.Graphics? #2984

KevinWorkman opened this issue Jun 8, 2018 · 1 comment

Comments

@KevinWorkman
Copy link
Contributor

Nature of issue?

  • Found a bug

Most appropriate sub-area of p5.js?

  • Color
  • createGraphics()
  • set()

Which platform were you using when you encountered this?

  • Desktop/Laptop

Details about the bug:

  • p5.js version: 0.6.1 (using the alpha web editor)
  • Web browser and version: Chrome 67.0.3396.62
  • Operating System: Linux
  • Steps to reproduce this:

From this Stack Overflow question.

It appears that the set() function does not work with P5.Graphics values. Is this expected?

let redRect;

function setup() {
  createCanvas(100,100);
  redRect = createGraphics(100,100);
  redRect.fill(255, 0, 0);
  redRect.rect(20,20,40,40);
	
  const blueRect = createGraphics(20, 20);
  blueRect.background(0, 0, 255);
  redRect.set(30, 30, blueRect);
  redRect.updatePixels();
}

function draw() {
  background(0, 255, 0);
  image(redRect,0,0);
}

I would expect this to create a graphics that contains a red rectangle, and then draw a blue rectangle to that first graphics. Instead, only a single pixel is set, and it's set to transparent?

red rectangle on green background

@Ajayneethikannan
Copy link
Contributor

I think that this feature should be present .
The reason why it is setting a single transparent pixel is the current set method checks whether the third parameter imgOrCol is an p5.Image instance or a color value. In case it is neither if them, it sets the value of the pixel mentioned as [0, 0, 0, 0].
We can check its implementation here .

We can check if the imgOrCol parameter is p5.Image instance or p5.Graphics instance,
then we can set the pixels of one p5.Graphics instance from another.

Also , if we pass a image as the third parameter set(x, y, image) the image fills the entire canvas from x, y onwards. Is this the intended behavior ?
Should we pass the height and width here
as

this.drawingContext.drawImage(imgOrCol.canvas, x, y, imgOrCol.width, imgOrCol.height);

Would love your suggestions ,
Thank you!

@limzykenneth limzykenneth moved this to Proposal in p5.js 2.0 May 28, 2024
@Qianqianye Qianqianye moved this from Proposal to Out of Scope in p5.js 2.0 Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Out of Scope
Development

No branches or pull requests

4 participants