Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A loading spinner.
- // By @marcedwards from @bjango.
- void setup() {
- size(300, 300, P2D);
- frameRate(30);
- smooth(8);
- noFill();
- stroke(255);
- strokeWeight(6);
- }
- void draw() {
- background(29);
- drawArc(8);
- }
- void drawArc(int endoffset) {
- float a = easeInOutN(timeCycle(40, 0 ), 4);
- float b = easeInOutN(timeCycle(40, endoffset ), 5);
- float r = timeCycle(40, 0);
- if (a > b) {
- b++;
- }
- pushMatrix();
- translate(width / 2, height / 2);
- rotate(TAU * 0.75);
- arc(0, 0, 100, 100,
- a * TAU * 0.8 + r * TAU * 0.2 - 0.3,
- b * TAU * 0.8 + r * TAU * 0.2 + 0.3
- );
- popMatrix();
- }
- float easeInOutN(float t, float power) {
- return t<0.5 ? 0.5*pow(2*t, power) : 1-0.5*pow(2*(1-t), power);
- }
- float timeCycle(int totalframes, int offset) {
- return float((frameCount + offset) % totalframes) / float(totalframes);
- }
Add Comment
Please, Sign In to add comment