你好,复变函数1.0

 

 输入时用后缀,开头空格

#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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值