mandelbrot.c (697B)
1 // Copyright 2022, Brian Swetland <swetland@frotz.net> 2 // Licensed under the Apache License, Version 2.0 3 4 #include <hw/debug.h> 5 6 void start(void) { 7 int top = 1000, bottom = -1000, ystep = 50; 8 int left = -2500, right = 1000, xstep = 30; 9 int maxiter = 1000; 10 11 for (int y0 = top; y0 > bottom; y0 -= ystep) { 12 for (int x0 = left; x0 < right; x0 += xstep) { 13 int i = 0, x = 0, y = 0, ch = ' '; 14 while (i < maxiter) { 15 int x2 = x * x / 1000; 16 int y2 = y * y / 1000; 17 if ((x2 + y2) > 4000) { 18 ch = (i > 9) ? '@' : (i + '0'); 19 break; 20 } 21 y = 2 * x * y / 1000 + y0; 22 x = x2 - y2 + x0; 23 i++; 24 } 25 xputc(ch); 26 } 27 xputc('\n'); 28 } 29 30 xprintf("Hello, Mandlebrot!\n"); 31 }