Is there a way to draw a semicircle?

616 views
Skip to first unread message

Yunfeng Zhang

unread,
Nov 14, 2013, 5:32:16 PM11/14/13
to psychop...@googlegroups.com
Is there a way to draw semicircles?  I found RadialStim, but it is not what I want.  I need to set its fill color.

Thanks,
Yunfeng

Jeremy Gray

unread,
Nov 14, 2013, 5:44:51 PM11/14/13
to psychop...@googlegroups.com
Hi Yunfen,

There's not a function for this, but if you make a quasi-circle with 128 vertices, you can then set its vertices to be only the first 64, and it becomes a half circle.

In the Builder, make a Polygon component with 128 vertices. Then in a code component, in the "Begin routine" box do:

polygon.vertices = polygon.vertices[:64]

--Jeremy

--Jeremy


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/df1eb3e9-33a5-409d-a403-8bb22f4fe86a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Yunfeng Zhang

unread,
Nov 14, 2013, 7:41:18 PM11/14/13
to psychop...@googlegroups.com
Thanks for the suggestion.  I tried, but it can only create a vertical semicircle no matter what slice I take (e.g., 32:96).  I printed out the vertices, and they are what I expected and should create a horizontal semicircle.  This is really strange.

Yunfeng

Jeremy Gray

unread,
Nov 14, 2013, 7:46:55 PM11/14/13
to psychop...@googlegroups.com
like you, I thought that would have worked. Try changing the orientation (ori) instead, this works for me.

--Jeremy


Yunfeng Zhang

unread,
Nov 14, 2013, 7:53:13 PM11/14/13
to psychop...@googlegroups.com
That worked.  Thanks!  Not sure why this happens though.

Yunfeng

Jeremy Gray

unread,
Nov 15, 2013, 8:35:17 AM11/15/13
to psychop...@googlegroups.com
That worked.  Thanks!  Not sure why this happens though.

I figured it out. There are vertices, but these are relative to the polygon's screen position, and can have the orientation applied to them (to rotate). So the slice was the right slice, but the vertices actually used for drawing were still the old ones. So just tell psychopy to update the vertices after taking the slice and it works as expected:

polygon.vertices = polygon.vertices[32:96]
polygon.needVertexUpdate = True

 

Yunfeng Zhang

unread,
Nov 16, 2013, 1:45:22 PM11/16/13
to psychop...@googlegroups.com
Thanks! I found that if I use setVertices instead of the assignment operator, it works too without rotation.
Reply all
Reply to author
Forward
0 new messages