Mandlebrot set zoomer...

Text mode nostalgia.

What should I do with it next?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#define LOOPS 1000
#define ESC 27
#define XSIZE 128
#define YSIZE 40
#define DELAY 1000
#define LOWCOLOR 1
#define HIGHCOLOR 6
#define LOWASCII 33
#define HIGHASCII 127
#define XFRACENTER -1.5
#define YFRACENTER 0
#define XFRACSIZE 3.2
#define YFRACSIZE 2.4
#define ZOOMER 0.98
#define SNOWFLAKEFACTOR 32

#include <stdio.h>
#include <stdlib.h>
int mandel (long double x,long double y);

int main (void){
	int loopcount=0;
	int x=0, y=0, xcount=0, ycount=0, delay=0;
	int color=0, oldcolor=0, temp=0;
	int ascii=32; //space
	long double xc=0,yc=0;
	long double xzoom=XFRACSIZE, yzoom=YFRACSIZE; //because this will be changing later

	for (loopcount=0; loopcount<LOOPS; loopcount++) {
		printf ("%c[0;0H",ESC); // vt100 for send cursor to 1,1 position
		for (ycount=0; ycount<YSIZE; ycount++) {
			for (xcount=0; xcount<XSIZE; xcount++) {

				xc=xcount; yc=ycount; //precast
				xc=(xc/XSIZE*2-1)*xzoom+XFRACENTER;
				yc=(yc/YSIZE*2-1)*yzoom+YFRACENTER;

				oldcolor=color;
				color=mandel(xc,yc);
				if (color!=DELAY) {
					temp=color/(HIGHCOLOR-LOWCOLOR+1);
					temp=temp*(HIGHCOLOR-LOWCOLOR+1);
					color=color-temp+LOWCOLOR;
				} else {
					color=0; // black for in-set
				}

//compress output text a bit...
				if (oldcolor!=color){
//					printf ("%c[3%im",ESC,color); //foreground
					printf ("%c[4%im",ESC,color); //background
				}

//				ascii=xcount+ycount+loopcount;
//				temp=ascii/(HIGHASCII-LOWASCII+1);
//				temp=temp*(HIGHASCII-LOWASCII+1);
//				ascii=ascii-temp+LOWASCII;
				printf ("%c",ascii);

			}
			printf ("%c[40;37m",ESC); //bring back white on black color before linefeed to avoid glitch
			printf ("\n");
			color=0; //to prevent start-of-line glitch in output compression 
		}
		xzoom=xzoom*ZOOMER; 
		yzoom=yzoom*ZOOMER;
	}
}


int mandel (long double xc,long double yc) {
	int count=0;
	long double numreal=xc, numimag=yc, temp=0;
//Proper method:
	for (count=0; (numreal*numreal+numimag*numimag)<4 && count <DELAY ; count++) {
//Faster method. In-set results are the same for SFF of 4 or more. Out-of-set results differ!
//	for (count=0; (abs(numimag)+abs(numreal))<SNOWFLAKEFACTOR && count <DELAY ; count++) {
		//square the complex number
		temp=numimag;
		numimag=numreal*numimag*2; 
		numreal=numreal*numreal-temp*temp;
		//add the original back to it
		numreal=numreal+xc;
		numimag=numimag+yc;
	}
	return count;
}
Topic archived. No new replies allowed.