Advertisement
xeromino

mask

Dec 7th, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. color blue = color(0, 0, 255);
  2. color yellow = color(255, 255, 0);
  3.  
  4. PImage gr, maskImage;
  5. PGraphics gradient, mask;
  6.  
  7. void setup() {
  8.   size(600, 400, P2D);
  9.   gr = createImage(width, height, RGB);
  10.   mask = createGraphics(width, height);
  11.   gradient = createGraphics(width, height, P2D);
  12.  
  13.   gradientRect(0, 0, width, height, blue, yellow);
  14.   createMask();
  15. }
  16.  
  17. void draw() {
  18.   background(0);
  19.   gr.mask(mask);
  20.   image(gr, 0, 0);
  21. }
  22.  
  23. void gradientRect(int x, int y, int w, int h, color c1, color c2) {
  24.   gradient.beginDraw();
  25.   gradient.beginShape();
  26.   gradient.fill(c1);
  27.   gradient.vertex(x, y);
  28.   gradient.vertex(x, y+h);
  29.   gradient.fill(c2);
  30.   gradient.vertex(x+w, y+h);
  31.   gradient.vertex(x+w, y);
  32.   gradient.endShape();
  33.   gradient.endDraw();
  34.   gr = gradient.copy();
  35. }
  36.  
  37. void createMask() {
  38.   mask.beginDraw();
  39.   mask.background(0);
  40.   mask.stroke(255);
  41.   mask.strokeWeight(20);
  42.   for (int i=0; i<5; i++) {
  43.   mask.line(50+i*100, 50, width-50, height-50);}
  44.  
  45.   mask.endDraw();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement