Новичок
Профиль
Группа: Участник
Сообщений: 10
Регистрация: 22.6.2007
Репутация: нет Всего: нет
|
Всем доброго времени суток!я написал в C++ v3 for Dos класс TShape и создал дочерние классы Head,Smile i Bor.Далее поместил в список фигуры(произвольно).Теперь мне необходимо нарисовать рамку вокруг этого списка,причем фигуры могут сочетатся в разном порядке,мне это надо учитывать.Теперь мне нужно определить самый крайний левый угол и самый нижний правый,чтоб нарисовать прямоугольник.Помогите пожалуйста.вот код: | Код | #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<iostream.h> #include<graphics.h> #include<string.h>
class TShape { protected: float lx,ly,rx,ry,color; public: TShape(float,float,float,float,float); virtual void move(int,int); virtual void show()=0; virtual void hide()=0; virtual void size(int); float getlx() {return lx;}; float getly() {return ly;}; float getrx() {return rx;}; float getry() {return ry;}; // int flag(){return flag;}; void setlx(float a) {lx=a;}; void setly(float a) {ly=a;}; void setrx(float a) {rx=a;}; void setry(float a) {ry=a;}; virtual int typeofshape()=0; int getcol() {return color;}; void setcol(int c) {color=c;}; float maxx() {return rx;}; float maxy() {return ry;}; float minx() {return lx;}; float miny() {return ly;}; };
TShape::TShape(float x,float y,float xx, float yy, float cc) { setcol(cc); lx=x; ly=y; rx=xx; ry=yy; }
void TShape::move(int dx,int dy) { hide(); setlx(getlx()+dx); setrx(getrx()+dx); setly(getly()+dy); setry(getry()+dy); setcolor(getcol()); show(); } void TShape::size(int p) { float y1,y2; hide(); setlx(getlx()-p); setly(getly()-p); setrx(getrx()+p); setry(getry()+p); y1=getly(); y2=getry(); if(y2-y1<=2) { size(1); return; } setcol(6); show(); }
class TSmile:public TShape {protected: int x1,x2,x3,y1,y2,y3,x4,y4,radius1,radius2,radius3,radius4; public: TSmile(float x,float y, float xx, float yy,float cc):TShape(x,y,xx,yy,cc) {x1=(getrx()-getlx())/2; y1=(getry()-getly())/2; radius1=60; x2=x1-20; setcol(cc); y2=y1-20; radius2=10; x3=x1+20; y3=y1-20; radius3=radius2; radius4=40; }; int getradius1() {return radius1;}; int getradius2() {return radius2;}; int getradius3() {return radius3;}; int getradius4() {return radius4;}; int getx1() {return x1;}; int getx2() {return x2;}; int getx3() {return x3;}; int getx4() {return x4;}; int gety1() {return y1;}; int gety2() {return y2;}; int gety3() {return y3;}; int gety4() {return y4;}; void setxy1(int a,int b) {x1=a;y1=b;}; void setxy2(int a,int b) {x2=a;y2=b;}; void setxy3(int a,int b) {x3=a;y3=b;}; void setxy4(int a,int b) {x4=a;y4=b;}; void setradius1(int a) {radius1=a;}; void setradius2(int a) {radius2=a;}; void setradius3(int a) {radius3=a;}; void setradius4(int a) {radius4=a;}; void setxyradius1(int,int,int); void setxyradius2(int,int,int); void setxyradius3(int,int,int); void setxyradius4(int,int,int); void show(); void hide(); // void zalivka(int a){return a;}; int getcol() {return color;}; void setcol(int c) {color=c;};
void move(int,int); void size(int); virtual int typeofshape() {return 1;}; };
/*TSmile::TSmile() { x1=(getrx()-getlx())/2; y1=(getry()-getly())/2; radius1=60; x2=x1-20; y2=y1-20; radius2=10; x3=x1+20; y3=y1-20; radius3=radius2; radius4=40;
} */ void TSmile::setxyradius1(int a,int b,int c) { x1=a; y1=b; radius1=c; }
void TSmile::setxyradius2(int a,int b,int c) { x2=a; y2=b; radius2=c; }
void TSmile::setxyradius3(int a,int b,int c) { x3=a; y3=b; radius3=c; }
void TSmile::setxyradius4(int a,int b,int c) { x4=a; y4=b; radius4=c; }
void TSmile::show() { x1=getx1(); y1=gety1(); radius1=getradius1(); setxyradius1(x1,y1,radius1); setcolor(getcol()); circle(x1,y1,radius1); x2=getx2(); y2=gety2(); radius2=getradius2(); setxyradius2(x2,y2,radius2); setcolor(getcol()); circle(x2,y2,radius2); x3=getx3(); y3=gety3(); radius3=getradius3(); setxyradius3(x3,y3,radius3); setcolor(getcol()); circle(x3,y3,radius3); radius4=getradius4(); setxyradius4(x1,y1,radius4); setcolor(getcol()); arc(x1,y1,225,315,radius4);
}
void TSmile::hide() {setcolor(0); circle(getx1(),gety1(),getradius1()); setcolor(0); circle(getx2(),gety2(),getradius2()); setcolor(0); circle(getx3(),gety3(),getradius3()); setcolor(0); arc(getx1(),gety1(),225,315,getradius4());
}
void TSmile::move (int dx,int dy) { hide(); setxy1(getx1()+dx,gety1()+dy); setxy2(getx2()+dx,gety2()+dy); setxy3(getx3()+dx,gety3()+dy); setxy4(getx4()+dx,gety4()+dy); show(); }
void TSmile::size(int dz) {int x; hide(); x=getradius1(); setradius1(getradius1()+dz*3); setradius2(getradius2()+dz); setradius3(getradius3()+dz); setradius4(getradius4()+dz*2); setxy2(getx2()-dz,gety2()-dz); setxy3(getx3()+dz,gety3()-dz); if((radius1<=20)||(radius2<=4)||(radius3<=4)||(radius4<=15)) { size(1); return; } show();
}
class TBor:public TShape {protected: float x1,y1,x2,y2,x3,y3; public: TBor(float x,float y, float xx, float yy, float cc):TShape(x,y,xx,yy,cc) {x1=(getrx()-getlx())/2+20; y1=(getry()-getly())/2+50; x2=x1-40; y2=y1; x3=x1-20; y3=y1+20; setcol(cc); }; float getx1() {return x1;}; float getx2() {return x2;}; float gety1() {return y1;}; float gety2() {return y2;}; float getx3() {return x3;}; float gety3() {return y3;}; int typeofshape() {return 2;}; void setxy1(float a,float b) {x1=a;y1=b;}; void setxy2(float a,float b) {x2=a;y2=b;}; void setxy3(float a,float b) {x3=a;y3=b;}; void show(); void hide(); void move(int,int); void size(int); int getcol() {return color;}; void setcol(int c) {color=c;};
};
/*TBor::TBor() { x1=(getrx()-getlx())/2+20; y1=(getry()-getly())/2+50; x2=x1-40; y2=y1; x3=x1-20; y3=y1+20;
} */
void TBor::show() { x1=getx1(); y1=gety1(); x2=getx2(); y2=gety2(); x3=getx3(); y3=gety3(); setxy1(x1,y1); setxy2(x2,y2); setxy3(x3,y3); setcolor(getcol()); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1);
}
void TBor::hide() {setcolor(0); line(getx1(),gety1(),getx2(),gety2()); line(getx2(),gety2(),getx3(),gety3()); line(getx3(),gety3(),getx1(),gety1());
}
void TBor::move (int dx,int dy) { hide(); setxy1(getx1()+dx,gety1()+dy); setxy2(getx2()+dx,gety2()+dy); setxy3(getx3()+dx,gety3()+dy); show(); } void TBor::size (int dz) {int x,xx; hide(); setxy1(getx1()+dz*2,gety1()+2*dz); setxy2(getx2()-dz*2,gety2()+2*dz); setxy3(getx3(),gety3()+dz*4); x=getx1(); xx=getx2(); if((x-xx)<=20) { size(1); return; } show();
}
class THair:public TShape { protected: int x1,y1,i,radius1,radius2; public: THair(float x,float y, float xx, float yy, float cc):TShape(x,y,xx,yy,cc) {setcol(cc); x1=(getrx()-getlx())/2; y1=(getry()-getly())/2-60; radius1=30; radius2=15; }; int getx1() {return x1;}; int getradius1() {return radius1;}; int getradius2() {return radius2;}; int gety1() {return y1;}; void setxy1(int a,int b) {x1=a;y1=b;}; void setradius1(int a) {radius1=a;}; void setradius2(int a) {radius2=a;}; void show(); void hide(); void move(int,int); void size(int); int typeofshape() {return 3;}; int getcol() {return color;}; void setcol(int c) {color=c;};
};
/*THair::THair() { flag=3; x1=(getrx()-getlx())/2; y1=(getry()-getly())/2-60; radius1=30; radius2=15;
} */
void THair::show() { x1=getx1(); y1=gety1(); radius1=getradius1(); radius2=getradius2(); int j,k,l,m;arccoordstype e; for (i=0;i<10;i++) { setcolor(0); arc(x1,y1,i*36,i*36+36,radius2); getarccoords(&e); j=e.xstart; k=e.ystart; l=e.xend; m=e.yend; arc(x1,y1,i*36+36,i*36+72,radius1); getarccoords(&e); setcolor(getcol()); line(j,k,e.xstart,e.ystart); line(e.xstart,e.ystart,l,m); }
} void THair::hide() {setcolor(0); int j,k,l,m;arccoordstype e; for (i=0;i<10;i++) { setcolor(0); arc(getx1(),gety1(),i*36,i*36+36,getradius2()); getarccoords(&e); j=e.xstart; k=e.ystart; l=e.xend; m=e.yend; arc(getx1(),gety1(),i*36+36,i*36+72,getradius1()); getarccoords(&e); setcolor(0); line(j,k,e.xstart,e.ystart); line(e.xstart,e.ystart,l,m); }
}
void THair::move (int dx,int dy) { hide(); setxy1(getx1()+dx,gety1()+dy); show(); } void THair::size(int dz) {int y1,y2; hide(); setradius1(getradius1()+dz); setradius2(getradius2()+dz); setxy1(getx1(),gety1()-3*dz); if((radius1<=2)||(radius2<=8)) { size(1); return; } show();
}
class TSpis {private:TShape *shape; TSpis *next; public: TSpis() { shape=NULL; next=NULL; };
~TSpis() { if(shape) delete shape; if(next) delete next; }; void setshape(TShape *a) {shape=a;}; void setnext(TSpis *a) {next=a;}; TShape *getshape() {return shape;}; TSpis *getnext() {return next;}; };
class TList {protected: TSpis *head; public: TList() {head=NULL;}; TSpis *getlist() {return head;}; void add(TShape *b) { if(head==NULL) { head=new TSpis; head->setshape(b); head->setnext(NULL); } else {TSpis *tmp; tmp=new TSpis; tmp->setshape(b); tmp->setnext(head); head=tmp; }}; void stshow() {TSpis *tmp; tmp=new TSpis; tmp=head; while(tmp!=NULL) {tmp->getshape()->show(); tmp=tmp->getnext();}};
void move(int dx, int dy) {TSpis *tmp; tmp=new TSpis; tmp=head; while(tmp!=NULL) {tmp->getshape()->move(dx,dy); tmp=tmp->getnext(); }};
void size(int dz) {TSpis *tmp; tmp=new TSpis; tmp=head; while(tmp!=NULL) {tmp->getshape()->size(dz); tmp=tmp->getnext();}};
TList operator + (TList a) { TSpis *tmp=head, *tmp2=a.head; TList b; float x1,y1,x2,y2; while(tmp!=NULL) { x1=tmp->getshape()->getlx(); y1=tmp->getshape()->getly(); x2=tmp->getshape()->getrx(); y2=tmp->getshape()->getry(); switch(tmp->getshape()->typeofshape()) { case 1: b.add(new TSmile(x1,y1,x2,y2,14)); break; case 2: b.add(new TBor(x1,y1,x2,y2,3)); break; case 3: b.add(new THair(x1,y1,x2,y2,6)); break; } tmp=tmp->getnext(); } while(tmp2!=NULL) { x1=tmp2->getshape()->getlx(); y1=tmp2->getshape()->getly(); x2=tmp2->getshape()->getrx(); y2=tmp2->getshape()->getry(); switch(tmp2->getshape()->typeofshape()) { case 1: b.add(new TSmile(x1,y1,x2,y2,14)); break; case 2: b.add(new TBor(x1,y1,x2,y2,3)); break; case 3: b.add(new THair(x1,y1,x2,y2,6)); break; } tmp2=tmp2->getnext(); } return b;}; };
void main() {int gdriver = DETECT, gmode, errorcode; int midx, midy, i; initgraph(&gdriver, &gmode, "c:\\Bc\\Bgi"); errorcode = graphresult(); if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1);}
TList *sp,a,b,l,*c; sp=new TList; a.add(new TSmile(0,0,600,400,14)); b.add(new TBor(0,0,600,4030,3)); l.add(new THair(0,0,600,400,6)); c=new TList; c->add(new TSmile(0,0,600,400,14)); c->add(new TBor(0,0,600,400,3)); c->add(new THair(0,0,600,400,6)); // l.stshow(); *sp=a+b; sp->stshow(); int key,fl=0; getch(); key=getch(); while(key!=27) { switch(key) { case 72:sp->move(0,-5);if (fl==1)c->stshow();break; case 80:sp->move(0,5);if (fl==1)c->stshow();break; case 75:sp->move(-5,0);if (fl==1)c->stshow();break; case 77:sp->move(5,0);if (fl==1)c->stshow();break; case 43:sp->size(5);if (fl==1)c->stshow();break; case 45:sp->size(-5);if (fl==1)c->stshow();break; case 49:c->stshow();fl=1; case 9: int key1; getch(); key1=getch(); while(key1!=9) { switch(key1) {case 72:sp->stshow();c->move(0,-5);break; case 80:sp->stshow();c->move(0,5);break; case 75:sp->stshow();c->move(-5,0);break; case 77:sp->stshow();c->move(5,0);break; case 43:sp->stshow();c->size(5);break; case 45:sp->stshow();c->size(-5);break;
} key1=getch(); } break; } key=getch(); }
closegraph(); }
|
Это сообщение отредактировал(а) Daevaorn - 8.12.2008, 00:21
|