0% found this document useful (0 votes)
13 views2 pages

Practical 4

The document is a practical assignment for a Computer Graphics and Animation course, detailing a program for the DDA line drawing algorithm using Python's turtle graphics. It includes the code for the algorithm and instructions for user input to draw a line based on specified coordinates. The assignment is submitted by a student named Bhargavi Pradhan with roll number 22032.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Practical 4

The document is a practical assignment for a Computer Graphics and Animation course, detailing a program for the DDA line drawing algorithm using Python's turtle graphics. It includes the code for the algorithm and instructions for user input to draw a line based on specified coordinates. The assignment is submitted by a student named Bhargavi Pradhan with roll number 22032.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name : Bhargavi Pradhan Roll No.

: 22032
Class : SYBSC IT Subject : Computer Graphics and Animation
Sem : IV Date of Performance : 00.00.0000

Practical 4. Solve the following :

a. Develop a program for DDA line drawing algorithm.

Code :
import turtle

def draw_dda_line(x1, y1, x2, y2):


dx = abs(x2 - x1)
dy = abs(y2 - y1)
steps = max(dx, dy)
dx /= steps
dy /= steps
x, y = x1, y1

for _ in range(int(steps) + 1):


turtle.setpos(round(x), round(y))
turtle.dot()
x += dx
y += dy

# Example usage
x1, y1 = map(float, input("Enter the value of x1 and y1 (comma-separated):
").split(','))
x2, y2 = map(float, input("Enter the value of x2 and y2 (comma-separated):
").split(','))

turtle.speed(1)
turtle.hideturtle()
draw_dda_line(x1, y1, x2, y2)
turtle.done()

Output :

You might also like