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

Fix clipping bug with ellipses #7249

Merged

Conversation

jeanetteandrews
Copy link
Contributor

Resolves #7158

Changes:

Added ctx.closePath(); to the ellipse() function in p5.Renderer2D.js. This fixed weird behavior when using circles, ellipses, and arcs with a clipping mask.

View this sketch and comment/uncomment the src tags in HTML to view changes:
https://editor.p5js.org/jeanetteandrews/sketches/CMjMhM0fb

Recreate bug:

function setup() {
    createCanvas(400, 400);
    background(0);
    beginClip();
    circle(100, 100, 100);
    ellipse(300, 100, 100, 100);
    circle(100, 300, 100);
    arc(300, 300, 100, 100 , 0, 2*PI);
    endClip();
    background(255);
}

This behavior can also be recreated with the Canvas API. It's resolved by adding ctx.closePath(); after each shape.

const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

ctx.ellipse(100, 100, 50, 50, 0, 0, 2 * Math.PI);  
// ctx.closePath(); 
ctx.ellipse(300, 100, 50, 50, 0, 0, 2 * Math.PI);  
// ctx.closePath(); 
ctx.ellipse(100, 300, 50, 50, 0, 0, 2 * Math.PI);  
// ctx.closePath(); 
ctx.arc(300, 300, 50, 50, 0, 2 * Math.PI);
// ctx.closePath(); 

ctx.fill(); 

Screenshots of the change:

Clipping mask behavior before, and after

Screenshot 2024-09-06 at 11 32 44 PM Screenshot 2024-09-06 at 11 33 55 PM

PR Checklist

  • npm run lint passes
  • Unit tests are included / updated (npm test passes)

Copy link

welcome bot commented Sep 7, 2024

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@davepagurek
Copy link
Contributor

nice find, thanks for the fix!

@davepagurek davepagurek merged commit 7aec76d into processing:main Sep 7, 2024
2 checks passed
@davepagurek
Copy link
Contributor

@all-contributors please add @jeanetteandrews for code

Copy link
Contributor

@davepagurek

I've put up a pull request to add @jeanetteandrews! 🎉

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

Successfully merging this pull request may close these issues.

Strange behavior of clips with three successive ellipses/circles
2 participants