[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CGraphics

(C) Graphics

Beginners Guide Graphics in C

------------------------------------------------------

This tutorial is for those who need to work with graphics in C or are interested in graphics.

C itself does not support any graphics library. The only chance people have to use graphichs in C are escape charcters.

You can use escape characters within formatted strings.


/* clearing the screen for graphics output */

printf("\033[2J"); 


The above code works because of the ASCII/ANSI control characters for the terminals. control code to clear the screen is ESC[2J. ESC is having octal value 33 in ASCII Table. so the code to clear the screen will be \033[2J

Example programs

Now i will show some sample program to demonstrate how you can use escape characters.


/* A program to change the video mode from "normal" to "invers" */

int main(int argc, char* argv[])
{
 /* display help text for user */
  if(argc != 2)
   {
      printf("\nUsage: normal,invers");
      exit(1);
   }
 /* set video mode to normal */
  if(strcmp(argv[1],"normal"))
   {
     printf("\033[0m");
     printf("\033[2J");
   }
  /* set video mode to invers */
  else if(strcmp(argv[1],"invers"))
    {
      printf("\033[7m");
      printf("\033[2J");
    }
}


This sample program is straightforward. It checks the argument the user has passed and sets the video mode accordingly.

'Graphics' links



last edited (March 7, 2007) by shinuvk, Number of views: 7999, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.