Drawing a tan-wave in paint using pyautogui and math

Viewed 135

I am having a difficulty in implementing drawing a tan function in python since it doesn't look smooth, and when having reached 90/180, it doesn't look nice, so im looking for some improvements on this part.

def tan_wave():
    pyautogui.click()
    theta = 0
    step = 10
    length = 10
    curr_x, curr_y = pyautogui.position()
    prev = (curr_x, curr_y)
    decrease_flag = False
    while theta <= 180:
        if (theta % 90) == 0:
            theta -= 0.99999
            decrease_flag = True
        x = curr_x + theta
        y = curr_y - math.tan(math.radians(theta))*length
        print(x, y, theta)
        pyautogui.click(*prev)
        pyautogui.dragTo(x, y)
        pyautogui.click(x, y)
        prev = (x, y)
        if decrease_flag:
            theta += 0.99999
            decrease_flag = False
        theta += step
    print('Done')

tan_wave()
0 Answers
Related