如何在 Python/PsychoPy 中绘制直角三角形?
How can I draw a right-angled triangle in Python/PsychoPy?
我想在Psychopy中画一个灰色覆盖区域的直角三角形,但我只得到一个等边三角形。它应该覆盖半个正方形。蓝线表示感兴趣的框架。
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#Designed for PsychoPy v1.85.6
from __future__ import unicode_literals
from psychopy import visual, core, event, gui, data
import sys # to get file system encoding
reload(sys)
sys.setdefaultencoding('utf8')
win = visual.Window(fullscr=True, color= '#FFFFFF', monitor ="WorkingSpace", units="deg")
border = visual.Rect(win, width=20,height=20, lineColor='black', lineWidth=5)
diag = visual.Polygon(win, edges=3, radius=11.5, fillColor='#E6E6E6',pos=[-4.2,0], ori =90)
line1 = visual.Line(win, start=(10, -10), end=(-10,10), lineColor="blue", lineWidth=10)
line2 = visual.Line(win, start=(-10, -10), end=(-10,10), lineColor="blue", lineWidth=10)
line3 = visual.Line(win, start=(10, -10), end=(-10,-10), lineColor="blue", lineWidth=10)
border.draw()
diag.draw()
line1.draw()
line2.draw()
line3.draw()
win.flip()
event.waitKeys(keyList=['space']) #press space to continue
win.close()
我正在使用 PsychoPy2 v1.85.6
visual.ShapeStim
怎么样,它可以让您从顶点列表中定义任意形状?这是您示例的修改版本,直角三角形以绿色叠加。
from psychopy import visual, event
# (switched to pixels to avoid monitor setup, note that sizes of things may be
# slightly different)
win = visual.Window(fullscr=True, color='#FFFFFF', units="pix")
verts = [(100, -100), (-100, 100), (-100, -100)]
right_tri = visual.ShapeStim(win, fillColor='green',
vertices=verts, lineColor='green',
opacity=0.5)
border = visual.Rect(win, width=200, height=200,
lineColor='black', lineWidth=5)
line1 = visual.Line(win, start=(100, -100), end=(-100, 100),
lineColor="blue", lineWidth=10)
line2 = visual.Line(win, start=(-100, -100), end=(-100, 100),
lineColor="blue", lineWidth=10)
line3 = visual.Line(win, start=(100, -100), end=(-100, -100),
lineColor="blue", lineWidth=10)
border.draw()
line1.draw()
line2.draw()
line3.draw()
right_tri.draw()
win.flip()
# save a screenshot
win.getMovieFrame()
win.saveMovieFrames('screenshot.png')
event.waitKeys(keyList=['space']) # press space to continue
win.close()
结果:
我想在Psychopy中画一个灰色覆盖区域的直角三角形,但我只得到一个等边三角形。它应该覆盖半个正方形。蓝线表示感兴趣的框架。
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#Designed for PsychoPy v1.85.6
from __future__ import unicode_literals
from psychopy import visual, core, event, gui, data
import sys # to get file system encoding
reload(sys)
sys.setdefaultencoding('utf8')
win = visual.Window(fullscr=True, color= '#FFFFFF', monitor ="WorkingSpace", units="deg")
border = visual.Rect(win, width=20,height=20, lineColor='black', lineWidth=5)
diag = visual.Polygon(win, edges=3, radius=11.5, fillColor='#E6E6E6',pos=[-4.2,0], ori =90)
line1 = visual.Line(win, start=(10, -10), end=(-10,10), lineColor="blue", lineWidth=10)
line2 = visual.Line(win, start=(-10, -10), end=(-10,10), lineColor="blue", lineWidth=10)
line3 = visual.Line(win, start=(10, -10), end=(-10,-10), lineColor="blue", lineWidth=10)
border.draw()
diag.draw()
line1.draw()
line2.draw()
line3.draw()
win.flip()
event.waitKeys(keyList=['space']) #press space to continue
win.close()
我正在使用 PsychoPy2 v1.85.6
visual.ShapeStim
怎么样,它可以让您从顶点列表中定义任意形状?这是您示例的修改版本,直角三角形以绿色叠加。
from psychopy import visual, event
# (switched to pixels to avoid monitor setup, note that sizes of things may be
# slightly different)
win = visual.Window(fullscr=True, color='#FFFFFF', units="pix")
verts = [(100, -100), (-100, 100), (-100, -100)]
right_tri = visual.ShapeStim(win, fillColor='green',
vertices=verts, lineColor='green',
opacity=0.5)
border = visual.Rect(win, width=200, height=200,
lineColor='black', lineWidth=5)
line1 = visual.Line(win, start=(100, -100), end=(-100, 100),
lineColor="blue", lineWidth=10)
line2 = visual.Line(win, start=(-100, -100), end=(-100, 100),
lineColor="blue", lineWidth=10)
line3 = visual.Line(win, start=(100, -100), end=(-100, -100),
lineColor="blue", lineWidth=10)
border.draw()
line1.draw()
line2.draw()
line3.draw()
right_tri.draw()
win.flip()
# save a screenshot
win.getMovieFrame()
win.saveMovieFrames('screenshot.png')
event.waitKeys(keyList=['space']) # press space to continue
win.close()
结果: