gigatron/rom/Compilers/glcc/stuff/veekoo/ascjulia.c
2025-01-28 19:17:01 +03:00

68 lines
1.4 KiB
C

/*----------------------------------------------------------------------+
| |
| ascjulia.c -- demonstrate fractal in text / quick and dirty |
| |
+----------------------------------------------------------------------*/
// Standard includes
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include <gigatron/console.h>
#define HEIGHT 15
#define WIDTH 26
#define SCALE 1.7
#define YSTEP 1
#define XSTEP 1
#define CX -0.8
#define CY 0.156
int julia(float x, float y) {
float zz;
float a;
float b;
float a2;
float b2;
float atemp;
int i;
a = x;
b = y;
i = 48;
while (i < 58)
{
a2 = a * a;
b2 = b * b;
zz = a2 + b2;
if(zz > 4) break;
atemp = a2 - b2 + CX;
b = 2.0 * a * b + CY;
a = atemp;
i++;
}
return i;
}
void main(void) {
int x, y, data;
float sx, sy;
for(y = 0; y < HEIGHT; y = y + YSTEP ) {
for(x = 0; x < WIDTH; x = x + XSTEP ) {
sx = (SCALE * (WIDTH/2.0 - x) / (WIDTH/2.0))*(-1);
sy = (SCALE * (HEIGHT/2.0 - y) / (HEIGHT/2.0))*(-0.75);
data = julia(sx, sy);
console_state.cx = x;
console_state.cy = y;
console_state.fgbg = (((data-48)*6+1) & 0x3f) << 8;
console_print((char*)&data, 1);
}
}
}