Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
58
Task/Mandelbrot-set/C3/mandelbrot-set.c3
Normal file
58
Task/Mandelbrot-set/C3/mandelbrot-set.c3
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
module mandelbrot;
|
||||
|
||||
extern fn int atoi(char *s);
|
||||
extern fn int printf(char *s, ...);
|
||||
extern fn void putchar(int c);
|
||||
|
||||
fn void main(int argc, char **argv)
|
||||
{
|
||||
int w = atoi(argv[1]);
|
||||
int h = w;
|
||||
|
||||
const LIMIT = 2.0;
|
||||
const SQUARE_LIMIT = LIMIT * LIMIT;
|
||||
|
||||
printf("P4\n%d %d\n", w, h);
|
||||
|
||||
int iter = 50;
|
||||
int bit_num = 0;
|
||||
char byte_acc = 0;
|
||||
for (double y = 0; y < h; y++)
|
||||
{
|
||||
for (double x = 0; x < w; x++)
|
||||
{
|
||||
double zr;
|
||||
double zi;
|
||||
double ti;
|
||||
double tr;
|
||||
double cr = (2.0 * x / w - 1.5);
|
||||
double ci = (2.0 * y / h - 1.0);
|
||||
for (int i = 0; i < iter && (tr + ti <= SQUARE_LIMIT); i++)
|
||||
{
|
||||
zi = 2.0 * zr * zi + ci;
|
||||
zr = tr - ti + cr;
|
||||
tr = zr * zr;
|
||||
ti = zi * zi;
|
||||
}
|
||||
|
||||
byte_acc <<= 1;
|
||||
if (tr + ti <= SQUARE_LIMIT) byte_acc |= 0x01;
|
||||
|
||||
++bit_num;
|
||||
|
||||
if (bit_num == 8)
|
||||
{
|
||||
putchar(byte_acc);
|
||||
byte_acc = 0;
|
||||
bit_num = 0;
|
||||
}
|
||||
else if (x == w - 1)
|
||||
{
|
||||
byte_acc <<= (8 - w % 8);
|
||||
putchar(byte_acc);
|
||||
byte_acc = 0;
|
||||
bit_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue