-
-
Save Slackwise/e7bdb2b935d706b537a352b7f0d0d8af to your computer and use it in GitHub Desktop.
OLED black smearing test for Processing 3.4
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
// OLED black smearing test for Processing 3.4. | |
// Black smearing = changing pixels to and from pure black is slower than changing to and from other colours. | |
// | |
// Code by @marcedwards from @bjango. | |
void setup() { | |
size(360, 360, P2D); | |
frameRate(60); | |
smooth(8); | |
noStroke(); | |
} | |
void draw() { | |
background(0); | |
float ypos = easeInOutSin(easeTriangle(timeCycle(40))) * 140; | |
fill(40); | |
rect(100, ypos + 30, 160, 160); | |
fill(200); | |
rect(130, ypos + 60, 100, 100); | |
//render(40); | |
} | |
float timeCycle(int totalframes, int offset) { | |
return float((frameCount + offset) % totalframes) / float(totalframes); | |
} | |
float timeCycle(int totalframes) { | |
return timeCycle(totalframes, 0); | |
} | |
float easeTriangle(float t) { | |
return t<0.5 ? t*2 : 2-(t*2); | |
} | |
float easeInOutSin(float t) { | |
return 0.5+sin(PI*t-PI/2)/2; | |
} | |
void render(int frames, String foldername) { | |
saveFrame(foldername + "/frame####.png"); | |
if (frameCount == frames) { | |
exit(); | |
} | |
} | |
void render(int frames) { | |
render(frames, "render"); | |
} | |
void render(String foldername) { | |
render(100, foldername); | |
} | |
void render() { | |
render(100, "render"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment