color blue = color(0, 0, 255); color yellow = color(255, 255, 0); PImage gr, maskImage; PGraphics gradient, mask; void setup() { size(600, 400, P2D); gr = createImage(width, height, RGB); mask = createGraphics(width, height); gradient = createGraphics(width, height, P2D); gradientRect(0, 0, width, height, blue, yellow); createMask(); } void draw() { background(0); gr.mask(mask); image(gr, 0, 0); } void gradientRect(int x, int y, int w, int h, color c1, color c2) { gradient.beginDraw(); gradient.beginShape(); gradient.fill(c1); gradient.vertex(x, y); gradient.vertex(x, y+h); gradient.fill(c2); gradient.vertex(x+w, y+h); gradient.vertex(x+w, y); gradient.endShape(); gradient.endDraw(); gr = gradient.copy(); } void createMask() { mask.beginDraw(); mask.background(0); mask.stroke(255); mask.strokeWeight(20); for (int i=0; i<5; i++) { mask.line(50+i*100, 50, width-50, height-50);} mask.endDraw(); }