I'm trying to create a dot that moves around the screen, bounces off the edges, and curves in a random direction every 50 frames or so.
What I've done so for is get a ball to move constantly and bounce off of the screen edges. Please note that this uses PsychoPy:
win = visual.Window(size=(1600, 900), fullscr=False, screen=0, allowGUI=False, allowStencil=False, units='pix',
monitor='testMonitor', colorSpace=u'rgb', color=[0.51,0.51,0.51])
keys = event.BuilderKeyResponse()
dot1 = visual.Circle(win=win, name='dot1',units='pix',
radius=10, edges=32,
ori=0, pos=(0,0),
lineWidth=1, lineColor='red', lineColorSpace='rgb',
fillColor='red', fillColorSpace='rgb',
opacity=1,interpolate=True)
x_change = 10
y_change = 10
while True:
dot1.pos+=(x_change,y_change)
if dot1.pos[0] > 790 or dot1.pos[0] < -790:
x_change = x_change * -1
if dot1.pos[1] > 440 or dot1.pos[1] < -440:
y_change = y_change * -1
dot1.draw()
win.flip()
if event.getKeys(keyList=["escape"]):
core.quit()
I imagine that this will require some trig, which I barely understand. Could anyone point me in the right direction? What variables will I need, and how should they be manipulated?