• DDA Line Draw Algorithm in Python

    DDA Line Draw Algorithm in Python

    Using DDA Line Draw Algorithm in Python, The DDA [Digital Differential Analyzer] Line Draw Algorithm is used to draw a line between two points having their co-ordinates. This algorithm is converted into python program using python turtle. The user needs to enter co-ordinates for two points and line is graphically drawn into turtle window.

    import turtleDDA Line Draw Output
    import math
    import time

    # Prompt the user for inputting two points
    x1, y1 = eval(input(“Enter x1 and y1 for point 1: “))
    x2, y2 = eval(input(“Enter x2 and y2 for point 2: “))
    # DDA Line Draw Algorithm
    dx = abs(x2 – x1)
    dy = abs(y2 – y1)

    length = dx if dx >= dy else dy

    dx = (x2 – x1)/length
    dy = (y2 – y1)/length

    x = x1
    y = y1

    i=1
    turtle.penup()
    turtle.goto(x1, y1)
    turtle.pendown()
    turtle.write(“Point 1”)

    while(i<=length):

    x = x + dx
    y = y + dy
    i = i + 1
    time.sleep(1)
    turtle.goto(x, y)

    turtle.goto(x2, y2) # Draw a line to (x2, y2)

    turtle.write(“Point 2”)

    turtle.penup()
    turtle.hideturtle()
    turtle.done()

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *