Skip to content

Instantly share code, notes, and snippets.



Last active Jan 28, 2021
What would you like to do?
Red [needs: view]
img: draw 4000x2000 [scale 2 2 fill-pen yello circle 1000x500 1000 500]
lag: object [max: avg: 0.0]
offset: 0x0
plot: []
system/view/auto-sync?: off
view/no-wait [
face: base 500x250 all-over on-over [offset: event/offset]
stats: text 500x25
loop 100 [unless do-events/no-wait [break]]
forever [
compose/deep/into [
scale (face/size/x / img/size/x) (face/size/y / img/size/y) [image img]
pen purple
fill-pen cyan
line (offset * 1x0) (as-pair offset/x face/size/y)
line (offset * 0x1) (as-pair face/size/x offset/y)
shape [move (face/size) line (face/size * 0x1) (plot) 'line (face/size * 0x1) close]
] clear b: []
face/draw: b
wait 0.02
t: dt [
show face
loop 10 [unless do-events/no-wait [break]]
unless face/state [quit]
t: t/second * 1e3
append plot as-pair (length? plot) (t / -1e3 + 1 * face/size/y)
if face/size/x < length? plot [clear plot]
lag/max: max lag/max t
lag/avg: either 0 = lag/avg [t][(lag/avg * 0.99) + (t * 0.01)]
stats/text: form reduce ["Lag max:" copy/part form lag/max 5 "^-avg:" copy/part form lag/avg 5 "ms"]
show stats
loop 10 [unless do-events/no-wait [break]]
unless face/state [quit]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment