Skip to content
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

Is this a bug with translations? #21

Open
tegacodes opened this issue Oct 1, 2024 · 2 comments
Open

Is this a bug with translations? #21

tegacodes opened this issue Oct 1, 2024 · 2 comments

Comments

@tegacodes
Copy link
Collaborator

Not sure if this is a bug, but if you don't call translations on color layers within push and pop, they accumulate when the two layers are cut out from one another. See here how the blue layer also inherits the translations from the pink layer when cutout is called. If the translations from each layer are in push and pop, the problem is solved. not sure if this is a bug.
https://editor.p5js.org/brain/sketches/Kj3uwPFmI

@antiboredom
Copy link
Owner

I'd call it a bug. Here's the code for cutout:

cutout(imageMask) {
  let img = this.get();
  img.cutout(imageMask);
  this.clear();
  this.copy(img, 0, 0, this.width, this.height, 0, 0, img.width, img.height);
}

What's happening is that it copies all pixels of the current layer to an image, does the cutout operation on the image, and then pastes that back into the layer. What I didn't consider is that if that layer has a transformation on it it gets applied to the cutout image. Oops!

@antiboredom
Copy link
Owner

I have a fix for it:

cutout(imageMask) {
    let img = this.get();
    img.cutout(imageMask);
    this.drawingContext.save();
    this.drawingContext.resetTransform();
    this.clear();
    this.copy(img, 0, 0, this.width, this.height, 0, 0, img.width, img.height);
    this.drawingContext.restore();
}

Slightly concerned that this might affect other things that I'm not aware of. Also just realizing that we really need some versioning for this library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants