Computer Graphics (22318) : Diploma in Computer Technology
Computer Graphics (22318) : Diploma in Computer Technology
GOVERNMENT POLYTECHNIC,
SOLAPUR
COMPUTER GRAPHICS
(22318)
A
MICRO-PROJECT REPORT
ON
Submitted by:
Roll No. 82 – Sharaneshwar Bharat Punjal
Submitted to:
Smt. S. P. Kadam
1
CERTIFICATE
ACKNOWLEDGEMENT
In the accomplishment of this micro-project successfully, many people
have best owned upon me their blessings and heart-privileged support.
Primarily, I would like to express a special thanks of gratitude to the Principal
2
Sir of the Government Polytechnic, Solapur for giving this golden opportunity
with all the required facilities for completing this micro-project of our group.
I would also like to thank my parents who have helped with their valuable
suggestions and provided the required resources needed for the micro-project.
3
ABSTRACT
As a student enrolled in the Government Polytechnic, Solapur, every
semester we require to do a micro-project on any one topic in the syllabus of the
respective subjects. Hence, I have done a micro-project to design rangolis using
computer graphics in C language.
4
INTRODUCTION
In this micro-project, three unique and creative rangoli designs are coded
using computer graphics in C language. This first rangoli is designed using the
2D rotation of square. It consists of 8 squares each rotated at 45 degrees and all
the squares are connected at the centre. The design that gets formed after
drawing these 8 squares is coloured with the help of flood fill algorithm by light
and dark shades of red, cyan, green and magenta. A big circle is also drawn and
coloured with blue colour.
The first rangoli code is of 260 lines, second rangoli code is of 140 lines
and the third rangoli code is of 60 lines.
5
REVIEW OF CONCEPTS
A short review of the important algorithms of computer graphics in C that
are used in this micro-project is here.
Now to draw the circle for a given radius ‘r’ and centre (xc, yc) We will
start from (0, r) and move in first quadrant till x=y (i.e. 45 degree). We should
start from listed initial condition:
d = 3 - (2 * r)
x=0
y=r
6
1. Set initial values of (xc, yc) and (x, y)
2. Set decision parameter d to d = 3 – (2 * r).
3. call drawCircle(int xc, int yc, int x, int y) function.
4. Repeat steps 5 to 8 until x < = y
5. Increment value of x.
6. If d < 0, set d = d + (4 * x) + 6
7. Else, set d = d + 4 * (x – y) + 10 and decrement y by 1.
8. call drawCircle(int xc, int yc, int x, int y) function
7
2. FLOOD FILL ALGORITHM –
In this method, a point or seed which is inside region is selected. This
point is called a seed point. Then four connected approaches or eight connected
approaches is used to fill with specified color.
The flood fill algorithm has many characters similar to boundary fill. But
this method is more suitable for filling multiple colors boundary. When
boundary is of many colors and interior is to be filled with one color we use this
algorithm.
In fill algorithm, we start from a specified interior point (x, y) and
reassign all pixel values are currently set to a given interior color with the
desired color. Using either a 4-connected or 8-connected approaches, we then
step through pixel positions until all interior points have been repainted.
8
computer graphics programs. The rangolis which we used to draw manually are
now being created with the help of computer graphics in C language.
HARDWARE REQUIREMENTS -
Laptop or PC or Mobile with Basic Configurations.
SOFTWARE REQUIREMENTS -
1. Operating System (Windows family)
2. IDE for C language (Turbo C, Visual Studio Code, Dev C++, etc.)
3. Text Editor
9
C PROGRAM CODE
- RANGOLI 01 -
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main()
{
int gd = DETECT, gm, diagonal_distance, i;
int square[5][2] = {{320, 240}, {320 + 100, 240}, {320 + 100,
240 + 100}, {320, 240 + 100}, {320, 240}};
int sq_rotated[5][2] = {0};
diagonal_distance = calculate_distance(square[0][0], square[0]
[1], square[2][0], square[2][1]);
10
// 1st square
draw_square(square);
delay(500);
// 2nd square
copy_square(&sq_rotated[0][0], square);
rotate_square_x(&sq_rotated[0][0], diagonal_distance);
draw_square(sq_rotated);
delay(500);
// 3rd square
reflect_square_x(&square[0][0]);
draw_square(square);
delay(500);
// 4th square
copy_square(&sq_rotated[0][0], square);
rotate_square_y(&sq_rotated[0][0], diagonal_distance);
draw_square(sq_rotated);
delay(500);
// 5th square
reflect_square_y(&square[0][0]);
draw_square(square);
delay(500);
// 6th square
copy_square(&sq_rotated[0][0], square);
rotate_square_x2(&sq_rotated[0][0], diagonal_distance);
draw_square(sq_rotated);
delay(500);
// 7th square
reflect_square_x2(&square[0][0]);
draw_square(square);
delay(500);
// 8th square
copy_square(&sq_rotated[0][0], square);
rotate_square_y2(&sq_rotated[0][0], diagonal_distance);
draw_square(sq_rotated);
delay(500);
// Filling objects
setfillstyle(1, MAGENTA);
floodfill(330, 290, WHITE);
delay(500);
setfillstyle(1, LIGHTMAGENTA);
floodfill(380, 250, WHITE);
11
delay(500);
setfillstyle(1, CYAN);
floodfill(410, 230, WHITE);
delay(500);
setfillstyle(1, LIGHTCYAN);
floodfill(330, 190, WHITE);
delay(500);
setfillstyle(1, GREEN);
floodfill(310, 220, WHITE);
delay(500);
setfillstyle(1, LIGHTGREEN);
floodfill(270, 230, WHITE);
delay(500);
setfillstyle(1, RED);
floodfill(230, 250, WHITE);
delay(500);
setfillstyle(1, LIGHTRED);
floodfill(310, 280, WHITE);
delay(500);
setfillstyle(1, BLUE);
floodfill(410, 330, WHITE);
floodfill(410, 150, WHITE);
floodfill(230, 150, WHITE);
floodfill(230, 330, WHITE);
floodfill(430, 240, WHITE);
floodfill(330, 130, WHITE);
floodfill(210, 240, WHITE);
floodfill(310, 350, WHITE);
// Outside circle
delay(500);
BresenhamCircle(320, 240, 200);
delay(500);
setfillstyle(1, LIGHTBLUE);
floodfill(420, 345, WHITE);
delay(500);
getch();
closegraph();
}
12
putpixel(x + xc, y + yc, getcolor());
putpixel(x + xc, -y + yc, getcolor());
putpixel(-x + xc, -y + yc, getcolor());
putpixel(-x + xc, y + yc, getcolor());
putpixel(y + xc, x + yc, getcolor());
putpixel(y + xc, -x + yc, getcolor());
putpixel(-y + xc, -x + yc, getcolor());
putpixel(-y + xc, x + yc, getcolor());
}
13
flood_fill(x - 1, y + 1, n, o);
}
}
14
*(sq + 4) = *(sq)-dis;
*(sq + 5) = *(sq + 1);
*(sq + 6) = *(sq + 2);
*(sq + 7) = *(sq + 3) - dis;
}
15
void draw_square(int square[5][2])
{
int i;
for (i = 0; i < 4; i++)
line(square[i][0], square[i][1], square[i + 1][0], square[i
+ 1][1]);
}
- RANGOLI 02 -
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
void main()
{
int gd = DETECT, gm, i;
initgraph(&gd, &gm, "C:\\TC\\BGI");
delay(500);
setfillstyle(1, DARKGRAY);
floodfill(1, 1, WHITE);
delay(500);
outtextxy(280, 10, "RANGOLI 02");
delay(500);
putpixel(320, 240, getcolor());
putpixel(321, 241, getcolor());
putpixel(321, 239, getcolor());
putpixel(319, 241, getcolor());
putpixel(319, 239, getcolor());
for (i = 1; i <= 3; i++)
BresenhamCircle(320, 240, i);
delay(500);
16
line(320, 290, 420, 240);
delay(500);
line(370, 265, 370, 165);
delay(500);
line(370, 215, 270, 165);
delay(500);
line(320, 190, 220, 240);
delay(500);
line(270, 215, 270, 315);
delay(500);
line(270, 265, 370, 315);
delay(500);
line(420, 240, 420, 90);
delay(500);
line(370, 165, 220, 90);
delay(500);
line(270, 165, 120, 240);
delay(500);
line(220, 240, 220, 390);
delay(500);
line(270, 315, 420, 390);
delay(500);
line(370, 315, 520, 240);
delay(500);
line(420, 90, 320, 140);
delay(500);
line(220, 90, 220, 190);
delay(500);
line(120, 240, 220, 290);
delay(500);
line(220, 390, 320, 340);
delay(500);
line(420, 390, 420, 290);
delay(500);
line(520, 240, 420, 190);
setfillstyle(1, RED);
delay(500);
floodfill(370, 290, WHITE);
delay(500);
floodfill(320, 165, WHITE);
17
delay(500);
floodfill(245, 240, WHITE);
setfillstyle(1, YELLOW);
delay(500);
floodfill(385, 240, WHITE);
delay(500);
floodfill(200, 240, WHITE);
delay(500);
floodfill(320, 315, WHITE);
delay(500);
BresenhamCircle(320, 240, 210);
delay(500);
setfillstyle(1, BLUE);
floodfill(320, 350, WHITE);
floodfill(335, 240, WHITE);
getch();
closegraph();
}
18
d = d + (4 * x) + 6;
}
else
{
d = d + (4 * x) - (4 * y) + 10;
y--;
}
x++;
EightWaySymm(xc, yc, x, y);
}
}
19
- RANGOLI 03 -
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
void main()
{
int gd = DETECT, gm, xc, yc, a = 200, b = 75, c = 1;
int i, j, k;
double rad1, rad2, x[10], y[10], angle1 = 0, angle2 = 0, pi =
3.141592654;
char ch;
initgraph(&gd, &gm, "C:\\TC\\BGI");
delay(500);
setfillstyle(1, DARKGRAY);
floodfill(1, 1, WHITE);
delay(500);
outtextxy(280, 10, "RANGOLI 03");
xc = 320;
yc = 240;
for (j = 0; j < 1440; j++)
{
for (k = 0; k < 8; k++)
{
rad1 = (pi * angle1) / 180;
rad2 = (pi * angle2) / 180;
x[k] = a * cos(rad1) * cos(rad2) - b * sin(rad1) *
sin(rad2);
y[k] = a * sin(rad1) * cos(rad2) + b * cos(rad1) *
sin(rad2);
circle(xc, yc, 5);
setfillstyle(1, WHITE);
floodfill(xc, yc, WHITE);
circle(xc + x[k], yc - y[k], c);
setfillstyle(1, WHITE);
floodfill(xc + x[k], yc - y[k], WHITE);
20
angle1 += 40.0;
}
angle2 += 0.25;
delay(1);
}
getch();
closegraph();
}
21
PROGRAM OUTPUT
- RANGOLI 01 –
22
- RANGOLI 02 –
23
- RANGOLI 03 –
24
CONCLUSION
The main outcome behind this micro-project was to implement different
algorithms in computer graphics and produce a creative and colourful graphic
using C language. After completing this micro-project, I think that this outcome
has been achieved.
25
REFERENCES
www.google.com
www.youtube.com
www.geeksforgeeks.org
www.tutorialspoint.com
www.generalnote.com
www.javatpoint.com
www.programiz.com
www.w3schools.in
26