Graphics Editor code Using C++ Language
Write a Graphics Editor program to develop a graphics editor which includes features like line draw, rectangle draw,circle draw, pie chart draw,ellipse draw,polygon draw,bard raw, pixel draw,text draw etc.
Graphics Editor have a menu for user interaction from which user can provide input to program.By selecting appropriate option user will get output.
Graphics Editor code
#include #include #include #include #include class figures { int x1,y1,x2,y2,rad,xrad,yrad,startang,endang,midx,midy; public: figures() { x1=0; y1=0; x2=0; y2=0; rad=0; xrad=0; startang=0; endang=0; midx=getmaxx(); midy=getmaxy(); } ~figures() { void linedraw(void); void rectangledraw(void); void circledraw(void); void piechartdraw(); void ellipsedraw(void); void polygondraw(void); void bardraw(void); void pixeldraw(void); void textdraw(void); }; void figures::linedraw(void) { int gd=DETECT,gm; cout<<"x1 is "; cin>>x1; cout<<"y1 is "; cin>>y1; cout<<"x2 is "; cin>>x2; cout<<"y2 is "; cin>>y2; getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"A LINE"); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); setcolor(YELLOW); line(x1+midx,midy-y1,x2+midx,midy-y2); getch(); cleardevice(); closegraph(); } void figures::rectangledraw(void) { int gd=DETECT,gm; cout<<"x1 is "; cin>>x1; cout<<"y1 is "; cin>>y1; cout<<"x2 is "; cin>>x2; cout<<"y2 is "; cin>>y2; getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"A RECTANGLE"); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); setcolor(YELLOW); rectangle(x1+midx,midy-y1,x2+midx,midy-y2); getch(); cleardevice(); closegraph(); } void figures::circledraw(void) { int gd=DETECT,gm; cout<<"CENTER POINTS"<<endl; <br=""> cout<<"x1 is "; cin>>x1; cout<<"y1 is "; cin>>y1; cout<<"r is "; cin>>rad; getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"A CIRCLE"); //use setaspestratio setcolor(YELLOW); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); setcolor(YELLOW); circle(x1+midx,midy-y1,rad); getch(); cleardevice(); closegraph(); } void figures::ellipsedraw() { int gd=DETECT,gm; cout<<"CENTER POINTS"<<endl; <br=""> cout<<"x1 is "; cin>>x1; cout<<"y1 is "; cin>>y1; cout<<"horizontal axis is "; cin>>xrad; cout<<"vertical axis is "; cin>>yrad; cout<<"starting angle is "; cin>>startang; cout<<"ending angle is "; cin>>endang; getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"AN ELLIPSE"); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); setcolor(YELLOW); ellipse(x1+midx,midy-y1,startang,endang,xrad+midx,midy-yrad); getch(); cleardevice(); closegraph(); } void figures::piechartdraw(void) { int gd=DETECT,gm,d=0,i,sum=0; int a[10]; cout<<"how many data you want to enter"<<endl; <br=""> cin>>d; for(i=0;i<d-1;i++) <br=""> { cout<<"percentage of data "<<i+1<<" =="<<endl; cin>>a[i]; sum=sum+a[i]; } a[i]=100-sum; cout<<" percentage="" of="" data="" "<<i+1<<"="=" "<<100-sum<<endl;="" <br=""> getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"A PIECHART"); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); startang=0; endang=0; for(i=0;i<d;i++) <br=""> { startang=endang; endang=startang+(a[i]*360)/100; setfillstyle(SOLID_FILL,i+3); pieslice(midx,midy,startang,endang,150); } getch(); cleardevice(); closegraph(); } void figures::polygondraw() { int gd=DETECT,gm; int poly[20],i=0; char other; cout<<"Enter vertices of the polygon"<<endl; <br=""> do { cout<<"x is "; cin>>poly[i]; poly[i]=poly[i]+318; i++; cout<<"y is "; cin>>poly[i]; poly[i]=-poly[i]+237; i++; cout<<endl<<"want to="" enter="" again";="" <br=""> cin>>other; }while(other=='y'); //closing polygon poly[i++]=poly[0]; poly[i]=poly[1]; clrscr(); i=(i+1)/2; initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(RED); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); setfillstyle(SOLID_FILL,GREEN); //use fillpoly to fill color fillpoly(i,poly);//drawpoly(number of point we have entered,array); getch(); //includes closing point also therefore i+1 cleardevice(); closegraph(); } void figures::bardraw() { int gd=DETECT,gm,d=0,i,a[10],sum=0; cout<<"how many data you want to enter"<<endl; <br=""> cin>>d; for(i=0;i<d-1;i++) <br=""> { cout<<"percentage of data "<<i+1<<" =="<<endl; cin>>a[i]; sum=sum+a[i]; } a[i]=100-sum; cout<<" percentage="" of="" data="" "<<i+1<<"="=" "<<100-sum<<endl;="" <br=""> getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"A BARGRAPH"); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); for(i=0;i<d;i++) <br=""> { setfillstyle(SOLID_FILL,i+3); bar(45*(i+1)+midx,midy-((a[i]*100)/100),midx+(45*(i+1))+20,midy); //(width,height,dist from y axis,bottom down) } getch(); cleardevice(); closegraph(); } void figures::pixeldraw(void) { int gd=DETECT,gm; cout<<"x1 is "; cin>>x1; cout<<"y1 is "; cin>>y1; getch(); clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(4); outtextxy(20+x1,20+y1,"A PIXEL"); line(0,midy,midx*2,midy); line(midx,0,midx,2*midy); setcolor(YELLOW); outtextxy(midx+x1,midy-y1,"(x1,y1)"); putpixel(midx+x1,midy-y1,YELLOW); getch(); cleardevice(); closegraph(); } void figures::textdraw() //graphics textstyle //cprintf { int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi"); for(int i=0;i<4;i++) { textmode(i); cout<<"C"; getch(); } closegraph(); } void main(void) { figures draw; int ch,ch1,i,n; clrscr(); do { clrscr(); draw.menu(); cin>>ch; switch(ch) { case 1: clrscr(); cout<<"HOW MANY LINE U WANT:"; cin>>n; for(i=0;i<n;i++) <br=""> draw.linedraw(); break; case 2: clrscr(); cout<<"HOW MANY LINE U WANT:"; cin>>n; for(i=0;i<n;i++) <br=""> draw.circledraw(); break; case 3: clrscr(); draw.ellipsedraw(); break; case 4: clrscr(); draw.piechartdraw(); break; case 5: clrscr(); draw.polygondraw(); break; case 6: clrscr(); draw.bardraw(); break; case 7: cout<<"HOW MANY LINE U WANT:"; cin>>n; for(i=0;i<n;i++) <br=""> draw.pixeldraw(); break; case 8: draw.rectangledraw; break; case 9: draw.textdraw(); break; case 10: break; default: cout<<"\nINVALID CHOICE"; } }while(ch!=9); getch(); }