第一行:0 或 1
第二行:(空格)+函数(后缀)
#pragma warning(disable:4996)
#include <easyx.h>
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
#define E 2.718281828459045
#define K (1.0 / 256.0)
#define K_1 256.0
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 _line;
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];
}
if (str[i] == '^') {
top--;
if (stack[top - 1].i == 0) {
C c;
c.r = cos(log(pow(stack[top - 1].r, stack[top].i))) * pow(stack[top - 1].r, stack[top].r);
c.i = sin(log(pow(stack[top - 1].r, stack[top].i)));
stack[top - 1] = c;
}
else if (stack[top].i == 0) {
#define A(x, y) (sqrt((x) * (x) + (y) * (y)))
C c;
c.r = pow(A(stack[top - 1].i, stack[top - 1].r), stack[top].r) * cos(stack[top].r * asin(stack[top - 1].i / A(stack[top - 1].i, stack[top - 1].r)));
c.i = pow(A(stack[top - 1].i, stack[top - 1].r), stack[top].r) * sin(stack[top].r * asin(stack[top - 1].i / A(stack[top - 1].i, stack[top - 1].r)));
stack[top - 1] = c;
#undef A
}
else {
MessageBox(NULL,L"暂不支持此运算", L"Error", MB_OK);
}
}
}
}
p[len][0] = 512 + int(stack[0].r * K_1 + 0.5);
p[len][1] = 512 - int(stack[0].i * K_1 + 0.5);
if (_line == 0)
putpixel(p[len][0], p[len][1], RGB(0, 255, 255));
len++;
}
int main() {
initgraph(1024, 1024, EX_SHOWCONSOLE);
setlinecolor(RGB(0, 255, 255));
scanf("%d", &_line);
getchar();
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);
}
if (_line == 1)
for (int i = 0; i < len - 1; i++) {
line(p[i][0], p[i][1], p[i + 1][0], p[i + 1][1]);
}
}
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);
}
if (_line == 1)
for (int i = 0; i < len - 1; i++) {
line(p[i][0], p[i][1], p[i + 1][0], p[i + 1][1]);
}
}
saveimage(L"1.jpg");
printf("--------\n");
getchar();
closegraph();
}