Lab Report 1
Lab Report 1
Bandarban University
Department of Computer Science and Engineering
Course Name: Computer Graphics
Lab Report-1
Submission: 16/10/2022
Submitted to:
Mr. Sultan Mahmud
Lecturer (Adjunct)
Department of Computer Science and Engineering
Bandarban University
Submitted by:
Uhai Mong Marma
ID: 15032004
Semester: 6th
Department of Computer Science and Engineering
Bandarban University
2
Table of Context
List of Problem: Page:
1. Write a program to generate Bresenham’s Line Draw 3
2. A program to generate of the Digital Differential Analyzer(DDA) Line Draw 5
3. Write a program to generate of the Midpoint Circle Draw 7
4. Write a program to generate of Translating an Object 9
Algorithm:
1. Input two line endpoint.
2. Calculate the constants dx = x2-x1,dy = y2-y1,i1 = 2*dy,i2= 2*(dy-dx), d = i1 –dx.
Program:
1. #include <iostream>
2. #include<graphics.h>
3. #include<stdio.h>
4. #include<conio.h>
5.
6. void drawline(int x1,int y1, int x2, int y2)
7. {
8. int dx,dy,p,x,y;
9.
10. dx = x2-x1;
11. dy = y2-y1;
12.
13. x = x1;
14. y = y1;
15.
16. p = 2*(dy-dx);
17.
18. while(x<x2)
19. {
20. if(p>=0)
21. {
22. putpixel(x,y,7);
23. y = y +1;
24. p = p + 2 * dy -2 * dx;
25. }
26. else
27. {
28. putpixel(x,y,7);
29. p = p + 2 * dy;
30. }
31. x = x + 1;
32. }
33. }
4
34.
35. main()
36. {
37. int gd = DETECT, gm, error,x1,y1,x2,y2;
38. initgraph(&gd,&gm,"");
39.
40. printf("Please Enter the first Co-ordinates point: \n");
41. scanf("%d%d",&x1,&y1);
42.
43. printf("Please Enter the second Co-ordinates point: \n");
44. scanf("%d%d",&x2,&y2);
45.
46. drawline(x1,y1,x2,y2);
47.
48. getch();
49.
50.
51. }
Outpute:
Result: The Bresenham’s Line drawing is successful. The output picture is generated.
5
31.
32. dx = dx/step;
33. dy = dy/step;
34.
35. x = x1;
36. y = y1;
37.
38. i = 1;
39. while(i<=step)
40. {
41. putpixel(x,y,5);
42. x = x+dx;
43. y = y+dy;
44. i = i+1;
45. }
46. getch();
47. }
Output:
Result: The DDA Line drawing is successful. The output picture is generated.
7
30. if(err>0)
31. {
32. x-=1;
33. err-=2*x+1;
34. }
35. }
36. }
37.
38. main()
39. {
40. int gd = DETECT,gm,error,x,y,r;
41. initgraph(&gd,&gm,"");
42.
43. printf("PLease Enter the radius of Circle: \n");
44. scanf("%d",&r);
45.
46. printf("Please Enter the co-ordinate of center x and y: \n");
47. scanf("%d%d",&x,&y);
48. drawcircle(x,y,r);
49.
50. getch();
51. }
Output:
Result: The Midpoint circle drawing is successful. The output picture is generated.
9
Output:
40. //floodfill(199,79,YELLOW);
41.
42. //drawing the school.
43.
44. line(50,150,500,150);
45. line(0,200,50,150);
46. line(50,150,100,200);
47. line(500,150,550,200);
48. line(0,200,550,200);
49. line(60,160,20,200);
50. //body
51. rectangle(20,200,530,270);
52. line(100,200,100,290);
53. //door
54. rectangle(180,210,220,270);
55. //under part
56. setcolor(DARKGRAY);
57. setfillstyle(LTSLASH_FILL,DARKGRAY);
58. rectangle(20,270,530,290);
59. floodfill(21,271,DARKGRAY);
60. //window
61. setcolor(CYAN);
62. setfillstyle(LTBKSLASH_FILL,CYAN);
63. rectangle(270,220,300,250);
64. floodfill(271,221,CYAN);
65.
66. setcolor(CYAN);
67. setfillstyle(LTBKSLASH_FILL,CYAN);
68. rectangle(350,220,380,250);
69. floodfill(351,221,CYAN);
70.
71. setcolor(CYAN);
72. setfillstyle(LTBKSLASH_FILL,CYAN);
73. rectangle(430,220,460,250);
74. floodfill(431,221,CYAN);
75.
76. //sign board
77. rectangle(30,220,90,250);
78. //text
79. outtextxy(40,230,"School");
80.
81. //flag pillar
82. rectangle(110,100,120,340);
13
83. rectangle(100,340,130,350);
84. rectangle(90,350,140,360);
85.
86. //flag
87. setcolor(GREEN);
88. setfillstyle(SOLID_FILL,GREEN);
89. rectangle(120,100,200,140);
90. floodfill(121,101,GREEN);
91. setcolor(RED);
92. setfillstyle(SOLID_FILL,RED);
93. circle(160,120,15);
94. floodfill(161,121,RED);
95.
96. //School road left side
97. setcolor(LIGHTGRAY);
98. line(180,300,180,340);
99. line(180,340,140,380);
100. line(140,380,60,390);
101.
102. //School road right side
103. line(220,300,220,340);
104. line(220,340,180,390);
105. line(180,390,80,450);
106.
107. //Grass
108. setcolor(GREEN);
109. setfillstyle(SOLID_FILL,GREEN);
110. line(300,350,270,400);
111. line(300,350,330,400);
112. line(270,400,330,400);
113. floodfill(290,390,GREEN);
114.
115. setcolor(YELLOW);
116. setfillstyle(SOLID_FILL,YELLOW);
117. rectangle(290,400,310,450);
118. floodfill(291,401,YELLOW);
119.
120. //Text
121. setcolor(CYAN);
122. outtextxy(100,460,"Art by Uhai");
123. getch();
124. }
14
Output: