-
-
Save shiffman/17190e1e01fd1531e25de30eeeef1576 to your computer and use it in GitHub Desktop.
Demonstration Faking Non-Double-Buffered Animation
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
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