Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Canvas JS and transparency : seeing through a cliped shape

The probleme is : I want to make a transparent holes in a shape, so I'm using a composite mode : destination-out, which allow to remove a part of the shape with a second shape.

That's ok on a single shape.

But when multiple "drilled" shapes are overlaping, there is no transparency effect. I understand that's because this is the way globalComposite and js canvas is working... But, is there a solution ? I tried clip() and various composite options, i didn't find.

Here is the expected result : https://i.stack.imgur.com/leVfB.png

and here is a simplified working JSFiddle : https://jsfiddle.net/7y5utsz0/

    // Drawing the shape
    ctx.save();
    ctx.beginPath();            
    ctx.rect(this.x, this.y, this.w, this.h);
    ctx.closePath();    
    ctx.fillStyle = '#'+this.color; 
    ctx.fill(this.path);
    ctx.restore();
    
    // "Drilling" the shape with a circle   
    ctx.save();                 
    ctx.globalCompositeOperation = 'destination-out';   
    ctx.beginPath();        
    ctx.arc(this.x + 30, this.y + 30, 20, 0, Math.PI * 2, false);
    ctx.fillStyle = '#ffffff';
    ctx.fill(); 
    ctx.closePath();
    ctx.restore();

Thanks for any kind of solutions !

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!