Results 1 to 5 of 5

Thread: Graphics with C programming for Different shapes

  1. #1
    Join Date
    Nov 2009
    Posts
    56

    Graphics with C programming for Different shapes

    I want to know about the C programming? What is the graphics in C programming? How can I create graphics for circle,rectangle and Triangle?
    How can I build my application in C using graphics?

  2. #2
    Join Date
    May 2008
    Posts
    2,302

    Re: Graphics with C programming for Different shapes

    C is a basic purpose language that is developed by Dennis Ritchie at the AT&TBells Laboratories in 1972 for specially compatible with the Unix operating system and specially for designing system software but now a days it is being used by MS-DOS.
    It is mother language of the newer programming languages .It was designed to be compiled using a relatively straightforward compiler that execute the code using top to down approach.
    C supports a rich set of operators, which are symbols used within an expression and programmer can perform a lot of operation and calculation using variables and many more Like:
    1. Basic datatypes and operators
    2. Uinon and structure
    3. File handling
    4. Functions
    5. Graphics
    6. Pointers
    using these provided facility,we can build a strong application
    Last edited by Zecho; 12-01-2010 at 09:44 AM.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,010

    Re: Graphics with C programming for Different shapes

    Using Graphics in C language
    To make a good look of our application,we use the graphics that provides a lot of shapes that are achieved by graphics codes.In a C program you need to initialize the graphics to your computer which is controlled by in-build header file "graphics.h" into the library of C.

    Graphics Mode initialization
    First of all you need to call the initgraph function which takes the following form:

    void initgraph(int far *grdriver, int far *grmode, char far *pathtodriver);
    This prototype will set the graphics system using graphics driver from disk(validating a registered driver) .

    Take a look of sample program which initialize graphics mode in C Language.

    #include <graphics.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    int main(void)
    {

    int grdriver = DETECT, grmode, errorcode;


    initgraph(&grdriver, &grmode, "");


    errorcode = graphresult();
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1);
    }


    line(0, 0, getmaxx(), getmaxy());


    getch();
    closegraph();
    return 0;
    }
    Last edited by kelfro; 12-01-2010 at 10:51 AM.

  4. #4
    Join Date
    May 2008
    Posts
    2,015

    Re: Graphics with C programming for Different shapes

    Creating circle in graphics in C:
    The circle command takes three parameters x coordinate ,y coordinate and radius which indicates x coordinate for Vertical axis, y coordinate for Horizontal axis and last one is radius of circle.We can construct it as follows:


    #include<graphics.h>
    #include<conio.h>
    main()
    {
    int gdriver=DETECT,gmode;
    initgraph(&gdriver,&gmode,"");
    circle(150,150,100);
    getch();
    closegraph();
    }
    Last edited by Katty; 12-01-2010 at 10:46 AM.

  5. #5
    Join Date
    Apr 2008
    Posts
    1,949

    Re: Graphics with C programming for Different shapes

    Creating Rectangle in C

    To create a rectangle in you need to initialize the graphics mode first and use rectangle function to draw a rectangle. This function takes four arguments left, top, right and bottom and every parameters should be in integer. A sample program which creates a rectangle:


    #include<graphics.h>
    #include<conio.h>
    main()
    {
    int graphd=DETECT,graphm;
    initgraph(&graphd,&graphm,"");
    rectangle(100,80,100,390);
    getch();
    closegraph();
    }
    Last edited by Praetor; 12-01-2010 at 10:49 AM.

Similar Threads

  1. Graphics program required in C programming Language
    By ramsun in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 11:17 AM
  2. How to cut shapes in Adobe Photoshop?
    By marcman in forum Windows Software
    Replies: 3
    Last Post: 01-10-2009, 08:53 AM
  3. Replies: 3
    Last Post: 13-12-2008, 12:49 PM
  4. How to create shapes in Gimp?
    By Beter 2 Burn Out in forum Customize Desktop
    Replies: 3
    Last Post: 02-08-2008, 12:47 PM
  5. Graphics & other programming in Turbo C/C++
    By aadipa in forum Software Development
    Replies: 34
    Last Post: 19-03-2004, 10:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •