inexorabletash / jslogo

Logo in JavaScript
https://calormen.com/jslogo
Other
368 stars 146 forks source link

Make loops yield less often #107

Closed bojidar-bg closed 6 years ago

bojidar-bg commented 6 years ago

Currently, doing animations which clear the screen every frame would lead to excessive tearing, as the browser redraws before the frame is finished. Example:

hideturtle forever [
  clearscreen
  fd repcount repeat 4 [fd 10 rt 90]
  home bk repcount repeat 4 [fd 10 rt 90]
  wait 1
]
Old (tearing) New (correct)
peek 2018-01-15 14-10 peek 2018-01-15 14-10-2

Note that the old one looks even worse on a real screen than in the gif, since it flickers faster than my screen recorder can capture.

Some more examples that might be useful to test this PR:

; - Old and new are the same in those four examples
forever [ setpos mousepos ]
forever [ clearscreen setpos mousepos ]
forever [ setpos mousepos wait 1 ]
forever [ clearscreen setpos mousepos wait 1 ]
; - New one is much faster than the old one, but experiences hiccups from time to time
fern 25 1
tree 150
; - New one finishes in around 4 seconds, but does not block the UI from responding
clearscreen
repeat 3600 [ randomcolor square random 200 rt 1 ] ; Mind the 3600
bojidar-bg commented 6 years ago

@inexorabletash Did the changes requested.

inexorabletash commented 6 years ago

Looks good - I'll try and test locally and merge tonight when I'm off work.

inexorabletash commented 6 years ago

Thanks again! Additional patches/suggestions very welcome!