Home > Back-end >  How to make lines around the origin(will be cursor) in tkinter
How to make lines around the origin(will be cursor) in tkinter

Time:05-03

What I am planning to do is make 360 lines that every one of it points to a different angle and it all will be around the cursor so line 1 will be in angle 1 and line 2 in angle 2 and I want it to be around the cursor

def redraw(event):
    cv.delete("all")
    length = 100
    xorigin = event.x - 250
    yorigin = event.y - 250


    newx = (xorigin - 500)*numpy.cos(45 * numpy.pi / 360)
    newy = (xorigin - 250)*numpy.sin(45 * numpy.pi / 360)
    cv.create_line(xorigin 250,yorigin 250,newx,newy, fill="red")

I've tried to make it one line for testing but the line is not from the angle i want the origin(cursor) kinda broken so basically what I am trying to do: The line at 1°

import numpy, tkinter

root = tkinter.Tk()

canvas = tkinter.Canvas(root)
canvas.pack(expand=True, fill="both")

def cos(degrees):
    return numpy.cos(degrees*(numpy.pi/180))
def sin(degrees):
    return numpy.sin(degrees*(numpy.pi/180))

def redraw(event):
    canvas.delete("all")
    length = 100
    xorigin = event.x
    yorigin = event.y

    # Loop through all the degrees of the circle, drawing a line for each one
    for d in range(0, 360):
        newx = xorigin - (length * cos(d))
        newy = yorigin - (length * sin(d))

        canvas.create_line(xorigin, yorigin, newx, newy, fill="red")

canvas.bind("<Motion>", redraw)

root.mainloop()

Hope this helps, and let me know if you have any questions about this answer!

  • Related