Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final float ROTATE_SPEED = 2.0;
- final float ZOOM_SPEED = 3.0;
- final boolean BACKGROUND_MORPH = true;
- final int FPS = 30;
- PGraphics canvas;
- PImage prevFrame;
- float zoomSpeed;
- int zoomStepW;
- int zoomStepH;
- float rotation;
- long frames;
- void setup() {
- size(800, 800);
- colorMode(HSB, 100);
- background(0);
- frameRate(FPS);
- canvas = createGraphics(width, height);
- canvas.smooth(4); // set to 2 for better background blur and shitty fps
- updateZoomSpeed(ZOOM_SPEED);
- }
- void updateZoomSpeed(float newZoomSpeed) {
- zoomSpeed = 1 - (newZoomSpeed/100);
- zoomStepW = Math.round((zoomSpeed * width) - width);
- zoomStepH = Math.round((zoomSpeed * height) - height);
- }
- void updateBlur() {
- frames++;
- prevFrame = canvas.copy();
- int offW = zoomStepW;
- int offH = zoomStepH;
- if (BACKGROUND_MORPH) {
- offW += (int)(zoomStepW*cos(rotation*3));
- offH += (int)(zoomStepH*sin(rotation*2));
- }
- prevFrame.resize(width+offW, height+offH);
- if (frames < (FPS*2)) {
- canvas.blendMode(ADD);
- updateZoomSpeed((frames/(FPS*2)) * 5);
- } else if (frames < (FPS*5)) {
- canvas.blendMode(BLEND);
- updateZoomSpeed(5 - ((frames-(FPS*2))/(FPS*4)) * 5);
- } else if (frames < (FPS*6)) {
- canvas.blendMode(DIFFERENCE);
- } else if (frames < (FPS*6.5)) {
- canvas.blendMode(SUBTRACT);
- } else {
- frames = 0;
- }
- canvas.image(prevFrame, offW/2, offH/2, width-offW, height-offH);
- }
- void draw() {
- canvas.beginDraw();
- updateBlur();
- canvas.colorMode(HSB, 100);
- canvas.translate(width/2, height/2);
- canvas.blendMode(BLEND);
- canvas.stroke((50*rotation)%100, 50, 25+50*abs(cos(rotation/2)));
- canvas.strokeWeight(0.01+2*abs(sin(rotation/4)));
- drawCircle(width/10, 8, rotation, 3, width/20);
- canvas.endDraw();
- image(canvas, 0, 0, width, height);
- rotation+=ROTATE_SPEED/100;
- //saveFrame("G:/frames/####.tif");
- }
- void drawCircle(float radius, int steps, float offset, int depth, float size) {
- float rotateStep = (TWO_PI/steps) * (depth % 2 == 0 ? 1 : -1);
- canvas.fill((50*(1+depth)*offset)%100, 100, 100);
- for (int i = 0; i <= steps; i++) {
- canvas.pushMatrix();
- canvas.rotate(offset + rotateStep * i);
- canvas.translate(radius, radius);
- canvas.scale(0.1+abs(2*sin(offset)),0.1+abs(2*cos(offset)));
- canvas.triangle(-size, -size, size, -size, 0, size*2*abs(sin(offset)));
- canvas.popMatrix();
- }
- if (depth > 0) {
- for (int i = 0; i <= steps; i++) {
- canvas.pushMatrix();
- canvas.rotate(offset + rotateStep * i);
- canvas.translate(radius, radius);
- canvas.scale(0.1+abs(2*sin(offset)), 0.1+abs(2*cos(offset)));
- drawCircle(radius, (steps/2 == 0 ? 2 : steps/2), offset*1.25, depth-1, size * 0.5);
- canvas.popMatrix();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement