line (x, y, x1, y1) (, ) (1, 1);
circle (x, y, radius) (x, y) radius ( );
arc (x, y, w1, w2, radius) (x, y), radius, w1 - , w2 ; , , , ;
fillellipse (x, y, xr, yr) (x, y), xr, yr ;
ellipse (x, y, w1, w2, xr, yr) (x, y), w1, w2 , xr, yr ;
lineto (x, y) (, );
moveto (x, y) (, );
rectangle (x, y, x1, y1) (x, y, x1, y1) );
bar (x, y, x1, y1) , ;
setlinestyle (x, y) (x y): 0-, 1-, 2 , 3 , 4 ; 1 , 3 .
: setfillstyle (pattern, color). 3 .
3. (pattern)
EMPTY_FILL | ||
SOLD_FILL | ||
LINE_FILL | --- | |
LSTLASH_FILL | /// | |
SLASH_FILL | /// | |
BKSLASH_FILL | \\\ | |
LTBKSLASH_FILL | \\\ | |
HATCH_FILL | ||
XHATCH_FILL | ||
INTERLEAVE_FILL | ||
WIDE_DOT_FILL | ||
CLOSE_DOT_FILL | ||
USER_FILL |
:
floodfill (x, y, color) , , color .
:
outtext () ;
outtextxy (x, y, ) (x, y).
1. , 10 .
1) BCW (Borland C++ for Windows) :
File New Project
2) (. 2) Project Path and Name ( ide);
. 2.
3) Platform DOS (Standart); , BGI Libraries;
|
|
4) OK, cpp -, . 3, , .
. 3.
#include <graphics.h>
#include <conio.h>
#include <dos.h>
void main (void)
{
int y = 200, r = 15, x= 5, i;
int a, b;
a = DETECT; //
initgraph (&a, &b, c:\\bc5\\bgi\\); /* BGI */
for (i = 0; i <= 10; i++)
{
setcolor(i);
circle(x, y, r);
setfillstyle(i, i);
floodfill(x, y, i);
x+=60;
delay(500);
}
getch();
closegraph();
}
- :
2. , [1] [ st; en ] Step .
# include <iostream.h> // cin, cout
# include <iomanip.h> // setprecision, setw
# include <conio.h> // clrscr(), getch()
# include <math.h> // sin(x)
# include <graphics.h>
# include <stdlib.h> // exit
// :
float F(float x);
void tabular_for(float Xst, float Xen, float Step);
float Fmodif(float x);
void graphF(float Xst, float Xen, float Step, int color);
void main()
{ clrscr();
float Xst, Xen, Step;
cout << "Tabulirovanie F(x).\n";
cout << "Xstart = "; cin>>Xst;
cout << "Xend = "; cin>>Xen;
cout << "Step = "; cin>>Step;
tabular_for(Xst, Xen, Step);
getch();
cout<<"\n Grafik F(x).\n";
cout<<"Xstart ="; cin>>Xst;
cout<<"Xend = "; cin>>Xen;
cout<<"Step = "; cin>>Step;
graphF(Xst, Xen, Step, 1); }
// :
float F(float x)
{ if(x == 0) return 1; else return sin(x)/x; }
void tabular_for(float Xst, float Xen, float Step)
{for(float x = Xst; x <= Xen; x += Step)
{ cout<<"\n x = " << setw(6)<<setprecision(2)<<x; // ;
cout<<" F(x) = "<<setw(6)<<setprecision(3)<<F(x);
} }
float Fmodif(float x)
{ if(x!= 0) return sin(x/6)/(x/6); else return 1; }
void graphF(float Xst, float Xen, float Step, int color)
{int gd=DETECT, gm, err;
// graph:
initgraph(&gd, &gm, ":\\bc5\\bgi");
// :
err = graphresult();
if (err!= grOk) // !
{cout<<"\n Error: "<< grapherrormsg(err); // ;
cout<<"\nEnter any kay:";
getch();
exit(1); // 1;
}
setbkcolor(15); // ;
setcolor(color); // ;
// :
int cX= (int) getmaxx()/2, cY= (int) getmaxy()/2;
float x, y;
line(0, cY, 2*cX, cY); // OX;
line(cX, 0, cX, 2*cY); // OY;
// :
for(x = Xst; x <= Xen; x += Step)
{ y = Fmodif(x); putpixel((int) x + cX, (int) -40*y + cY, color); }
getch(); }
. C++ Help - (\HELP\bcdos.hlp Borland Graphic Interface (BGI)).
|
|
:
F(x) [-1; 1] 0,4:
C++
++ getimage,imagesize, putimage putpixel. . getimage . :#include <graphics.h>void getimage (int left, int top, int right, int bottom, void far *bitmap), left, top, right bottom , , bitmap , . , . Borland C++. IBM PC , , . Windows.imagesize , . , 64-1 , imagesize 0xFFFF(-1). : #include <graphics.h> unsigned far imagesize (int left, int top, int right, int bottom). putimage , getimage, . : #include <graphics.h>void getimage (int left, int top, void far *bitmap int op), left top , , bitmap , , op , , , . putimage_op , 4. 4. putimage_opCOPY_PUT | 0 | |
XOR_PUT | 1 | |
OR_PUT | 2 | |
AND_PUT | 3 | |
NOT_PUT | 4 |
3. getimage putimage , . , .
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
int change(int current)
{
if (random(32767) > 30000)
{
switch (random(5))
{
case 0: return -2;
case 1: return -1;
case 2: return 0;
case 3: return 1;
case 4: return 2;
}
}
return current;
}
void main(void)
{
int gd = VGA, gm = VGAHI, i;
int StartX = 100, StartY = 50, r = 20;
int ulx, uly, lrx, lry, width, height, size;
int dx = 0, dy = 0;
int do_job = 1;
void *img;
initgraph(&gd, &gm, "c:\\bc5\\bgi");
setfillstyle(SOLID_FILL, getmaxcolor());
fillellipse(StartX, StartY, r, (r / 3) + 2);
ellipse(StartX, StartY - 4, 190, 357, r, r / 3);
line(StartX + 7, StartY - 6, StartX + 10, StartY - 12);
circle(StartX - 10, StartY - 12, 2);
line(StartX - 7, StartY - 6, StartX - 10, StartY - 12);
circle(StartX + 10, StartY - 12, 2);
ulx = StartX - (r + 1);
uly = StartY - 14;
lrx = StartX + (r + 1);
lry = StartY + (r / 3) + 3;
width = lrx - ulx + 1;
height = lry - uly + 1;
size = imagesize(ulx, uly, lrx, lry);
img = malloc(size);
getimage(ulx, uly, lrx, lry, img);
cleardevice();
for (i = 1; i < 1000; i++)
putpixel(random(640), random(480), random(16));
while (do_job)
{
putimage(StartX, StartY, img, XOR_PUT);
delay(50);
putimage(StartX, StartY, img, XOR_PUT);
dx = change(dx);
dy = change(dy);
StartX += dx;
StartY += dy;
if (StartX > 639 - width) StartX = 639 - width;
if (StartY > 479 - height) StartY = 479 - height;
|
|
if (StartX < 0) StartX = 0;
if (StartY < 0) StartY = 0;
if (kbhit()) do_job = (getch()!= ' ');
}
closegraph();
}
12
1. F [st; en] Step ; st, en Step . .
1.
2.
3.
4.
5.
6.
7.,
8.
9.
10.
11.
12.
13.
14.
15.
2. .
1. .
2. .
3. .
4. .
5. 30 .
6. .
7. , .
8. .
9. .
10. .
11. , .
12. , 45 .
13. .
14. .
15. .
;
;
;
-;
;
.
1. . . C ++. . .: .: , 2001. 241 .
2. .. /++. . .: , 2010.
3. . ++. . .: , 2003. 645 .
++
I , 220000 ,
220700 .