Skip to content

Commit 40d91b0

Browse files
committed
Colorize Mandelbrot set rendering
1 parent db591d2 commit 40d91b0

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

build/mandelbrot.elf

100644100755
64.7 KB
Binary file not shown.

tests/mandelbrot.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ short toPrec(double f, int bitsPrecision)
2626
}
2727
#endif
2828

29-
static const int width = 64; /* basic width of a zx81 */
30-
static const int height = 32; /* basic width of a zx81 */
29+
static const int width = 64; /* basic width */
30+
static const int height = 32; /* basic width */
3131
static const int zoom = 1; /* leave at 1 for 32x22 */
3232

3333
int main(int argc, char *argv[])
@@ -41,17 +41,17 @@ int main(int argc, char *argv[])
4141
const short LIMIT = 0x100; /* toPrec(4, bitsPrecision) */
4242

4343
/* fractal */
44-
char charset[] = ".:-=X$#@.";
45-
short max_iter = sizeof(charset) - 1;
44+
char charset[] = ".:-=X$#@ ";
45+
const short max_iter = sizeof(charset) - 1;
4646

4747
for (short py = 0; py < height * zoom; py++) {
4848
for (short px = 0; px < width * zoom; px++) {
4949
short x0 = ((px * X1) / width) - X2;
5050
short y0 = ((py * Y1) / height) - Y2;
5151
short x = 0, y = 0;
5252

53-
short i = 0;
54-
while (i < max_iter) {
53+
short i;
54+
for (i = 0; i < max_iter; i++) {
5555
short xSqr = (x * x) >> bitsPrecision;
5656
short ySqr = (y * y) >> bitsPrecision;
5757

@@ -63,16 +63,14 @@ int main(int argc, char *argv[])
6363
* and we see nothing. By including the overflow break out we
6464
* can see the fractal again though with noise.
6565
*/
66-
if ((xSqr + ySqr) >= LIMIT || (xSqr + ySqr) < 0)
66+
if ((xSqr + ySqr) >= LIMIT)
6767
break;
6868

6969
short xt = xSqr - ySqr + x0;
7070
y = (((x * y) >> bitsPrecision) * 2) + y0;
7171
x = xt;
72-
73-
i++;
7472
}
75-
printf("%c", charset[--i]);
73+
printf("\033[48;05;%dm%c\033[0m", i, charset[i - 1]);
7674
}
7775

7876
printf("\n");

0 commit comments

Comments
 (0)