Skip to main content

Graphics


Computer graphics is one of the most powerful and interesting aspects of computers. There is a lot that we can do in graphics apart from drawing figures of various shapes. All video games, animation, multimedia predominantly works with computer graphics. To work with graphics, C has various library functions. Some of built in functions which are defined within header file graphics.h are illustrated in this chapter.
Let us see one example which demonstrates graphics initialization and some built in functions related to graphics.

#include<graphics.h>
void main()
{
int gDriver=DETECT,gMode;
int polyArray[]={200,100,250,150,300,200,350,200,300,150,200,100};
initgraph(&gDriver,&gMode,"c:\\tc\\bgi");
setcolor(GREEN);
line(200,100,300,250); /*line from (200,100) to (300,250) */
circle(300,300,50); /*circle at center (300,300) having radius 50 */
ellipse(150,200,0,360,100,50);           /* ellipse at center (150,200) and angle from 0 to              
                                                             360 and the xradius 100, yradius 50*/
arc(200,300,300,90,80);  /* arc having center at (200,300) and radius 80 from starting
                                           angle 300 to end angle 90 */
rectangle(50,100,350,400);  /* rectangle of diagonal points at (50,100) and (350,400)*/
drawpoly(6,polyArray); /* polygon of 6 corner points*/
getch();
closegraph();

}

Comments

Popular posts from this blog

Object Oriented Programming

Object Oriented Programming Programming paradigm that represents the concept of "objects" that have data fields (attributes that describe the object) and associated procedures known as methods Programming methodology based on objects, instead of just functions and procedures Focuses on data rather than process As individual objects can be modified without affecting other aspects of the program, it is easier for programmers to structure and organize software programs Easier to update and change programs written in object-oriented languages Simula was the first object oriented programming language Eg: C++, Java, etc. Features of OOPS Objects Referred as instance of class Basic run-time entities in an object-oriented system a person, a place, a bank account, a table of data, etc can be an object They occupy space in memory that keeps its state  Each object contains data and code to manipulate the data  Classes Blue print or prototype  which defi

How structure elements are stored?

  The elements of a structure are always stored in contiguous memory locations. This can be illustrated as void main() {     struct student      {      int roll;      float marks;      char remarks;   };   struct student st={200,60.5,'P'};   printf("\nAddress of roll=%u",&st.roll);   printf("\nAddress of marks=%u",&st.marks);   printf("\nAddress of remarks=%u",&st.remarks);   getch(); } Output: Address of roll=65518 Address of marks=65520 Address of remarks=65524                  st.roll               st.marks                          st.remarks 200 60.5 ‘P’               65518             65520                               65524           

How containership is different than inheritance ?

               Inheritance is the mechanism of deriving properties of one class into another. While containership is mechanism in which one class contain objects of other classes as its member.                     class alpha{_ _ _ _ _ };                     class beta{_ _ _ _ _ };                      class gamma                      {                         alpha a;                         beta b;                       _ _ _ _ _ };            All objects of gamma class will contain the objects a and b, this kind of relationship is called containership or nesting.