psychopy.org | Reference | Downloads | Github

Drawing oval and positioning shapes within a window

Beginner to python and psychopy! I am designing a sort of computer game with player icons of geometric shapes and an oval-shaped table that the players “sit” around. I can find info online about drawing circles, but I’m not sure how to crate one with two vertices so it makes an oval. One source said to change the units to ‘norm’ instead of ‘pix’ so that the circle would stretch to fit the screen size, but that didn’t work for me.
I also need to position the shapes in specific places within the window I created earlier in my code, but can’t figure out how to do that. Here’s my code for these below.

table = visual.Circle(
win=win,
units=‘norm’,
radius=150,
edges=200,
fillColor=[0, 100, 0],
lineColor=[-1, -1, -1])
table.draw()

p1_icon = visual.Rect(
win=win,
units=‘pix’,
width=50,
height=80,
fillColor=[0, 163, 240],
lineColor=[0, 163, 240])
p1_icon.draw()

p2_icon = visual.Polygon(
win=win,
units=‘pix’
edges=3,
radius=5
fillColor=[255, 255, 0],
lineColor=[255, 255, 0])
p2_icon.draw()

p3_icon = visual.Circle(
win=win,
units=‘pix’,
radius=60,
fillColor=[255, 0, 0],
lineColor=[255, 0, 0])
p3_icon.draw()

Thanks for the help!

Hi there,

For general points on how to draw things in particular places, you might want to start with PsychoPy’s own tutorial:

https://www.psychopy.org/coder/tutorial1.html

And also Damien Mannion’s tutorial:

https://www.djmannion.net/psych_programming/vision/draw_shapes/draw_shapes.html

In general though, it is the “pos” (position) argument which controls positioning - it requires coordinates in whatever units you designated when you created the window. See here for more detail on units. Most, if not all stimuli objects have this argument.

To get an oval, it’s probably easiest to generate a Grating stim and set the size to something rectangular. Then, set the “mask” argument to “circle”, and you will have an ellipse with the same height and width of the rectangular dimensions you set. The code below should get you started!

win = visual.Window(size=[800, 800], fullscr=False, units="pix")

# "size" in pixels is narrower than it is tall (a rectangle).
# "pos" is "(0,0)" - the centre of the screen.

ellipse = visual.GratingStim(win, tex=None, mask='circle', size=(300,600), \
                                      color=(1,1,1), pos=(0,0), texRes = 1024)

ellipse.draw()

win.flip()

And welcome to PsychoPy and Python!

1 Like