输入时用后缀,开头空格
#include <easyx.h>
#include <stdio.h>
#define PI 3.141592653589793
#define E 2.718281828459045
#define K (1.0 / 256.0)
#define K_1 256.0
//#define LINE//决定函数是用线画还是用点画
struct C {
double i;
double r;
C operator = (C n) {
i = n.i; r = n.r;
return C({ i, r });
}
C operator + (C n) {
return C({ i + n.i, r + n.r });
}
C operator - (C n) {
return C({ i - n.i, r - n.r });
}
C operator * (C n) {
return C({ r * n.i + i * n.r, r * n.r - i * n.i});
}
C operator / (C n) {
return C({
(i * n.r - r * n.i) / (n.i * n.i - n.r * n.r),
(i * n.i + r * n.r) / (n.i * n.i - n.r * n.r)
});
}
void print() {
printf("%lfi%+lf", i, r);
}
};
int top = 0;
int len = 0;
int p[4096][2];
char str[512];
C stack[512];
void getnum(int l) {
bool k = false;
double x = 1.0;
stack[top] = C({ 0, 0 });
for (int i = l; str[i] != ' ' && str[i] != '\0'; i++) {
if (k) x *= 10;
if (str[i] != '.')
stack[top] = stack[top] * C({ 0, 10 }) + C({ 0, double(str[i] - '0') });
else k = true;
}
stack[top] = stack[top] / C({ 0, x });
top++;
}
void del(C c) {
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == ' ') {
i++;
if (str[i] >= '0' && str[i] <= '9')
getnum(i);
if (str[i] == 'e')
stack[top++] = C({ 0, E });
if (str[i] == 'x')
stack[top++] = c;
if (str[i] == '+') {
top--;
stack[top - 1] = stack[top - 1] + stack[top];
}
if (str[i] == '-') {
top--;
stack[top - 1] = stack[top - 1] - stack[top];
}
if (str[i] == '*') {
top--;
stack[top - 1] = stack[top - 1] * stack[top];
}
if (str[i] == '/') {
top--;
stack[top - 1] = stack[top - 1] / stack[top];
}
}
}
p[len][0] = 512 + int(stack[0].r * K_1 + 0.5);
p[len][1] = 512 - int(stack[0].i * K_1 + 0.5);
#ifndef LINE
putpixel(p[len][0], p[len][1], RGB(0, 255, 255));
#endif
len++;
}
int main() {
initgraph(1024, 1024, EX_SHOWCONSOLE);
setlinecolor(RGB(0, 255, 255));
gets_s<512>(str);
for (int y = -1024; y < 1024; y += 16) {
len = 0;
for (int x = -1024; x < 1024; x += 1) {
top = 0;
C c = { y * K, x * K };
del(c);
}
#ifdef LINE
for (int i = 0; i < len - 1; i++) {
line(p[i][0], p[i][1], p[i + 1][0], p[i + 1][1]);
}
#endif
}
for (int y = -1024; y < 1024; y += 16) {
len = 0;
for (int x = -1024; x < 1024; x += 1) {
top = 0;
C c = { x * K, y * K };
del(c);
}
#ifdef LINE
for (int i = 0; i < len - 1; i++) {
line(p[i][0], p[i][1], p[i + 1][0], p[i + 1][1]);
}
#endif
}
printf("%d", getchar());
saveimage(L"1.jpg");
closegraph();
}