sharpie7 / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
2.29k stars 633 forks source link

current dots may appear to reverse direction of movement at high speed due to aliasing with refresh rate #680

Closed ericfont closed 2 years ago

ericfont commented 2 years ago

Take a simple circuit such as a current source feeding connected to a short circuit. Use a slider to control the current's amperage. Wen start to increase the current dots seem fine. However if I cause the current to be high enough to exceed the refresh rate, then the dots appear to be moving in the reverse direction. Even faster and they return to normal or become chaotic.

This is a bit of a problem particularly when the current direction appear to reverse because the user may assume the apparent direction of the dots is the actual behavior of the circuit. Of course the user may reduce current speed, but may not realize this, and reducing current speed changes speed of everything.

Suggestion: maybe use another method to indicate that current speed has exceeded the screen drawing refresh. Maybe put a little warning message. Maybe change the dots into question marks? Maybe draw the current as if it was at the maximum unalised speed (like just below (dot distance)/(refresh rate)), that way they are at the maximum apparent speed...and maybe include a warning message or '?' for the dots...or maybe use '>' or '<' instead of '.' so that the direction of the current is always knowable. Or maybe some other method.

nulldg commented 2 years ago

What if we add motion blur to the dots?

Something like this, which is just the same dots except drawn 4 times at different phases and with different hues and transparencies. Even with the dots being drawn without continuity, it should be more apparent which direction they're going. Additionally, this can be controlled programmatically. image

pfalstad commented 2 years ago

That's what I wanted to do, but the position of the dots is stored simply as a double in hundreds of places, and those would all have to be changed. Unless I encode the dot speed + position somehow in a double, which would be a big hack.

Instead, if the current is too fast, I draw it as a blur with a random dot position. That only requires a minor hack to encode the "too fast" state as a "magic" current position value.