Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda