Can I use Anvil for timing reactions in the browser?

Years ago I have built something similar for a neuropsychologist friend of mine.

At the time Anvil didn’t exist yet and I wrote it all in Javascript. Today I would have used Anvil.

The requirements were to display images and animations. Animations could be objects moving on the screen, or objects appearing in one position and disappearing after a certain time. There was a bar displaying the score, and an animated time bar showing the remaining time.

Today in Anvil I would use a canvas to show whatever I need to show, a timer to manage the animations and the canvas’ click events to manage the user interactions. Using time.time() inside the click event is the best way to know what happened when. Here you can see an example of how to use animations and click events in a canvas.

In a simpler scenario, where graphics is not required and some clickable buttons or links in a fixed position would do, then there is no need to deal with canvasses. Using the click events of buttons or links will do.

Here you need 3 things at microsecond precision:

  1. The time.time() implementation needs to be precise enough. I don’t know the details of the implementation in Skulpt, but I’m guessing it’s using whatever Javascript offers under the hood, so, if you are going to use a browser, Anvil will be as good as any other tool.
  2. The browser / computer needs to be responsive. Windows or Linux are not real time operating systems, so you cannot be sure the browser will be listening to you at microsecond precision. It will be there most of the time, but once in a while it will be busy doing something else and some of your click events may be delayed.
  3. The mouse (or input device) needs to be consistent in its response time. I don’t know if you need any special piece of hardware here.

When we developed the old JavaScript app, we considered all of these factors and decided that it was acceptable to have a small amount of noise caused by the imperfect environment.

3 Likes