COMPUTER GRAPHICS IN C
INDIAN FLAG
Aim:-
To draw a indian flag using circle and rectangle.
Algorithm:-
1: Start.
2: Use intialize graphics driver and graphics mode.
3:Draw the indian model using the rectangle () and Circle () functions.
4:Stop
#include#include #include void main() { int gd=DETECT,gm; initgraph(&gd,&gd,"c:\\Turboc3\\BGI"); setcolor(RED); rectangle(200,100,500,150); setfillstyle(SOLID_FILL,RED); floodfill(201,101,RED); setcolor(WHITE); rectangle(200,150,500,200); setfillstyle(SOLID_FILL,WHITE); floodfill(201,151,WHITE); setcolor(GREEN); rectangle(200,200,500,250); setfillstyle(SOLID_FILL,GREEN); floodfill(201,201,GREEN); setcolor(BLACK); circle(350,175,70); line(350,175,365,105); line(350,175,415,150); line(350,175,415,200); line(350,175,365,243); line(350,175,310,233); line(350,175,280,190); line(350,175,286,150); line(350,175,305,120); setcolor(WHITE); rectangle(180,80,200,450); setfillstyle(SOLID_FILL,YELLOW); floodfill(181,81,WHITE); circle(190,60,20); getch(); }
Output :-
The program mentioned here is the Indian flag. This program uses a rectangle () and a circle() functions. A total of four colors are used here such as red, white, yellow and green. Setcolor() gives foreground color, like text color etc ... . Setfillstyle () gives color inside an object. This function has two properities.
First step, draw a red rectangle that is wider and longer using a rectangle () function, example: rectangle (200,100,500,150); . infact, give it a red color. syntax
rectangle (left, top, right, bottom),
Here left = 200, top = 100, right = 500 and bottom = 150. setfillstyle (), setcolor (), and floodfill () to give color, such as setcolor (RED) ;, setfillstyle (SOLID_FILL, RED); And floodfill (201,101, RED); where SOLID_FILL is the color pattern whose number code is '1'. The floodfill () function gives the rectangle x and y coordinates color, which has a border color pattern where the border color is red. Here floodfill (201,151, RED); x = 201, y = 101, border color = red. Given this, draw a first red rectangle.
Second step, draw a white rectangle that is wider and longer using a rectangle () function, example: rectangle(200,150,500,200);
Here left = 200, top = 150, right = 500 and bottom = 200. In this program setcolor (WHITE);, setfillstyle (SOLID_FILL, WHITE); And floodfill (201,151, WHITE);.The floodfill () function gives the rectangle x and y coordinates color, which has a border color pattern where the border color is WHITE. Here floodfill (201,151, WHITE); x = 201, y = 151, and border color = WHITE. Given this, draw a SECOND WHITE rectangle.
Third step, draw a green rectangle that is wider and longer using a rectangle () function, example: rectangle(200,200,500,250);
Here left = 200, top = 200, right = 500 and bottom = 250. In this program setcolor (GREEN);, setfillstyle (SOLID_FILL, GREEN); And floodfill (201,201, GREEN);.The floodfill () function gives the rectangle x and y coordinates color, which has a border color pattern where the border color is GREEN. Here floodfill (201,201, GREEN); x = 201, y = 201, and border color = GREEN. Given this, draw a THIRD GREEN rectangle.
Fourth step circle and line drawing, first draw a circle and then draw a line inside it. When drawing a circle, the three rectangles drawn earlier should be inside. The circle and line are drawn using the circle () and rectangle () functions.circle () syntax: -
Here x coordinates is 350, y coordinates is 175 and radious = 70.
radious means size of the circle. The next line is the line inside the circle .line syntax: -
Here x1 = 350, y1 = 175, x2 = 365 and y2 = 105, all you have to do is change the coordinates accordingly. When you do this, the line inside the circle is ready.
The fifth step is to make a stand. To do this, use a narrow, long rectangle and then a small circle. Use the above rectangle and circle functions.rectangle (180,80,200,450);
These are the coordinates that draw the narrowest and longest rectangle. Then use setcolor () and setfillstyle () to color.
When these three functions are used, the narrow and long rectangle color will be yellow.Then coordinates to draw a circle on top of it. circle (190,60,20); When this is done, an Indian flag is ready.setcolor (WHITE);setfillstyle (SOLID_FILL, YELLOW);floodfill (181,81, WHITE);
We can use circle(), rectangle(), ellipse() and line() when drawing a person. There are many functions in graphics.
If you have any doubts or suggestions regarding this article, please leave a comment in the comment box.
0 Comments