mandelbrot.mc 894 Bytes
Newer Older
Alexander Hirsch's avatar
Alexander Hirsch committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
float transform_x(float x)
{
	float fx;
	fx = x;
	return (-2.0) + ((1.0) - (-2.0)) * (fx / 80.0);
}

float transform_y(float y)
{
	float fy;
	fy = y;
	return ((1.0) - ((1.0) - (-1.0)) * (fy / 50.0)) * 2.0;
}

15
bool is_in_set(float pX, float pY, int iterations)
Alexander Hirsch's avatar
Alexander Hirsch committed
16
17
18
19
20
21
22
23
24
25
{
	float temp;
	float x;
	float y;
	int i;

	x = 0.0;
	y = 0.0;
	i = 0;

26
	while (((x * x + y * y) <= 4.0) && i < iterations) {
Alexander Hirsch's avatar
Alexander Hirsch committed
27
28
29
30
31
32
		temp = x * x - y * y + pX;
		y = 2.0 * x * y + pY;
		x = temp;
		i = i + 1;
	}

33
	if (i == iterations)
Alexander Hirsch's avatar
Alexander Hirsch committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
		return true;

	return false;
}

int main()
{
	float fx;
	float fy;
	float x;
	float y;

	y = 0.0;

48
49
50
	int iterations;
	iterations = read_int();

Alexander Hirsch's avatar
Alexander Hirsch committed
51
52
53
54
55
56
57
58
	while (y < 50.0) {
		x = 0.0;

		while (x < 80.0) {
			fx = transform_x(x);
			fy = transform_y(y);
			x = x + 1.0;

59
			if (is_in_set(fx, fy, iterations)) {
Alexander Hirsch's avatar
Alexander Hirsch committed
60
61
62
63
64
65
66
67
68
69
70
71
				print(".");
			} else {
				print(" ");
			}
		}

		print_nl();
		y = y + 1.0;
	}

	return 0;
}