Guest User

Untitled

a guest
Jul 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // A loading spinner.
  2. // By @marcedwards from @bjango.
  3.  
  4. void setup() {
  5. size(300, 300, P2D);
  6. frameRate(30);
  7. smooth(8);
  8. noFill();
  9. stroke(255);
  10. strokeWeight(6);
  11. }
  12.  
  13. void draw() {
  14. background(29);
  15. drawArc(8);
  16. }
  17.  
  18. void drawArc(int endoffset) {
  19. float a = easeInOutN(timeCycle(40, 0 ), 4);
  20. float b = easeInOutN(timeCycle(40, endoffset ), 5);
  21. float r = timeCycle(40, 0);
  22.  
  23. if (a > b) {
  24. b++;
  25. }
  26.  
  27. pushMatrix();
  28. translate(width / 2, height / 2);
  29. rotate(TAU * 0.75);
  30. arc(0, 0, 100, 100,
  31. a * TAU * 0.8 + r * TAU * 0.2 - 0.3,
  32. b * TAU * 0.8 + r * TAU * 0.2 + 0.3
  33. );
  34. popMatrix();
  35. }
  36.  
  37. float easeInOutN(float t, float power) {
  38. return t<0.5 ? 0.5*pow(2*t, power) : 1-0.5*pow(2*(1-t), power);
  39. }
  40.  
  41. float timeCycle(int totalframes, int offset) {
  42. return float((frameCount + offset) % totalframes) / float(totalframes);
  43. }
Add Comment
Please, Sign In to add comment