-
-
Save citrusui/79622edf65251b01e8834949162fd113 to your computer and use it in GitHub Desktop.
A loading spinner for Processing 3.3.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment