I would like to know how to draw a line using the x and y coordinates of two 2-dimensional points. I tried the turtle graphics, but it works using degrees.
Depending of your needs for plotting you can use matplotlib
import matplotlib.pyplot as plt
plt.plot([x1,x2],[y1,y2])
plt.show()
I tried the turtle graphics, but it works using degrees.
Your premise doesn't hold -- turtle can do it, no degrees needed:
import turtle
point1 = (50, 100)
point2 = (150, 200)
turtle.penup()
turtle.goto(point1)
turtle.pendown()
turtle.goto(point2)
turtle.hideturtle()
turtle.exitonclick()
You could make use of pygame depending on what you are doing it for as it allows a similar:
line(Surface, color, (x1,y1), (x2,y2), width)
For Example, when the environment has been set up:
pygame.draw.line(screen, (255,0,255), (20,20), (70,80), 2)
can draw:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With