Բ ² CI
Ѳ.
1. Ͳ Ͳ ²Ҳ
1.1 Ѳ graphics.h, 䒺 #include
#include <graphics.h>
initgraph, :
initgraph(int *driver, int *mode, char *path);
driver . , detect (0).
( ) , mode. mode=0. Path ( bgi).
closegraph() restorecrtmode().
.
arc(int x, int y, int start, int end, int radius) (x,y) radius start end, .
bar(int left, int top, int right, int bottom) - (left,top) (right,bottom) , .
rectangle (int left, int top, int right, in bottom) - .
bar3d(int left, int top, int right, int bottom, int depth, int topflag) - , . bar. depth . topflag (1) (0).
circle(int x, int y, int radius) - (x,y) radius.
cleardevice() - (0,0).
clearviewport() - (0,0) ).
drawpoly(int numpoints, int *points) - , numpoints. *points .
fillpoly(int numpoints, int *points) - .
line(int x1, int y1, int x2, int y2) - 璺 (x1,y1), (x2,y2) .
lineto(int x, int y) - (x,y).
linerel(int deltax, int deltay) - , deltax y deltay.
moveto(int x, int y) - (x,y).
outtext(char *str) - .
outtextxy(int x, int y, char *str) - str, (x,y).
|
|
getbkcolor() - .
getcolor() - .
getmaxcolor() - .
getmaxx() - - x.
getmaxy() - - y.
getx() - x.
gety() - y.
ellipse(int x, int y, int start, int end, int xr, int yr) - (x,y), xr, yr. start end .
fillellipse(int x, int y, int xr, int yr) - .
floodfill(int x, int y, int border) - ᒺ . (x,y)- ᒺ. border .
putpixel(int x, int y, int color) - (x,y) color.
setbkcolor(int color) - color.
setcolor(int color) - . 0, 1, 2, 3,...,15 :
BLACK=0
BLUE=1
GREEN=2
CYAN=3
RED=4
MAGENTA=5
BROWN=6
LIGHTGRAY=7
DARKGRAY=8
LIGHTBLUE=9
LIGHTGREEN=10
LIGHTCYAN=11
LIGHTRED=12
LIGHTMAGENTA=13
YELLOW=14
WHITE=15
setfillstyle(int pattern, int color) - pattern color . pattern 0 12 (0- , 1- , 2- , 3- , 4- , 5- ,...).
setlinestyle(int style, unsigned pattern, int width) - .
style: SOLID_LINE , DOTTED_LINE , CENTER_LINE - , DASHED_LINE , USERBIT_LINE , (pattern). width (): NORM_WIDTH 1 , THICK_WIDTH 3 . pattern USERBIT_LINE, , . (1) (0) . , pattern =0xFFFF, - 0x00FF;
settextstyle(int font, int direction, int size) - . font ( 0 10), direction (0 HORIZ_DIR) (1 VERT_DIR), size , ( 0 10).
setviewport(int left, int top, int right, int bottom, int clip) - . - (left,top), (right,bottom). clip =1, , , .
1. y=10sin(x)-0.2x2cos(x)+5x+7 -10 10.
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <float.h>
#include <stdlib.h>
void koordsystem();
/* */
int graphik(float x,float xmax,float y,float ymax,int color);
/* ; (x,y)- ; xmax- - x;ymax- - y; color- */
|
|
void main(void)
{int driver, mode;
float y,x;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,"c:\\borlandc\\bgi");
/* */
setbkcolor(WHITE);
/* */
koordsystem();
/* */
x=-10;
while(x<10)
/* */
{y=10*sin(x)*x-0.2*x*x*cos(x)+5*x+7;
graphik(x,10,y,200,CYAN);
/* */
x=x+0.0001;}
getch();
/* */
restorecrtmode();
/*³ */
}
void koordsystem()
{setcolor(RED);
line(10,getmaxy()/2,getmaxx()-10,getmaxy()/2);
line(getmaxx()/2,10,getmaxx()/2,getmaxy()-10);
/* */
outtextxy(getmaxx()/2+10,10,"y");
outtextxy(getmaxx()-20,getmaxy()/2+10,"x");
outtextxy(getmaxx()/2-10,getmaxy()/2+10,"0");
/* */
}
int graphik(float x,float xmax,float y,float ymax,int color)
{float d,f;
d=x*(getmaxx()/2-10)/xmax;
f=y*(getmaxy()/2-10)/ymax;
putpixel(int(d+getmaxx()/2),int(-f+getmaxy()/2),color);
/* int float int*/
return 0;
}
1.2 getimage() putimage(). getimage() :
getimage(x1,y1,x2,y2,__);
, x1,y1,x2,y2 ( ), , __. , ᒺ , , void:
void *pimage;
' malloc(), :
void *malloc('___);
ᒺ , 0 .
imagesize(), :
imagesize(x1,y1,x2,y2);
putimage(). :
putimage(x1, y1, , _);
x1, y1 . _ , , , . : COPY_PUT , XOR_PUT , OR_PUT - , AND_PUT - , NOT_PUT Ͳ.
2. , .
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
void main(void)
{
const int r=10;
const float h=0.005, A=2, w=10, tmax=2;
int errorcode,xstart, ystart,gd=DETECT,gm=0;
double x,y;
float mx,my;
int xend, yend,xst_limit,yst_limit,xend_limit,yend_limit,size;
void *pimage;
initgraph(&gd,&gm,"C:\\TC\\BGI");
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s\n;",grapherrormsg(errorcode));
printf("Press any key to exit");
getch();
exit(1);
}
xst_limit=0.1*getmaxx();
yst_limit=0.1*getmaxy();
xend_limit=0.9*getmaxx()-2*r;
yend_limit=0.9*getmaxy()-2*r;
mx=(xend_limit-xst_limit)/(w*tmax);
my=(yend_limit-yst_limit)/(2*A);
setfillstyle(SOLID_FILL,RED);
fillellipse(xst_limit+r,(yst_limit+yend_limit)/2,r,r);
size=imagesize(xst_limit,-r+(yst_limit+yend_limit)/2,xst_limit+2*r,r+(yst_limit+yend_limit)/2);
pimage=malloc(size);
getimage(xst_limit,-r+(yst_limit+yend_limit)/2,xst_limit+2*r,r+(yst_limit+yend_limit)/2,pimage);
cleardevice();
setbkcolor(LIGHTGRAY);
|
|
x=0;
do
{
y=A*sin(x);
xstart=xst_limit+mx*x;
ystart=-r+(yst_limit+yend_limit)/2-my*y;
putimage(xstart,ystart,pimage,XOR_PUT);
delay(1);
x+=h;
putimage(xstart,ystart,pimage,XOR_PUT);
}
while(xend_limit-xstart-2*r>0);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
outtextxy(0.4*getmaxx(),0.7*getmaxy(),"Press any key");
getch();
closegraph();
}
2.
Ѳ, .
2.1. , . Գ
2.2. , .
2.3. , - .
2.4. , - .
2.5. , - .
2.6. X 0 2. , . W .
2.7. X 0 1. , . B .
2.8. 2 X 0 5. , . , B W .
2.9. X 0 3. , . W .
2.10. , X 0 20. , . ,B,C W .
3. Ͳ
3.1. .
3.2. .
3.3. .
3.4. .
3.5. .
' 18