Cut out a shape of another

I want to create a parachute simply using the given shapes. I draw using arc() and cut out using ellipse(). This works great if there is only one image on the screen at a given time. The problem is, there can be more of these parachutes on the screen. Because the cut out is just an ellipse in background color, it will draw over parachutes in the background.

I need to cut the ellipse() out, but have the region to be transparent afterwards. (substract, cut out, delete region, what ever you would call it).

Is there an easy way to achive this task? The arc()s shall have different colors. What would I look for?

PGraphics parachute;

 void setup()
 {

  size(800,800);
   background(0);

   parachute = createGraphics(500,500);
   parachute.beginDraw();
   parachute.fill(255,0,0);
   parachute.arc(250,250,400,200, radians(180), radians(250));
   parachute.fill(0,255,0);
   parachute.arc(250,250,400,200, radians(250), radians(290));
   parachute.fill(0,0,255);
   parachute.arc(250,250,400,200, radians(290), radians(360));

   //cutout
   parachute.fill(0);
   parachute.ellipse(250,250,400,170);

   parachute.endDraw();

 }

void draw()
{
  image(parachute,200,200);
  image(parachute,150,100);

}
Tagged:

Answers

  • mask() is cool for this. Here:

    PImage chute;
    
    void setup() {
      size(800, 800);
      PGraphics pg;
      PImage mask;
      pg = createGraphics(500, 500);
      pg.beginDraw();
      pg.noStroke();
      pg.background(0);
      pg.fill(255);
      pg.arc(250, 250, 400, 200, radians(180), radians(360));
      pg.fill(0);
      pg.ellipse(250, 250, 400, 170);
      pg.endDraw();
      mask = pg.get();
      pg.beginDraw();  
      pg.fill(255, 0, 0);
      pg.arc(250, 250, 400, 200, radians(180), radians(250));
      pg.fill(0, 255, 0);
      pg.arc(250, 250, 400, 200, radians(250), radians(290));
      pg.fill(0, 0, 255);
      pg.arc(250, 250, 400, 200, radians(290), radians(360));
      pg.endDraw();
      chute = pg.get();
      chute.mask(mask);
    }
    
    void draw()
    {
      background(128, 128, 255);
      image(chute, 200, 200);
      image(chute, 150, 100);
    }
    
  • thats nice, thanks

Sign In or Register to comment.