Created
July 11, 2015 15:09
-
-
Save dgellow/cec413b61f1b8dab9d9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import times | |
const | |
speed = 1000 | |
iterator deltat(): int {.closure.} = | |
var | |
t0: float = epochTime() | |
t1: float | |
while true: | |
t1 = epochTime() | |
yield ((t1 - t0) * 1_000).toInt() | |
t0 = t1 | |
iterator nextframe(): bool {.closure.} = | |
let | |
genDeltaT = deltat | |
var | |
accTime: int = 0 | |
while true: | |
accTime += genDeltaT() | |
if accTime >= speed: | |
yield true | |
accTime = 0 | |
else: | |
yield false | |
var | |
genNextFrame = nextframe | |
while true: | |
if genNextFrame(): | |
echo "FINISH" | |
quit() | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment