Search code examples
pythonmathrotationvpython

Rotation Slider in Python Fails


Goal:

My goal is to rotate the white line as you change the slider value. But it doesn't work! Please assist. Image: Rotation Slider

Effort:

Things I've tried:

  • Drawing white line as a curve and rotating the curve with rotate method
  • Drawing white line as an arrow and rotating arrow with rotate method
  • Establishing a frame f and appending white line to frame and rotating the frame
  • Using a for loop to continually update the angle of the line.

Please assist.

Code: Rotation Slider

Relevant Lines:

c = curve(pos = [vector(-10,0,0),vector(10,0,0)], radius = 0.3)

def setspeed(s):
    wt.text = '{:1.0f}'.format(s.value)
    
sl = slider(min=0, max=360, step = 10, value = 45, bind=setspeed)

wt = wtext(text='{:1.2f}'.format(sl.value))

c.rotate(angle=sl.value, axis = vector(0,0,1), origin = vector(0,0,0))

Solution

  • It looks like the problem is that the rotate function expects angles in radians, not degrees, so you would say angle=radians(sl.value).