Advertisement
xeromino

masks

Dec 23rd, 2016
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. int frms = 250, num = 6;
  2. int w = 120, h = 50, radius = 140, side = 270;
  3. float theta = 0;
  4. PImage niceImage, maskedImage;
  5. PGraphics myMask, src;
  6.  
  7. void setup() {
  8.   size(540, 540);
  9.   rectMode(CENTER);
  10.   myMask = createGraphics(width, height);
  11.   src = createGraphics(width, height);
  12. }
  13.  
  14. void draw() {
  15.   background(238);
  16.  
  17.   src.beginDraw();
  18.   src.background(255);
  19.   src.rectMode(CENTER);
  20.   src.noStroke();
  21.   src.stroke(34);
  22.   src.strokeWeight(2);
  23.   src.fill(225, 76, 69);
  24.   src.rect(width/2, height/2, side, side);
  25.   src.endDraw();
  26.  
  27.   myMask.beginDraw();
  28.   myMask.background(0);
  29.   myMask.rectMode(CENTER);
  30.   for (int i=0; i<num; i++) {
  31.     float angle = TWO_PI/num*i;
  32.     float x = width/2 + cos(angle)*radius;
  33.     float y = height/2 + sin(angle)*radius;
  34.     myRect(x, y, angle);
  35.   }
  36.   myMask.endDraw();
  37.  
  38.   maskedImage = src.get();
  39.   maskedImage.mask(myMask);
  40.   image(maskedImage, 0, 0);
  41.  
  42.   for (int i=0; i<num; i++) {
  43.     float angle = TWO_PI/num*i;
  44.     float x = width/2 + cos(angle)*radius ;
  45.     float y = height/2 + sin(angle)*radius;
  46.     pushMatrix();
  47.     translate(x, y);
  48.     rotate(theta + angle);
  49.     noFill();
  50.     stroke(34);
  51.     strokeWeight(2);
  52.     rect(0, 0, w, h, 20);
  53.     popMatrix();
  54.   }
  55.  
  56.   if (frameCount<=frms) saveFrame("image-###.gif");
  57.  
  58.   theta += TWO_PI/frms;
  59. }
  60.  
  61. void myRect(float x, float y, float angle) {
  62.   myMask.pushMatrix();
  63.   myMask.translate(x, y);
  64.   myMask.rotate(theta+angle);
  65.   myMask.fill(255);
  66.   myMask.noStroke();
  67.   myMask.rect(0, 0, w, h, 20);
  68.   myMask.popMatrix();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement