rew
Full Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору вот когда писал по этому поводу Код: #include <stdio.h> #include<stdlib.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<dos.h> //#define bgipath "a:\\bgi" #define bgipath "d:\\borlandc\\bgi" class axes { private: int xcent,ycent,xend,yend; float x,xt,y,yt,a,b,c; void init(); public: int x0,y0;//nachalo otnositel`no (0,0) ekrana int xmin,ymin;//nachlo okna otnositelno (x0,y0) int xmax,ymax;//konec"""""""""""""""" int bc,gc,fc;//border color,grid color,fill color int gstp;//zoomgrid step int grdstp; //grid step float fstp; //func step float zoom; //zoom int ax;//show grid on/off //axes4(int x0,int y0,int xmin,int ymin,int xmax,int ymax,int bc,int gc,int fc,int ax);//constructor //axes(int,int,int,int,int,int,int,int,int,int,int,int); axes() { x0=y0=20; xmin=-120;xmax=120; ymin=-100;ymax=100; bc=12; gc=10; fc=7; zoom=1; grdstp=1; fstp=zoom/10.0; gstp=1/fstp*grdstp; ax=1; a=1; b=16; c=8; } //end of constructor */ void draw_grid(); void draw_function(); void clear(); }; //end of class void graphit (char *path) { int gd, gm , err ; gd = 9 ; gm = 2 ; initgraph (&gd, &gm, path); err = graphresult(); /* an error occurred */ if (err != grOk) { printf("Graphics error: %s\n", grapherrormsg(err)); printf("Press any key to halt:"); getch(); exit(1); } } void axes::init() { xcent=x0-xmin; ycent=y0+ymax; xend=xcent+xmax; yend=ycent-ymin; fstp=zoom/1.0; gstp=18/fstp*3.141592*grdstp; } void axes::clear() { init(); setfillstyle(1,0); bar(x0,y0,xend,yend); } void axes::draw_grid() { init(); if(xend>639) //?????? xend=639; //?????? if(yend>479) //?????? yend=479; //?????? setcolor(bc); rectangle(x0,y0,xend,yend); setcolor(fc); if(ycent>y0&&ycent<yend) line(x0,ycent,xend,ycent); else { setcolor(fc-2); if(ycent<=y0) line(x0,y0,xend,y0); else line(x0,yend,xend,yend); } setcolor(fc); if(xcent>x0&&xcent<xend) line(xcent,y0,xcent,yend); else { setcolor(fc-2); if(xcent<=x0) line(x0,y0,x0,yend); else line(xend,y0,xend,yend); } if(gstp<2) gstp=0; if(gstp&&ax) { for(x=-xmin%gstp+x0;x<xend;x+=gstp) for(y=ymax%gstp+y0;y<yend;y+=gstp) if(x>x0&&y>y0) putpixel(x,y,gc); } } void axes::draw_function() { int sign; init(); for(x=xmin,xt=xmin*fstp;x<=xmax;x++,xt+=fstp) { y=sin((3.141592/180)*xt)*180/3.141592;//a*pow(xt,2)+b*xt+c; yt=sin((3.141592/180)*(xt+fstp))*180/3.141592;//a*pow((xt+fstp),2)+b*(xt+fstp)+c; sign=y<yt?1:-1; while(y*sign<yt*sign) { if(y/fstp>ymin&&y/fstp<ymax) { putpixel(x+xcent,ycent-y/fstp,4); //delay(1); } y+=sign*fstp; } } } void main() { char ch=' '; float zom[2]={10,10}; int i,up[2]={100,100},down[2]={-100,-100},left[2]={-100,-100},right[2]={100,100},step[2]={1,1},pres=0,grdstp[2]={1,1}; axes m[2];//(10,50,-100,-60,120,130,10,14,4,3,1); graphit (bgipath) ; m[1].x0=300; m[1].y0=50; m[0].x0=50; m[0].y0=50; for(i=0;i<2;i++) { m[i].xmin=left[i]; m[i].xmax=right[i]; m[i].ymin=down[i]; m[i].ymax=up[i]; m[i].zoom=zom[i]; m[i].draw_grid(); m[i].draw_function(); } while(ch!='q') { ch=getch(); switch(ch) { case 'e':up[pres]-=step[pres];down[pres]-=step[pres];break; case 'x':up[pres]+=step[pres];down[pres]+=step[pres];break; case 'd':left[pres]-=step[pres];right[pres]-=step[pres];break; case 's':left[pres]+=step[pres];right[pres]+=step[pres];break; case '6':zom[pres]+=.1;break; case '5':if(zom[pres]>0.1)zom[pres]-=.1;break; case '7':if(step[pres]) step[pres]--;break; case '8':step[pres]++;break; case 'h':up[pres]=100;down[pres]=-100;left[pres]=-100;right[pres]=100;break; case '1':pres=0;break; case '2':pres=1;break; case 'o':if(grdstp[pres]>1)grdstp[pres]--;break; case 'p':grdstp[pres]++; } m[pres].grdstp=grdstp[pres]; m[pres].xmin=left[pres]; m[pres].xmax=right[pres]; m[pres].ymin=down[pres]; m[pres].ymax=up[pres]; m[pres].zoom=zom[pres]; m[pres].clear(); m[pres].draw_grid(); m[pres].draw_function(); } getch(); } | на борланд си под досом даже работало, рисовало синус, можно было двигать и зумить, правда это "с++", но переделать под просто си не сложно по моему |