Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.76 KB | None | 0 0
  1.  
  2. final float ROTATE_SPEED = 2.0;
  3. final float ZOOM_SPEED = 3.0;
  4. final boolean BACKGROUND_MORPH = true;
  5. final int FPS = 30;
  6.  
  7. PGraphics canvas;
  8. PImage prevFrame;
  9. float zoomSpeed;
  10. int zoomStepW;
  11. int zoomStepH;
  12. float rotation;
  13. long frames;
  14.  
  15. void setup() {
  16.   size(800, 800);
  17.   colorMode(HSB, 100);
  18.   background(0);
  19.   frameRate(FPS);
  20.   canvas = createGraphics(width, height);
  21.   canvas.smooth(4); // set to 2 for better background blur and shitty fps
  22.   updateZoomSpeed(ZOOM_SPEED);
  23. }
  24.  
  25. void updateZoomSpeed(float newZoomSpeed) {
  26.   zoomSpeed = 1 - (newZoomSpeed/100);
  27.   zoomStepW = Math.round((zoomSpeed * width) - width);
  28.   zoomStepH = Math.round((zoomSpeed * height) - height);
  29. }
  30.  
  31. void updateBlur() {
  32.   frames++;
  33.  
  34.   prevFrame = canvas.copy();
  35.   int offW = zoomStepW;
  36.   int offH = zoomStepH;
  37.   if (BACKGROUND_MORPH) {
  38.     offW += (int)(zoomStepW*cos(rotation*3));
  39.     offH += (int)(zoomStepH*sin(rotation*2));
  40.   }
  41.   prevFrame.resize(width+offW, height+offH);
  42.  
  43.   if (frames < (FPS*2)) {
  44.     canvas.blendMode(ADD);
  45.     updateZoomSpeed((frames/(FPS*2)) * 5);
  46.   } else if (frames < (FPS*5)) {
  47.     canvas.blendMode(BLEND);
  48.     updateZoomSpeed(5 - ((frames-(FPS*2))/(FPS*4)) * 5);
  49.   } else if (frames < (FPS*6)) {
  50.     canvas.blendMode(DIFFERENCE);
  51.   } else if (frames < (FPS*6.5)) {
  52.     canvas.blendMode(SUBTRACT);
  53.   } else {
  54.     frames = 0;
  55.   }
  56.  
  57.   canvas.image(prevFrame, offW/2, offH/2, width-offW, height-offH);
  58. }
  59.  
  60. void draw() {
  61.   canvas.beginDraw();
  62.   updateBlur();
  63.   canvas.colorMode(HSB, 100);
  64.   canvas.translate(width/2, height/2);
  65.   canvas.blendMode(BLEND);
  66.   canvas.stroke((50*rotation)%100, 50, 25+50*abs(cos(rotation/2)));
  67.   canvas.strokeWeight(0.01+2*abs(sin(rotation/4)));
  68.   drawCircle(width/10, 8, rotation, 3, width/20);
  69.   canvas.endDraw();
  70.   image(canvas, 0, 0, width, height);
  71.   rotation+=ROTATE_SPEED/100;
  72.   //saveFrame("G:/frames/####.tif");
  73. }
  74.  
  75. void drawCircle(float radius, int steps, float offset, int depth, float size) {
  76.   float rotateStep = (TWO_PI/steps) * (depth % 2 == 0 ? 1 : -1);
  77.   canvas.fill((50*(1+depth)*offset)%100, 100, 100);
  78.   for (int i = 0; i <= steps; i++) {
  79.     canvas.pushMatrix();
  80.     canvas.rotate(offset + rotateStep * i);
  81.     canvas.translate(radius, radius);
  82.     canvas.scale(0.1+abs(2*sin(offset)),0.1+abs(2*cos(offset)));
  83.     canvas.triangle(-size, -size, size, -size, 0, size*2*abs(sin(offset)));
  84.     canvas.popMatrix();
  85.   }
  86.   if (depth > 0) {
  87.     for (int i = 0; i <= steps; i++) {
  88.       canvas.pushMatrix();
  89.       canvas.rotate(offset + rotateStep * i);
  90.       canvas.translate(radius, radius);
  91.       canvas.scale(0.1+abs(2*sin(offset)), 0.1+abs(2*cos(offset)));
  92.       drawCircle(radius, (steps/2 == 0 ? 2 : steps/2), offset*1.25, depth-1, size * 0.5);
  93.       canvas.popMatrix();
  94.     }
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement