Sie sind auf Seite 1von 7

IMPLEMENTATION OF LINE, CIRCLE AND ELLIPSE ATTRIBUTES DESCRIPTION: Output primitives have geometric and non-geometric attributes.

Geometric attributes, such as the character height, affect the size and shape of a primitive, whereas non-geometric attributes are qualities such as colour, line style, etc. The output primitives Such as Line, Circle and Ellipse are associated with set of attributes such as Line (color and Line Style), Cicrle (Color) and Ellipse (Color and Patterns). CODING: #include<graphics.h> /* include the necessary header files*/ #include<stdlib.h> #include<stdio.h> #include<conio.h> int main(void) { /* select a driver and mode that supports */ /* multiple drawing colors.*/ int gdriver=EGA,DETECT,gmode=EGAHI,errorcode; int color,maxcolor,x,y,s,ch,ch1,ch2,i; int midx,midy; int radius=100; int xradius=100,yradius=50;

char msg[80]; char *lname[]={"Solid Line", "Dotted Line", "Center Line", "Dashed Line", "Usebit Line"}; /* initialize graphics and local variables */ initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); /* read result of initialization */ errorcode=graphresult(); if (errorcode!=grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } do{ printf("\n1.Line\n2.Circle\n3.Ellipse\n"); /* get the user choice*/ printf("\nEnter Your choice\n"); scanf("%d",&ch); switch(ch) { case 1: printf("Attribute: 1.Color 2.Style:\n"); scanf("%d",&ch1); switch(ch1)

{ case 1: maxcolor=getmaxcolor(); /* use predefined methods to change the color*/ x=getmaxx()/2; y=getmaxy()/2; for(color=1;color<=maxcolor;color++) { cleardevice(); setcolor(color); line(100,100,100,300); sprintf(msg,"Color:%d",color); outtextxy(x,y,msg); getch(); } closegraph(); break; case 2: initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); for(s=0;s<5;s++) { setlinestyle(s,1,1); /* pre defined method for linestyle*/ line(20,20+s*50,120,120+s*50); outtextxy(125,120+s*50,lname[s]);

} getch(); closegraph(); break; } break; case 2: initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; maxcolor=getmaxcolor(); /* draw circles of different colors*/ for(color=1;color<=maxcolor;color++) { cleardevice(); setcolor(color); /* draw the circle */ circle(midx,midy,radius); /* clean up */ getch(); } closegraph(); break; case 3:

printf("\n1.pattern 2.colour\n"); /* get choice for color or style of eclipse*/ printf("\nEnter your choice:\n"); scanf("%d",&ch2); switch(ch2) { case 1: /* initialize graphics and local variables */ initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; /* loop through the fill patterns */ for(i=EMPTY_FILL;i<USER_FILL;i++) { /* set fill pattern */ setfillstyle(i,getmaxcolor()); /* draw a filled ellipse */ fillellipse(midx, midy, xradius, yradius); getch(); } closegraph(); break; case 2: initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

maxcolor=getmaxcolor(); for(color=1;color<=maxcolor;color++) { cleardevice(); setcolor(color); ellipse(100,200,0,360,xradius,yradius); getch(); } /* clean up */ closegraph(); break; } default: /exit(0); break; } } while(ch==3); return 0; } OUTPUT: Line Color Line Style

Circle Color Ellipse Pattern Ellipse Color RESULT: Thus the attributes were successfully applied to Line, circle and ellipse and the output is drawn and verified.

Das könnte Ihnen auch gefallen