[Python] Why doesn't my code check for angles at certain increments?

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to detect whether or not the mouse position is at a certain angles, given a centre to rotate around , but it is not working completely.

    radius = 110#px
    angle = math.pi /2
    step=0

    while True:
    x= radius * math.cos((angle))
    y = radius * math.sin((-angle))
    win32api.SetCursorPos((int( x+xcentre),int(y+ycentre)))

    if angle >= 2*math.pi + math.pi/2:
    break
    degrees_angle=int(math.degrees(angle))
    mx,my = pyautogui.position()
    print(degrees_angle)
    if (degrees_angle - 90)%cycles==0:
    print("found")
    pyautogui.mouseDown(button='left')
    position_list.append(mx)
    position_list.append(my)
    time.sleep(1)

    angle+=0.1


    At the moment it starts at the top and rotates counter clockwise. To remove ambiguity cycles=4. But right now it only found twice at 0 and 180 rather than 4 times which should be at 0,90,180 and 270 degrees. Does anyone know what I did wrong?

    Continue reading...

Compartilhe esta Página