0% found this document useful (0 votes)
19 views18 pages

CG File

Uploaded by

souravdhandhi443
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views18 pages

CG File

Uploaded by

souravdhandhi443
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Programme: 1

Write a Program to draw basic graphics construction like line, circle, arc, ellipse and
rectangle.
1. #include<graphics.h>

2. #include<conio.h>

3. void main()

4. {

5. intgd=DETECT,gm;

6. initgraph (&gd,&gm,"c:\\tc\\bgi");

7. setbkcolor(GREEN);

8. printf("\t\t\t\n\nLINE");

9. line(50,40,190,40);

10. printf("\t\t\n\n\n\nRECTANGLE");

11. rectangle(125,115,215,165);

12. printf("\t\t\t\n\n\n\n\n\n\nARC");

13. arc(120,200,180,0,30);

14. printf("\t\n\n\n\nCIRCLE");

15. circle(120,270,30);

16. printf("\t\n\n\n\nECLIPSE");

17. ellipse(120,350,0,360,30,20);

18. getch();

19. }
Output
Programme: 2
Write a Program to draw animation using increasing circles filled with different colors and
patterns.
1. #include<graphics.h>

2. #include<conio.h>

3. void main()

4. {

5. intgd=DETECT, gm, i, x, y;

6. initgraph(&gd, &gm, "C:\\TC\\BGI");

7. x=getmaxx()/3;

8. y=getmaxx()/3;

9. setbkcolor(WHITE);

10. setcolor(BLUE);

11. for(i=1;i<=8;i++)

12. {

13. setfillstyle(i,i);

14. delay(20);

15. circle(x, y, i*20);

16. floodfill(x-2+i*20,y,BLUE);

17. }

18. getch();

19. closegraph();

20. }
Output
Programme:3
Program to make screen saver in that display different size circles filled with different
colors and at random places.
1. #include<stdio.h>

2. #include<conio.h>

3. #include"graphics.h"

4. #include"stdlib.h"

5. void main()

6. {

7. intgd=DETECT,gm,i=0,x,xx,y,yy,r;

8. //Initializes the graphics system

9. initgraph(&gd,&gm,"c:\\tc\\bgi");

10. x=getmaxx();

11. y=getmaxy();

12. while(!kbhit())

13. {

14. i++;

15. // setfillstyle(random(i),random(30));

16. circle(xx=random(x),yy=random(y),random(30));

17. setfillstyle(random(i),random(30));

18. floodfill(xx,yy,getmaxcolor());

19. delay(200);

20. }

21. getch();

22. }
Output
Programme: 4
Write a Program to make a moving colored car using inbuilt functions.
1. #include<graphics.h>

2. #include<conio.h>

3. int main()

4. {

5. intgd=DETECT,gm, i, maxx, cy;

6. initgraph(&gd, &gm, "C:\\TC\\BGI");

7. setbkcolor(WHITE);

8. setcolor(RED);

9. maxx = getmaxx();

10. cy = getmaxy()/2;

11. for(i=0;i<maxx-140;i++)

12. {

13. cleardevice();

14. line(0+i,cy-20, 0+i, cy+15);

15. line(0+i, cy-20, 25+i, cy-20);

16. line(25+i, cy-20, 40+i, cy-70);

17. line(40+i, cy-70, 100+i, cy-70);

18. line(100+i, cy-70, 115+i, cy-20);

19. line(115+i, cy-20, 140+i, cy-20);

20. line(0+i, cy+15, 18+i, cy+15);

21. circle(28+i, cy+15, 10);

22. line(38+i, cy+15, 102+i, cy+15);

23. circle(112+i, cy+15,10);

24. line(122+i, cy+15 ,140+i,cy+15);

25. line(140+i, cy+15, 140+i, cy-20);

26. rectangle(50+i, cy-62, 90+i, cy-30);

27. setfillstyle(1,BLUE);

28. floodfill(5+i, cy-15, RED);

29. setfillstyle(1, LIGHTBLUE);


30. floodfill(52+i, cy-60, RED);

31. delay(10);

32. }

33. getch();

34. closegraph();

35. return 0;

36. }
Output
Programme:5
Write a Program to print your name in Hindi script on console output in C.
1. #include<stdio.h>

2. #include<conio.h>

3. #include<graphics.h>

4. #include<dos.h>

5. void main()

6. {

7. int gd=DETECT,gm;

8. initgraph(&gd,&gm,"c:\\tc\\bgi");

9. setbkcolor(9);

10. line(100,100,370,100);

11.

12. line(120,100,120,170);

13. arc(143,100,0,180,23);

14. line(165,100,165,155);

15. arc(150,155,100,0,15);

16. line(180,100,180,170);

17.

18. circle(210,140,10);

19. line(210,130,250,130);

20.

21. circle(280,140,10);

22. line(280,130,330,130);

23. line(330,100,330,170);

24. line(345,100,345,170);

25. ellipse(337,100,0,180,9,18);

26. getch();

27. }
Output
Programme:6

Write a Program control a ball using arrow keys.

1. #include<graphics.h>

2. #include<stdio.h>

3. void main()

4. {

5. intgd=DETECT,gm,x,y,r=40;

6. charch;

7. initgraph(&gd,&gm,"C:/TURBOC3/BGI");

8. setbkcolor(3);

9. x=getmaxx()/2;

10. y=getmaxy()/2;

11. setfillstyle(1,RED);

12. circle(x,y,r);

13. floodfill(x,y,getmaxcolor());

14. while((ch=getch())!=13)

15. {

16. switch(ch)

17. {

18. case 75: if(x>=r+1)

19. {

20. cleardevice();

21. circle(x-=10,y,r);

22. floodfill(x,y,getmaxcolor());

23. }

24. break;

25. case 72: if(y>=r+1)

26. {

27. cleardevice();

28. circle(x,y-=10,r);

29. floodfill(x,y,getmaxcolor());
30. }

31. break;

32. case 77: if(x<=(getmaxx()-r-10))

33. {

34. cleardevice();

35. circle(x+=10,y,r);

36. floodfill(x,y,getmaxcolor());

37. }

38. break;

39. case 80: if(y<=(getmaxy()-r-10))

40. {

41. cleardevice();

42. circle(x,y+=10,r);

43. floodfill(x,y,getmaxcolor());

44. }

45. }

46. }

47. getch();

48. }
Output
Programme:7
Write a Program to implement Digital Clock.
1. #include<stdio.h>

2. #include<conio.h>

3. #include<graphics.h>

4. #include<dos.h>

5.

6. struct time t;

7. void display(int,int,int);

8. void main()

9. {

10. int i=0,gd=DETECT,gm,hr,min,sec;

11. clrscr();

12. initgraph(&gd,&gm,"c:\\turboc3\\bgi");

13. setcolor(GREEN);

14. settextstyle(4,0,7);

15.

16. while(!kbhit())

17. {

18. gettime(&t);

19. hr=t.ti_hour;

20. min=t.ti_min;

21. sec=t.ti_sec;

22. i++;

23.

24. display(100,100,hr);

25. display(200,100,min);

26. display(300,100,sec);

27. sound(400);

28. delay(30);

29. nosound();
30. delay(930);

31. cleardevice();

32. }

33. getch();

34. }

35. void display(int x,int y,int num)

36. {

37.

38. char str[3];

39. itoa(num,str,10);

40.

41. settextstyle(4,0,7);

42.

43. outtextxy(180,100,":");

44. outtextxy(280,100,":");

45. outtextxy(x,y,str);

46.

47. rectangle(90,90,380,200);

48. rectangle(70,70,400,220);

49.

50. outtextxy(90,250,"Digital Clock");

51. }
Output

You might also like