Controlled Randomization?
HI!
I'm a super beginner to coding and opensesame! For my experiment, I need to define the areas on the screen (excluding the center and corners) in which the stimulus will appear on random locations. I also want to be able to record the relative distance of the stimulus appearance to later look at. How do I accomplish this?
Thank you in advance!
Comments
Hi,
There are many, many ways to do that.
First of all, if you are a super beginner, I recommend that you finish a few tutorials before you tackle your problems. This will make your life so much easier in the future and even though it will take some extra time now, you'll save much more time later.
You can start with the Opensesame tutorial to get familiar with the interface and the structure:
https://osdoc.cogsci.nl/3.2/tutorials/beginner/
and can also have a look at some basic Python tutorials (there are soo many out there!):
https://python.cogsci.nl/
One approach could be to define areas that you want to exclude, and then randomly sample x,y positions and check whether they fall in that area. Here an example for how you would exclude the central 100 pixels around fixation (in a box shape, if you want a circular shape, you should use the distance between the middle of the sphere and the sampled position)
Distance can easily be computed with Pythagoras. For two points (x1,y1 and x2,y2) you square the difference between the x coordinates and add it with the squared distance of the y-coordinates and, finally, take the square root of that sum (
sqrt((x1-x2)^2 + (y1-y2)^2)). You can write this code yourself or use existing functions, e.g. hypot in themathlibrary.I hope this will get you started.
Eduard