Skip to content

Instantly share code, notes, and snippets.

@dgellow
Created July 11, 2015 15:09
Show Gist options
  • Save dgellow/cec413b61f1b8dab9d9b to your computer and use it in GitHub Desktop.
Save dgellow/cec413b61f1b8dab9d9b to your computer and use it in GitHub Desktop.
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