Guest User

Untitled

a guest
Oct 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // OLED black smearing test for Processing 3.4.
  2. // Black smearing = changing pixels to and from pure black is slower than changing to and from other colours.
  3. //
  4. // Code by @marcedwards from @bjango.
  5.  
  6. void setup() {
  7. size(360, 360, P2D);
  8. frameRate(60);
  9. smooth(8);
  10. noStroke();
  11. }
  12.  
  13. void draw() {
  14. background(0);
  15.  
  16. float ypos = easeInOutSin(easeTriangle(timeCycle(40))) * 140;
  17.  
  18. fill(40);
  19. rect(100, ypos + 30, 160, 160);
  20.  
  21. fill(200);
  22. rect(130, ypos + 60, 100, 100);
  23.  
  24. //render(40);
  25. }
  26.  
  27. float timeCycle(int totalframes, int offset) {
  28. return float((frameCount + offset) % totalframes) / float(totalframes);
  29. }
  30.  
  31. float timeCycle(int totalframes) {
  32. return timeCycle(totalframes, 0);
  33. }
  34.  
  35. float easeTriangle(float t) {
  36. return t<0.5 ? t*2 : 2-(t*2);
  37. }
  38.  
  39. float easeInOutSin(float t) {
  40. return 0.5+sin(PI*t-PI/2)/2;
  41. }
  42.  
  43. void render(int frames, String foldername) {
  44. saveFrame(foldername + "/frame####.png");
  45. if (frameCount == frames) {
  46. exit();
  47. }
  48. }
  49.  
  50. void render(int frames) {
  51. render(frames, "render");
  52. }
  53.  
  54. void render(String foldername) {
  55. render(100, foldername);
  56. }
  57.  
  58. void render() {
  59. render(100, "render");
  60. }
Add Comment
Please, Sign In to add comment