Skip to content

Instantly share code, notes, and snippets.

@marcedwards
Created October 20, 2018 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcedwards/28da97e26240b048724679b29433221f to your computer and use it in GitHub Desktop.
Save marcedwards/28da97e26240b048724679b29433221f to your computer and use it in GitHub Desktop.
OLED black smearing test for Processing 3.4
// 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