psychopy.org | Reference | Downloads | Github

How to draw a pacman shape?

Hello! I’m trying to draw a pacman or pie shape (e.g., removing 1/4 of the entire circle like this). I’ve been searching for an answer but had no luck so far. Is there a way to specify such a property of a circle using a function like visual.Circle()? Thanks in advance!

Reading through this thread might help:

https://groups.google.com/forum/#!topic/psychopy-users/j6m8YlVVeuc

Hello Michael,

I’m so sorry for the late reply! I’ll read the thread and try solving the problem!

Thank you so much for your time and kindness.

Best,
Takashi

Thanks to Michael’s help, I was able to draw a pacman shape using the codes below.


#specifying the screen height/width ratio to correct circle's distortion
wide = 1920
high = 1200
display = 0
visual_angle = 1.5

win = visual.Window(fullscr=True, screen = 0, allowGUI=False, waitBlanking=True)

win_ratio = high/wide
circle_size = round(0.18*(1/2.5),2)*visual_angle

wedge = visual.RadialStim(win, tex='None', color=1, size=[circle_size*win_ratio, circle_size], 
    angularRes=360, visibleWedge=[0, 270], interpolate=False,
    autoLog=False, ori=0)

wedge.draw()
win.flip()

The next thing I have to do is to rotate the pacman shape (wedge). The first thing I tried was to change the starting and ending angles in visibleWedge=[0, 270]. However, it does not work when the ending angle is passed 360. For example, if I entered something like visibleWedge=[135, 405] to rotate the figure 135 degrees, I will get this shape which is not what I want.

On the other hand, when I try to rotate the wedge by entering ori=135, the whole shape gets distorted like this due to the screen height/width ratio.

I would very much appreciate it if anyone could suggest any possible ways to solve this dilemma – i.e., to rotate the pacman shape without distortion. Thank you so much for your time and kindness.

Best,
Takashi

1 Like

Dear Takashi,

Well done on solving this. To rotate the PacMan, you should indeed just create the stimulus once and then simply alter its .ori attribute as required.

I would guess that the distortion you are seeing is due to using the default “norm” units system for your window and stimuli. This means that both the height and width of the monitor are scaled to equal 2.0. You can instead use “height” units if you want normalised coordinates that account for the aspect ratio of the display. i.e. the height of the window is still scaled to 2.0, but the width is scaled relative to that (generally a larger value) so that stimuli with equal dimensions display as circles/squares rather than as ellipses/rectangles. Or you can use explicit units like pixels, degrees, cm, etc:

https://www.psychopy.org/general/units.html

Dear Michael,

Thank you so much for your further help! Correcting the unit worked perfectly :slight_smile: I put the revised line for everyone’s reference.

wedge = visual.RadialStim(win, tex='None', color=1, units='height', size=[circle_size, circle_size], 
    angularRes=360, visibleWedge=[0, 270], interpolate=False,
    autoLog=False, ori=135)

I truly appreciate your kindness!

Best,
Takashi

1 Like

Dear Michael,

I’m sorry, now I have an additional question.

If I want to draw an open circle like this, what is the best way to do it?

With my current knowledge (I got the idea from here), I can do so by superimposing a circle. However, when I use the lines below, I get some unwanted line like this.

wedge = visual.RadialStim(win, tex='None', color=1, units='height', size=[0.5, 0.5], 
    angularRes=360, visibleWedge=[0, 270], interpolate=False,
    autoLog=False, ori=135)

circle = visual.Circle(win, units='height', size=[0.4, 0.4], fillColor=0)

I would very much appreciate it if you could share some possible tip. Thank you so much for your time!

Best,
Takashi

I guess you should also set the lineColor attribute of your circle stimulus.

Dear Michael,

Thank you so much for your reply! It worked perfectly :slight_smile:

Best,

Takashi