How to copy a triangle out of an image

edited April 2018 in How To...

Hi there,

I have looked at processings copy() and get() functions and am wondering if it is possible to copy irregular shapes out of images with similar functions?

For the sake of clarity if the copy and get functions are rectangular cookie cutters, I am looking for a cookie cutter that can cut triangles/circles etc.




  • edited March 2018 Answer ✓

    The key thing that the basic mask() example doesn't show you is that you can draw the mask using PGraphics.

    Start with the basic example, and combine it with the PGraphics example to draw your own mask -- e.g. a triangle.

     * TriangleMask
     * draw a Mask example
     * 2016-11-01 Processing 3.2.1
    PImage photo;
    PGraphics maskImage;
    void setup() {
      size(512, 512);
      photo = loadImage("https://");
      // create mask
      maskImage = createGraphics(512,512);
      maskImage.triangle(30, 480, 256, 30, 480, 480);
      // apply mask
    void draw() {
      // show masked image
      image(photo, 0, 0);


  • Wowww, awesome thank you both very much.

Sign In or Register to comment.