CG 2
CG 2
tarun
Reg no.:vu22csen0500091
Assignment-01
Digital Differential Analyzer Algorithm:
Algorithm:
Step7: xinc=dx/step
yinc=d
y/
step
assign
x = x1
assign
y = y1
Step8: Set pixel (x, y)
Step9: x
= x + xinc
y=y+
yinc
Set pixels (Round
9 until x = x2 Step11:
End Algorithm
Source Code:
Digital Differential Analyzer (DDA) Line Drawing Algorithm In
Python.
Bresenham's Line Drawing Algorithm:
Algorithm:
Step1: Start Algorithm
Step5: Consider (x, y) as starting point and xend as maximum possible value of
x.
If dx < 0
Then x
= x2 y =
y2
xend=x
1
If dx > 0
Then x =
x 1 y = y1
xend=x2
Step9: Increment x = x + 1
Step11: Go to step 7
Step 1: Get the input of the coordinates for the centre of the circle and radius of the
circle and store them as x, y and R respectively. Initialize two new variables p and q and
set them as P = 0 and Q = R.
Step 4: Call the function of drawing the circle (X, Y, P and Q).
i.e. p1k+1=p1k+2ry²xk+1-2rx²yk+1+ry2
p2_{0}={r_{v}}^{2}(x_{0}+1/2)^{2}+
{r_{x}}^{2}(y_{0}-1)^{2}-{r_{x}}^{2}
{r_{y}}^{2}
i.e. p2k+1=p2k-2rx²yk+1+rx²
Step 1 − Initialize the value of seed point seedx,seedy, fcolor and dcol.
Step 3 − Check if the current seed point is of default color, then repeat the
steps 4 and 5 till the boundary pixels are reached.
Step 6 − Exit
Text Drawing Algorithm:
Algorithm:
Step 1: Initialize
Set the current position to the starting
position (seedx, seedy). Set the fill color
(fcol) and default color (dcol).
Iterate through each character in the text.