#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
int OpenGraph();
int CloseGraph();
void ShowDecart(int X2, int Y2);
int GetX(int X2, double x);
int GetY(int Y2, double y);
double Function(double x);
void Shedule(double a, double b, int X2, int Y2);
int main (void){
OpenGraph();
const int X = getmaxx();
const int Y = getmaxy();
const int X2 = X / 2;
const int Y2 = Y / 2;
ShowDecart(X2, Y2);
Shedule(-100, 100, X2, Y2);
getche();
CloseGraph();
return 0;
}
double Function(double x){
return fabs(x);
}
void Shedule(double a, double b, int X2, int Y2){
double x = a;
double step = .1;
while (x <= b + step / 2){
putpixel(GetX(X2, x), GetY(Y2, Function(x)), RED);
x += step;
}
}
int OpenGraph(){
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc\\tc\\bgi");
return graphresult();
}
int CloseGraph(){
closegraph();
return graphresult();
}
void ShowDecart(int X2, int Y2){
int delta = 200;
int d = delta / 10;
line(X2 - delta, Y2, X2 + delta, Y2);
line(X2, Y2 - delta, X2, Y2 + delta);
int i = X2 - delta;
while (i <= X2 + delta){
if ((i > X2) && (i < X2 + delta)){
char *s;
itoa((i - X2) / d, s, 10);
outtextxy(i - 3, Y2 + 5, s);
}
circle(i, Y2, 1);
i += d;
};
i = Y2 - delta;
while (i <= Y2 + delta){
if ((i > Y2) && (i < Y2 + delta)){
char *s;
itoa((i - Y2)/ d, s, 10);
outtextxy(X2 - 10, i - 3, s);
}
circle(X2, i, 1);
i += d;
};
}
int GetX(int X2, double x){
return X2 + int(x);
}
int GetY(int Y2, double y){
return Y2 - int(y);
}
Может кому пригодится