Thursday 25 April 2013

Understand and Programming with Computer Graphics using C

First of all i Introduce you to Computer Graphics Using C language.


  • Advances in computer graphics have transformed how we use computers.
  • It has the become one of Most powerful and intersting facet of computers.
  • There is the virtually no area in which griphical displays cannot be used to some advantage,and so it is not suprising to find the use of computer graphics so widespread.
Evoultion /Need of computer graphics

  • The best way to represent any information is the pictirol representation just like this blog.
  • Consider for example a profit-loss analysis of an IT compeny working since last 40 years.
  • Dealing with such a big amount of data is difficult.
  • Instead of this, if we are provided with a chart that shows the analysis, it is quite easy to understand and comparison would be far easier.
  • Hence graphics came into picture.
  • But if this graphs or graphical data is created manully, it would be consume time and would be less accurate.
  • Moreover we might be even face truble data is created manually ,it would be consume time and would less accurate.
  • On the Other hand,using computer for creating this graphics would be provide sufficent  and no paper time limitations would occur.
  • This is an Example of how computer + graphics that is Computer graphics come an picture.That blog and also any computer scren also the exam of computer + graphics.
For short,we can have some the following advantages through the use of CG:

  • Saves Time
  • Provides more accuracy
  • Easy comparison
  • Easy understanding
  • Better representation,etc.
This Picture is the Example Picture of the Data with image.







This Image Below You see the Image And How it accurate.This type of image are the binding  up with the data



Applications of computer graphics




  • Computer Generated Arts
  • Video Games
  • Movies
  • CAD
  • Information Visualization
  • Forensic Science
  • Education &Traning
  • Image Processing



Like this Artical this there you go and Start the programming If you need to programming with C language you need to Download and install the Turbo C software to download this software click on Turbo C Software



There is some Example Program



The Main Conponant of that I put the programs on this blog is share the my knowledge with you.note that if you some basic knowledge of the computer graphics and also the Mouse programing then and then see the code and copy and paste in to your turbo c software go over here and see some wonderful programs done by me and my knowledge there you go and copy this code.



1.Create Circle With Computer Graphics



#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:\\TurboC3\\BGI");
   delay(1000);

   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;
}


2.That is the Program That Shutdown The Computer




#include <stdio.h>
#include <stdlib.h>

main()
{
   char ch;

   printf("Do you want to shutdown your computer now (y/n)\n");
   scanf("%c",&ch);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown /s");

   return




3.The Smile Face Created with computer Graphics 




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

main()
{
   int gd = DETECT, gm, area, temp1, temp2, left = 25, top = 75;
   void *p;

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

   setcolor(YELLOW);
   circle(50,100,25);
   setfillstyle(SOLID_FILL,YELLOW);
   floodfill(50,100,YELLOW);

   setcolor(BLACK);
   setfillstyle(SOLID_FILL,BLACK);
   fillellipse(44,85,2,6);
   fillellipse(56,85,2,6);

   ellipse(50,100,205,335,20,9);
   ellipse(50,100,205,335,20,10);
   ellipse(50,100,205,335,20,11);

   area = imagesize(left, top, left + 50, top + 50);
   p = malloc(area);

   setcolor(WHITE);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   outtextxy(155,451,"Smiling Face Animation");

   setcolor(BLUE);
   rectangle(0,0,639,449);

   while(!kbhit())
   {
      temp1 = 1 + random ( 588 );
      temp2 = 1 + random ( 380 );


  getimage(left, top, left + 50, top + 50, p);
      putimage(left, top, p, XOR_PUT);
      putimage(temp1 , temp2, p, XOR_PUT);
      delay(500);
      left = temp1;
      top = temp2;
   }

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

4.Paint Using The Computer Graphics And Mouse Programming



//This Softwere is developed by Virat All right Reserved @ VIRAT
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>

union REGS i, o;
int leftcolor[15];

int get_key()
{
   union REGS i,o;

   i.h.ah = 0;
   int86(22,&i,&o);

   return ( o.h.ah );
}

void draw_color_panel()
{
   int left, top, c, color;

   left = 100;
   top = 436;

   color = getcolor();
   setcolor(GREEN);
   rectangle(4,431,635,457);
   setcolor(RED);
   settextstyle(TRIPLEX_FONT,0,2);
   outtextxy(10,431,"Colors : ");

   for( c = 1 ; c <= 15 ; c++ )
   {
      setfillstyle(SOLID_FILL, c);
      bar(left, top, left+16, top+16);
      leftcolor[c-1] = left;
      left += 26;

  }

   setcolor(color);
}

void draw_shape_panel()
{
   int left, top, c, color;

   left = 529;
   top = 45;

   color = getcolor();
   setcolor(GREEN);
   rectangle(525,40,633,255);

   for( c = 1 ; c <= 7 ; c++ )
   {
      rectangle(left, top, left+100, top+25);
      top += 30;
   }
   setcolor(RED);
   outtextxy(530,45,"Bar");
   outtextxy(530,75,"Line");
   outtextxy(530,105,"Pixel");
   outtextxy(530,135,"Ellipse");
   outtextxy(530,165,"Freehand");
   outtextxy(530,195,"Rectangle");
   outtextxy(530,225,"Clear");
   setcolor(color);
}

void change_color(int x, int y)
{
   int c;

   for( c = 0 ; c <= 13 ; c++ )
   {
      if( x > leftcolor[c] && x < leftcolor[c+1] && y > 437 && y < 453 )
setcolor(c+1);

if( x > leftcolor[14] && x < 505 && y > 437 && y < 453 )
setcolor(WHITE);
   }
}

char change_shape(int x, int y)
{
   if ( x > 529 && x < 625 && y > 45 && y < 70 )
      return 'b';
   else if ( x > 529 && x < 625 && y > 75 && y < 100 )
      return 'l';
   else if ( x > 529 && x < 625 && y > 105 && y < 130 )
      return 'p';
   else if ( x > 529 && x < 625 && y > 135 && y < 160 )
      return 'e';
   else if ( x > 529 && x < 625 && y > 165 && y < 190 )
      return 'f';
   else if ( x > 529 && x < 625 && y > 195 && y < 220 )
      return 'r';
   else if ( x > 529 && x < 625 && y > 225 && y < 250 )
      return 'c';
}

void showmouseptr()
{
   i.x.ax = 1;
   int86(0x33,&i,&o);
}

void hidemouseptr()
{
   i.x.ax = 2;
   int86(0x33,&i,&o);
}

void restrictmouseptr( int x1, int y1, int x2, int y2)
{
   i.x.ax = 7;
   i.x.cx = x1;

i.x.dx = x2;
   int86(0x33,&i,&o);

   i.x.ax = 8;
   i.x.cx = y1;
   i.x.dx = y2;
   int86(0x33,&i,&o);
}

void getmousepos(int *button,int *x,int *y)
{
   i.x.ax = 3;
   int86(0x33,&i,&o);

   *button = o.x.bx;
   *x = o.x.cx;
   *y = o.x.dx;
}

main()
{
   int gd = DETECT,gm;

   int maxx,maxy,x,y,button,prevx,prevy,temp1,temp2,key,color;
   char ch = 'f' ;            // default free-hand drawing

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

   maxx = getmaxx();
   maxy = getmaxy();

   setcolor(BLUE);
   rectangle(0,0,maxx,maxy);

   setcolor(WHITE);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   outtextxy(maxx/2-180,maxy-28,"This sottwere is devoloped by VIRAT");
draw_color_panel();
   draw_shape_panel();

   setviewport(1,1,maxx-1,maxy-1,1);

   restrictmouseptr(1,1,maxx-1,maxy-1);
   showmouseptr();
   rectangle(2,2,518,427);
   setviewport(1,1,519,428,1);

   while(1)
   {
      if(kbhit())
      {
key = get_key();

if( key == 1 )
{
   closegraph();
   exit(0);
}
      }

      getmousepos(&button,&x,&y);

      if( button == 1 )
      {
if( x > 4 && x < 635 && y > 431 && y < 457 )

change_color( x, y );
else if ( x > 529 && x < 625 && y > 40 && y < 250 )
    ch = change_shape( x, y );

temp1 = x ;
temp2 = y ;

if ( ch == 'f' )
{
   hidemouseptr();
   while( button == 1 )
   {
      line(temp1,temp2,x,y);
      temp1 = x;
      temp2 = y;
      getmousepos(&button,&x,&y);
   }
   showmouseptr();
}

while( button == 1)
   getmousepos(&button,&x,&y);

/* to avoid interference of mouse while drawing */
hidemouseptr();

if( ch == 'p')
   putpixel(x,y,getcolor());

else if ( ch == 'b' )
{
   setfillstyle(SOLID_FILL,getcolor());
   bar(temp1,temp2,x,y);
}
else if ( ch == 'l')
   line(temp1,temp2,x,y);
else if ( ch == 'e')
   ellipse(temp1,temp2,0,360,abs(x-temp1),abs(y-temp2));
else if ( ch == 'r' )

rectangle(temp1,temp2,x,y);
else if ( ch == 'c' )
{
   ch = 'f';          // setting to freehand drawing
   clearviewport();
   color = getcolor();
   setcolor(WHITE);
   rectangle(2,2,518,427);
   setcolor(color);
}

showmouseptr();
      }
   }
}


If you Have UnderStand More Watch This Video.


0 comments:

Post a Comment