Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int frms = 250, num = 6;
- int w = 120, h = 50, radius = 140, side = 270;
- float theta = 0;
- PImage niceImage, maskedImage;
- PGraphics myMask, src;
- void setup() {
- size(540, 540);
- rectMode(CENTER);
- myMask = createGraphics(width, height);
- src = createGraphics(width, height);
- }
- void draw() {
- background(238);
- src.beginDraw();
- src.background(255);
- src.rectMode(CENTER);
- src.noStroke();
- src.stroke(34);
- src.strokeWeight(2);
- src.fill(225, 76, 69);
- src.rect(width/2, height/2, side, side);
- src.endDraw();
- myMask.beginDraw();
- myMask.background(0);
- myMask.rectMode(CENTER);
- for (int i=0; i<num; i++) {
- float angle = TWO_PI/num*i;
- float x = width/2 + cos(angle)*radius;
- float y = height/2 + sin(angle)*radius;
- myRect(x, y, angle);
- }
- myMask.endDraw();
- maskedImage = src.get();
- maskedImage.mask(myMask);
- image(maskedImage, 0, 0);
- for (int i=0; i<num; i++) {
- float angle = TWO_PI/num*i;
- float x = width/2 + cos(angle)*radius ;
- float y = height/2 + sin(angle)*radius;
- pushMatrix();
- translate(x, y);
- rotate(theta + angle);
- noFill();
- stroke(34);
- strokeWeight(2);
- rect(0, 0, w, h, 20);
- popMatrix();
- }
- if (frameCount<=frms) saveFrame("image-###.gif");
- theta += TWO_PI/frms;
- }
- void myRect(float x, float y, float angle) {
- myMask.pushMatrix();
- myMask.translate(x, y);
- myMask.rotate(theta+angle);
- myMask.fill(255);
- myMask.noStroke();
- myMask.rect(0, 0, w, h, 20);
- myMask.popMatrix();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement