C LANGUAGE - GRAPHICS

 GRAPHICS

 

Example

 

#include<stdio.h>

#include<stdio.h>

#include<graphics.h>

main()

{

int gd=DETECT;

int gm;

initgraph(&gd,&gm," ");

setbkcolor(DARKGRAY);

setcolor(LIGHTGREEN);

outtextxy(155,165,"ARUNYA HOUSE");

line(200,50,100,200);

line(200,50,300,200);

setcolor(LIGHTRED);

rectangle(132,150,268,300);

setcolor(LIGHTGREEN);

rectangle(175,225,225,300);

setcolor(LIGHTCYAN);

line(268,325,225,350);

line(225,350,225,365);

line(225,365,365,365);

line(268,325,325,325);

line(325,325,365,350);

line(365,350,365,365);

circle(255,375,10);

circle(345,375,10);

rectangle(265,340,280,350);

rectangle(310,340,325,350);

setcolor(YELLOW);

line(246,370,11,370);

line(252,370,600,370);

line(11,420,600,420);

getch();

closegraph();

}

 

 

Line

 

Line command is used to draw line between two specified points

 

Syntax

 

line(int x1,int y1,int x2,int y2);

 

Example

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int xmax,ymax;

initgraph(&gdriver,&gmode,"");

line(100,50,300,50);

line(100,50,100,200);

line(100,200,300,200);

line(300,200,300,50);

getch();

closegraph();

}

 

Circle

 

Circle command is used to draw a circle int the current x,y position

 

Syntax

 

circle(int x,int y,int radius)

 

Example

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int midx,midy;

int radius=100;

initgraph(&gdriver,&gmode,"");

midx=getmaxx()/2;

midy=getmaxy()/2;

circle(midx,midy,radius);

getch();

closegraph();

}

 

Arc

 

Arc draws a circular arc in the current x, y position

 

Syntax

 

arc(int x, int y, int stangle, int endangle, int radius);

 

Example

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int midx,midy;

int stangle =45,endangle=135;

int radius=100;

initgraph(&gdriver,&gmode,"");

midx=getmaxx()/2;

midy=getmaxy()/2;

setcolor(getmaxcolor());

arc(midx,midy,stangle,endangle,radius);

getch();

closegraph();

}

 

PieSliceas

 

PieSlice draws a pieslice in the current x, y position and the fills it using current fill pattern and fill color.

 

Syntax

 

pieslice(int x, int y, int stangle, int endangle, int radius);

 

Where (x, y)         - Center point of arc, circlew, or pieslice

Stangle        - Start angle in degrees

Endangle     - End angle in degrees

Radius                  - Radius of arc, circle, and pieslice

 

Example

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int midx,midy;

int stangle =45,endangle=135;

int radius=100;

initgraph(&gdriver,&gmode,"");

midx=getmaxx()/2;

midy=getmaxy()/2;

setfillstyle(2,getmaxcolor());

pieslice(midx,midy,stangle,endangle,radius);

getch();

closegraph();

}

 

Bar

 

Bar draws a filled-in, rectangular, two-dimensional bar.

The bar is filled using the current fill pattern and fill color. Bar does not outline the bar.

 

Syntax

 

Bar(int left, int top, int right, int bottom);

 

Where         (left,top)     – The rectangle’s upper left corner

          (right,bottom)       – The rectangle’s lower right corner

 

Example

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int midx,midy;

initgraph(&gdriver,&gmode,"");

midx=getmaxx()/2;

midy=getmaxy()/2;

for(i=SOLID_FILL;i<USER_FILL;i++)

{

setfillstyle(i,getmaxcolor());

bar(midx-50,midy-50,midx+50,midy+50);

getch();

}

closegraph();

}

 

Bar 3d

 

Bar 3d draws a three – dimensional rectangular bar, then fills it using the current fill pattern and fill color.

 

The three – dimensional outline of the bar is drawn in the current line style and color

 

Syntax:

 

Bar3d (int left, int top, int right, int bottom , int depth, int topflag)

 

Where             depth      -        bar’s depth In pixels

Topflag                -        governs whether a three – dimensional top is put on the bar

(left, top)              -        rectangle’s upper left corner

(right, bottom)               -        rectangle’s lower right corner

 

Example:

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int midx,midy,i;

initgraph(&gdriver,&gmode,””);

midx=getmaxx()/2;

midy=getmaxy()/2;

for(i=EMPTY_FILL;i<USER_FILL;i++)

{

          setfillstyle(i,getmaxcolor());

          bar3d(midx-50,midy-50,midx+50,midy+50,10,1);

          getch();

}

closegraph();

}

                  

Rectangle

 

          Rectangle draws a rectangle in the current line style, thickness and drawing color

 

Syntax:

 

Rectangle (left,top,right,bottom)

 

Where left,top                -        the upper left corner of the rectangle

Right,bottom                 -        the lower right corner

 

Example:

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main()

{

int gdriver = DETECT, gmode;

initgraph(&gdriver,&gmode,””);

rectangle(100,50,300,150);

getch();

closegraph();

}

 

Ellipse

 

Ellips draws an elliptical arc in the current drawing color

 

Syntax:

 

          Ellipse(int x,int y, int stangle, int endangle, int xradius, int yradius);

 

Where (x,y)          -        center of ellipse

          Xradius       -        horizantol axis

          Yradius       -        vertical axis

          Stangle                 -        starting angle

          Endangle     -        ending angle

 

Example:

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main()

{

int gdriver=DETECT,gmode;

int midx,midy;

int stangle = 0,endangle = 360;

int xradius = 100, yradius=50;

initgraph(&gdriver,&gmode,””);

midx=getmaxx()/2;

midy=getmaxy()/2;

setcolor(getmaxcolor());

ellipse(midx,midy,stangle,endangle,xradius,yradius);

getch();

}

 

Fillellipse

 

Fillellipse draws an ellipse, then fills the ellipse with the current fill color and fill pattern

 

Syntax;

 

          Fillellipse (int x,int y ,int xradius, int yradius);

 

Where  (x,y)                   -        center of ellipse

          Xradius       -        horizandal axis

          Yradius       -        vertical axis

          Stangle                 -        starting angle

          Endangle     -        ending angle

 

Example:

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main()

{

int gdriver = DETECT, gmode;

int midx,midy,i;

int xradius=100,yradius=50;

initgraph(&gdriver,&gmode,””);

midx=getmaxx()/2;

midy=getmaxy()/2;

for(i=EMPTY_FILL;i <USER_FILL;i++)

{

          setfillstyle(i,getmaxcolor());

          fillellipse(midx,midy,xradius,yradius);

getch();

}

          closegraph();

}

 

Sector

 

Sector draws and fills an elliptical pie slice in the current drawing color, then fills it using the pattern and color defined by defined by setfillstyle or setfillpattern.

 

Syntax

 

Sector(int x,int y,int stangle, int endangle,int xradius,int yradius);

 

X,y – center of ellipse

Xradius – Horizontal axis

Yradius – Vertical axis

Stangle – Starting angle

Endangle – ending angle

 

Example:

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main()

{

int gdriver = DETECT, gmode;

int midx,midy,i;

int stangle=45,endangle=135;

int xrad=100,yrad=50;

initgraph(&gdriver,&gmode,””);

midx=getmaxx()/2;

midy=getmaxy()/2;

for(i=EMPTY_FILL;i <USER_FILL;i++)

{

          setfillstyle(i,getmaxcolor());

          sector(midx,midy,stangle,endangle,xrad,yrad);

getch();

}

closegraph();

}

 

 

Text style

 

Outtextxy displays the string in the current x,y position

 

Syntax

 

Outtextxy(int x,int y,*string);

 

X is the current x coordinate

Y is the current y coordinate

 

String is the text to be displayed

 

Example:

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

char *fname[]={“DEFAULT font”,”TRIPLEX font”,”SMALL font”,”SANS SERIF font”,”GOTHIC font”};

 

void main()

{

int gdriver = DETECT, gmode;

int midx,midy,style;

initgraph(&gdriver,&gmode,””);

midx=getmaxx()/2;

midy=getmaxy()/2;

settextjustify(CENTER_TEXT,CENTER_TEXT);

                   for(style=DEFAULT_FONT;style<=GOTHIC_FONT;style++)

{

cleardevice();

settextstyle(style,HORIZ_DIR,5);

outtextxy(midx,midy,”SIVA”);

getch();

}

closegraph();

}

 

 

House Program

 

#include<graphics.h>

#include<stdio.h>

#include<conio.h>

void main(void)

{

int gdriver = DETECT, gmode;

int xmax,ymax;

initgraph(&gdriver,&gmode,"");

line(100,210,180,70);

line(180,70,260,210);

line(180,70,400,70);

line(100,210,480,210);

line(100,210,100,360);

line(260,210,260,360);

line(480,210,480,360);

line(100,360,480,360);

line(150,270,150,360);

line(210,270,210,360);

line(150,270,210,270);

line(150,270,180,280);

line(180,280,180,340);

line(180,340,150,360);

line(150,280,170,290);

line(170,290,170,345);

line(400,70,480,210);

line(320,250,320,320);

line(320,250,420,250);

line(420,250,420,320);

line(320,320,420,320);

line(320,270,420,270);

line(320,300,420,300);

line(350,250,350,320);

line(390,250,390,320);

circle(370,285,5);

circle(180,160,30);

circle(180,160,20);

getch();

closegraph();

}

 

String

 

 

#include<stdio.h>

#include<conio.h>

#include<string.h>

main()

{

int no,bm,fm,om,tot;

float avg;

char na[30],c[10],re[10];

clrscr();

printf("Enter the Register No=");

scanf("%d",&no);

printf("\nEnter the Name=");

scanf("%s",na);

printf("\nEnter the Basic Mark=");

scanf("%d",&bm);

printf("\nEnter the Roxpro Mark=");

scanf("%d",&fm);

printf("\nEnter the Oracle Mark=");

scanf("%d",&om);

tot=bm+fm+om;

avg=tot/3.0;

if((bm>=35) && (fm>=35) && (om>=35))

{

strcpy(re,"PASS");

if(avg>=60)

strcpy(c,"FIRST");

else if(avg>=50)

strcpy(c,"SECOND");

else

strcpy(c,"THIRD");

}

else

{

strcpy(re,"FAIL");

}

printf("\n Total %d \n Average %f \n Result %s  \n Class %s",tot,avg,re,c);

getch();

}

 

No comments:

Post a Comment