Skip to content

Instantly share code, notes, and snippets.

@shiffman
Created September 11, 2022 17:00
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 shiffman/17190e1e01fd1531e25de30eeeef1576 to your computer and use it in GitHub Desktop.
Save shiffman/17190e1e01fd1531e25de30eeeef1576 to your computer and use it in GitHub Desktop.
Demonstration Faking Non-Double-Buffered Animation
float x = 200;
float y = 150;
float r = 24;
float dx = 16;
float dy = 8;
void setup() {
size(400, 300);
pixelDensity(2);
frameRate(24);
// noLoop();
background(0);
}
void keyPressed() {
if (key == ' ') redraw();
if (key == 's') loop();
}
void mousePressed() {
redraw();
}
void draw() {
if (frameCount % 2 == 0) {
background(0);
} else {
fill(255);
stroke(255);
circle(x, y, r*2);
x += dx;
y += dy;
if (x < r || x > width - r) dx *= -1;
if (y < r || y > height - r) dy *= -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment