Why not? It will be much easier than creating your own from scratch (because PsychoJS stimuli already know where to draw themselves to). Simply create as many polygons as you need, set their locations etc, and draw them. API here:
https://psychopy.github.io/psychojs/module-visual.Polygon.html
Although I would suggest that you just create the required number of polygons once per trial, rather than create them and draw them at the same time. Depending on timing (e.g. if you want them visible for the whole duration of the trial), you could create them just once and set their autodraw
property to true
. Otherwise, separate the creation and drawing into separate functions.
There’s more than one way to skin a cat, of course. Instead of creating multiple polygon stimuli, you can just create one and then draw it at each of a number of locations. Using this approach, you could even use a Builder polygon stimulus component, rather than creating your own in code.