Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Original code by Jerome Herr found at
- // http://p5art.tumblr.com/post/120693457458/ellipsorect-code
- // Bouncy effect by aBe, using Penner's easing equation
- int num = 240, dotsSide = num/4, spaceBetween = 5, counter, frames = 180, toSave = 0;
- float x, y, radius, sz = 2;
- PVector[] dotsRect = new PVector[num];
- PVector[] dotsCircle = new PVector[num];
- void setup() {
- size(540, 540);
- background(0);
- fill(255);
- noStroke();
- for (int j=1; j<=4; j++) {
- for (int i=0; i<dotsSide; i++) {
- switch (j) {
- case 1:
- x = i*spaceBetween;
- y = 0;
- break;
- case 2:
- x = dotsSide*spaceBetween;
- y = i*spaceBetween;
- break;
- case 3:
- x = dotsSide*spaceBetween - i*spaceBetween;
- y = dotsSide*spaceBetween;
- break;
- case 4:
- x = 0;
- y = dotsSide*spaceBetween - i*spaceBetween;
- break;
- }
- dotsRect[counter] = new PVector(x, y);
- counter++;
- }
- }
- radius = (dotsSide*spaceBetween)/2;
- for (int i=0; i<num; i++) {
- x = radius + cos(PI+PI/4+TWO_PI/num*i)*radius*.8;
- y = radius + sin(PI+PI/4+TWO_PI/num*i)*radius*.8;
- dotsCircle[i] = new PVector(x, y);
- }
- }
- void draw() {
- background(0);
- translate((width-2*radius)/2, (width-2*radius)/2);
- for (int i=0; i<num; i++) {
- float a = dotsCircle[i].heading();
- float delta = 15 + 15 * cos(a);
- float t = (frameCount + delta) % frames;
- float lerpValue;
- if (t < frames * 0.25) {
- lerpValue = Bounce.easeOut(t, 0, 1, frames*0.25);
- } else if (t < frames * 0.5) {
- lerpValue = 1;
- } else if (t < frames * 0.75) {
- lerpValue = Bounce.easeOut(t-frames*0.5, 1, -1, frames*0.25);
- } else {
- lerpValue = 0;
- }
- PVector newV = PVector.lerp(dotsRect[i], dotsCircle[i], lerpValue);
- ellipse(newV.x, newV.y, sz, sz);
- }
- if(toSave > 0) {
- saveFrame("/tmp/frm#####.gif");
- println(--toSave);
- }
- }
- // https://github.com/jesusgollonet/processing-penner-easing
- public static class Bounce {
- // time, beginning, change, duration
- public static float easeOut(float t, float b, float c, float d) {
- if ((t/=d) < (1/2.75f)) {
- return c*(7.5625f*t*t) + b;
- } else if (t < (2/2.75f)) {
- return c*(7.5625f*(t-=(1.5f/2.75f))*t + .75f) + b;
- } else if (t < (2.5/2.75)) {
- return c*(7.5625f*(t-=(2.25f/2.75f))*t + .9375f) + b;
- } else {
- return c*(7.5625f*(t-=(2.625f/2.75f))*t + .984375f) + b;
- }
- }
- }
- void keyPressed() {
- if(key == 's') {
- toSave = frames;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement