Showing posts with label Draw. Show all posts
Showing posts with label Draw. Show all posts

Monday, 31 March 2014

C Programming graphics | To draw circles in circles using C graphics

C Programming graphics | To draw circles in circles using C graphics

Source Code:-)

#include<graphics.h>
#include<conio.h>
#include<dos.h>

main()
{
   int gd = DETECT, gm, x, y, color, angle = 0;
   struct arccoordstype a, b;

   initgraph(&gd, &gm, "C:\\TC\\BGI");
   delay(2000);

   while(angle<=360)
   {
      setcolor(BLACK);
      arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);
      setcolor(RED);
      getarccoords(&a);
      circle(a.xstart,a.ystart,25);
      setcolor(BLACK);
      arc(getmaxx()/2,getmaxy()/2,angle,angle+2,150);
      getarccoords(&a);
      setcolor(GREEN);
      circle(a.xstart,a.ystart,25);
      angle = angle+5;
      delay(50);
   }

   getch();
   closegraph();
   return 0;
}

C Programming graphics | To draw a 3d bar chart using C graphics

C Programming graphics | To draw a 3d bar chart using C graphics

 Source code:-)

#include <graphics.h>
#include <conio.h>

int main()
{
   int gd = DETECT, gm;

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

   setcolor(YELLOW);
   rectangle(0,30,639,450);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   setcolor(WHITE);
   outtextxy(275,0,"Bar Chart");

   setlinestyle(SOLID_LINE,0,2);

   line(100,420,100,60);
   line(100,420,600,420);
   line(90,70,100,60);
   line(110,70,100,60);
   line(590,410,600,420);
   line(590,430,600,420);

   outtextxy(95,35,"Y");
   outtextxy(610,405,"X");
   outtextxy(85,415,"O");

   setfillstyle(LINE_FILL,BLUE);
   bar(150,100,200,419);

   setfillstyle(XHATCH_FILL,RED);
   bar(225,150,275,419);

   setfillstyle(WIDE_DOT_FILL,GREEN);
   bar(300,200,350,419);

   setfillstyle(INTERLEAVE_FILL,MAGENTA);
   bar(375,125,425,419);

   setfillstyle(HATCH_FILL,BROWN);
   bar(450,175,500,419);

   getch();
   return 0;
}

C Programming graphics | To draw pie chart using C graphics

 C Programming graphics | To draw pie chart using C graphics

 Source code:-) 

#include<graphics.h>
#include<conio.h>

int main()
{
   int gd = DETECT, gm, midx, midy;

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

   setcolor(MAGENTA);
   rectangle(0,40,639,450);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   setcolor(WHITE);
   outtextxy(275,10,"Pie Chart");

   midx = getmaxx()/2;
   midy = getmaxy()/2;

   setfillstyle(LINE_FILL,BLUE);
   pieslice(midx, midy, 0, 75, 100);
   outtextxy(midx+100, midy - 75, "20.83%");

   setfillstyle(XHATCH_FILL,RED);
   pieslice(midx, midy, 75, 225, 100);
   outtextxy(midx-175, midy - 75, "41.67%");

   setfillstyle(WIDE_DOT_FILL,GREEN);
   pieslice(midx, midy, 225, 360, 100);
   outtextxy(midx+75, midy + 75, "37.50%");

   getch();
   return 0;
}

C Programming graphics | C program draw bar chart using C graphics

C Programming graphics | C program draw bar chart using C graphics

Source code:-)

#include <graphics.h>
#include <conio.h>

main()
{
   int gd = DETECT, gm;

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

   setcolor(YELLOW);
   rectangle(0,30,639,450);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   setcolor(WHITE);
   outtextxy(275,0,"Bar Chart");

   setlinestyle(SOLID_LINE,0,2);

   line(100,420,100,60);
   line(100,420,600,420);
   line(90,70,100,60);
   line(110,70,100,60);
   line(590,410,600,420);
   line(590,430,600,420);

   outtextxy(95,35,"Y");
   outtextxy(610,405,"X");
   outtextxy(85,415,"O");

   setfillstyle(LINE_FILL,BLUE);
   bar(150,100,200,419);

   setfillstyle(XHATCH_FILL,RED);
   bar(225,150,275,419);

   setfillstyle(WIDE_DOT_FILL,GREEN);
   bar(300,200,350,419);

   setfillstyle(INTERLEAVE_FILL,MAGENTA);
   bar(375,125,425,419);

   setfillstyle(HATCH_FILL,BROWN);
   bar(450,175,500,419);

   getch();
   return 0;
}

C Programming graphics | Draw shapes using C graphics

C Programming | Draw shapes using C graphics

 Source code:-)

#include<graphics.h>
#include<conio.h>

main()
{
   int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;

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

   rectangle(left, top, right, bottom);
   circle(x, y, radius);
   bar(left + 300, top, right + 300, bottom);
   line(left - 10, top + 150, left + 410, top + 150);
   ellipse(x, y + 200, 0, 360, 100, 50);
   outtextxy(left + 100, top + 325, "My First C Graphics Program");

   getch();
   closegraph();
   return 0;
}