COMPUTER GRAPHICS IN C
HUT
Aim:-
To draw a hut using line,circle and rectangle.
Algorithm:-
1: Start.
2: Use intialize variables graphics driver and graphics mode
3:Draw the Hut model using the rectangle (), Line () and Circle () functions.
4:Use forloop to change sun color.
5:Stop.
Program:-
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gd,"c:\\Turboc3\\BGI");
setcolor(BLUE);
rectangle(160,200,500,400);
setfillstyle(1,BLUE);
floodfill(161,201,BLUE);
setcolor(GREEN);
rectangle(280,290,380,400);
setfillstyle(8,GREEN);
floodfill(281,291,GREEN);
setcolor(YELLOW);
line(130,200,530,200);
line(190,100,470,100);
line(130,200,190,100);
line(530,200,470,100);
line(180,220,240(WHITE);
circle(5,100);
line(240,220,290,100);
line(290,220,340,100);
line(340,220,390,100);
line(390,220,440,100);
line(440,220,490,135);
setcolor0,80,50);
setfillstyle(10,WHITE);
floodfill(50,80,WHITE);
setcolor(RED);
for(i=0;i<=15;i++)
{
circle(50,80,20);
setfillstyle(1,i);
floodfill(51,81,RED);
delay(500);
}
getch();
}
Output :-
rectangle (int left, int top, int right, int bottom);
According to this syntax we have to draw a rectangle of our choice. Give that rectangle a blue color.
The second step is to draw a small rectangle inside the large rectangle drawn earlier. Further, draw a line as a slope inside that small rectangle. The function used for this is setfillstyle ().
The pattern with the small rectangle drawn earlier is called 'XHATCH_FILL' infact, its number is '8' according to the pattern, hence 'setfillstyle (8, GREEN);' Thus written. When you look at the picture you get the output, you know that there is a small green color pattern inside the previously drawn rectangle.
Now the third step is to draw the roof of the house. For that we need to use the line () function. The syntax of the line () function is: -line (int x1, int y1, int x2, int y2);
x1, y1, x2, y2 are all starting and ending coordinates. That is why in the program 'line (440,220,490,135);' It is written like this. Four lines are drawn for the roof of the house. Futhermore, six lines are drawn as a slope inside it. We can see in the output that the color of the roof is yellow.
The fourth thing to do is to draw the sun. This program is sun animated. In fact, it is animated using forloop. Here two circles are used to draw the sun. One circle for sunshine and the other for sun. The big circle is sunshine and the second circle is sun. The sun color varies from 1 to 15 color. The second circle uses the white color pattern. What is the pattern is mentioned above. Draw a hut and sunshine using these steps.
All you have to do is give the circle () and line () function to make the coconut harvester. Then we can give the mountain. The arc () function should be given to the mountain. Give the mountain color green.
Clouds can be placed on top of the house using arc (). Let's draw flying parrots.How beautiful a house we can be. Let us draw a pond on the front of the house.Two arc bends are enough to draw the bird. Black color is the best bird.
If you have any doubts or suggestions regarding this article, please leave a comment in the comment box.
0 Comments