From 6ce18d625c276ca568298adc2981c3352a2b1b98 Mon Sep 17 00:00:00 2001 From: Muskan Kumari <54639539+Code414@users.noreply.github.com> Date: Fri, 1 Oct 2021 23:23:31 +0530 Subject: [PATCH] Created Bresenham's Line Drawing ALgorithm,py file --- BresenhamLineDrawingALgorithm,py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 BresenhamLineDrawingALgorithm,py diff --git a/BresenhamLineDrawingALgorithm,py b/BresenhamLineDrawingALgorithm,py new file mode 100644 index 0000000..6414afc --- /dev/null +++ b/BresenhamLineDrawingALgorithm,py @@ -0,0 +1,39 @@ +#Bresenham's Line Drawing Algorithm + +#In this,x1,y1 should be less than x2,y2 and m<1 +import turtle as t + +x1 = float(input("x-coordinate: ")) +y1 = float(input("y-coordinate: ")) + +x2 = float(input("x-coordinate: ")) +y2 = float(input("y-coordinate: ")) + +dx = x2 - x1 +dy = y2 - y1 +screen = t.Screen() + +p = t.Turtle() +p.shapesize(0.3) + +p.speed("fastest") +p.shape("circle") + +e = 2*dy - dx + +p.penup() +p.goto(int(x1), int(y1)) +p.pendown() + +for i in range(int(dx)): + x1 += 1 + if e < 0: + e += 2*dy + + else: + e += 2 * dy - 2 * dx + y1 += 1 + + p.goto(int(x1), int(y1)) + +screen.exitonclick()