Controlling Speed of a Moving Canvas
in OpenSesame
Hi all,
I have a script that practically create a circle and move it in a certain angle.
import numpy
my_canvas = canvas()
BigR = 150
SmallR = BigR*5/6
xTiny0 = 0.01
yTiny0 = SmallR+((BigR-SmallR)/2)
RTiny = (BigR-SmallR)/1.5
RES = 200 # step resolution
TIME =1# seconds
R = yTiny0 # Circle radius
def move_by_angle(origin, angle, r):
alpha = numpy.arctan(origin[1] / origin[0])
angle_step = angle/RES
path = []
for point in range(0, RES):
beta = alpha + point*angle_step
path.append ([r*numpy.sin(beta), r*numpy.cos(beta)])
return path
start = [yTiny0,xTiny0] * R
angle = numpy.pi*-0.5
path = move_by_angle(start, angle, R)
for step in range(0, RES):
xTiny0, yTiny0 = path[step][0], path[step][1]
TinyCircle = my_canvas.circle(xTiny0, yTiny0, RTiny, fill=True, color= '#404040')
my_canvas.show()
my_canvas.clear()
Though it works, my limited experience with programming is facing me with a problem. My problem is that the moving circle has sort of "innate speed"; it seems like the last "for" loop enforce the circle a speed that i'm not sure how to control. My goal is to determine or measure the speed and to change it according to a certain radius or angle.
Can anyone help me with that?
Thanks
Comments
Hi,
If you use the psycho or xpyriment backend, the display presentation will be locked to the refresh rate. That is, if your refresh rate is 60Hz, then
my_canvas.show()
will be executed 60 times per second. (Or less if you're doing very time-consuming things in between, but I doubt that's a problem here. But never more!)So the steps would be to:
my_canvas.show()
to verify that it's indeed tracking the refresh rateRES
.By the way, your trigonometry seems correct, but not particularly elegant. Here you can see a more Pythonic approach:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you so much!!!