All I needed to do minor changes to asc-version to get gfx-version.lb3361 wrote: ↑12 Sep 2021, 03:03 Now with graphics?
Note: the code above assumes the screen has not been scrolled -- default videoTable.Code: Select all
#include <gigatron/console.h> void drawPixel(int x, int y, int color) { screenMemory[y][x] = color; }
Otherwise you can include <gigatron/console.h> and call console_clear_screen(void) to reset it.
Code: Select all
#include <gigatron/console.h>
#include <gigatron/sys.h>
void drawPixel(int x, int y, int color)
{
screenMemory[y][x] = color;
}
The colors are pseudo colors...color=iteration
Code: Select all
/*----------------------------------------------------------------------+
| |
| gfxbrot.c -- demonstrate fractal in gfx / 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>
#include <gigatron/sys.h>
#define HEIGHT 120
#define WIDTH 160
#define SCALE 1.4
#define YSTEP 1
#define XSTEP 1
int mandelbrot(float x, float y) {
float zz;
float a;
float b;
float a2;
float b2;
float atemp;
int i;
a = 0;
b = 0;
i = 0;
while (i < 63)
{
a2 = a * a;
b2 = b * b;
zz = a2 + b2;
if(zz > 32) break;
atemp = a2 - b2 + x;
b = 2.0 * a * b + y;
a = atemp;
i++;
}
if(x+y < 4) return i;
return 0;
}
void drawPixel(int x, int y, int color)
{
screenMemory[y][x] = color;
}
void main(void) {
int x, y, data;
int offset = 0;
float sx, sy;
for(y = 0; y < HEIGHT; y = y + YSTEP ) {
for(x = 0; x < WIDTH; x = x + XSTEP ) {
sx = -0.7 + SCALE * (WIDTH/2.0 - x) / (WIDTH/2.0);
sy = SCALE * (HEIGHT/2.0 - y) / (HEIGHT/2.0);
data = mandelbrot(sx, sy);
offset = ( x + y * WIDTH);
drawPixel(x,y,data);
}
}
}
Code: Select all
/*----------------------------------------------------------------------+
| |
| gfxjulia.c -- demonstrate fractal in gfx / 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>
#include <gigatron/sys.h>
#define HEIGHT 120
#define WIDTH 160
#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 = 0;
while (i < 63)
{
a2 = a * a;
b2 = b * b;
zz = a2 + b2;
if(zz > 32) break;
atemp = a2 - b2 + CX;
b = 2.0 * a * b + CY;
a = atemp;
i++;
}
if(x+y < 4) return i;
return 0;
}
void drawPixel(int x, int y, int color)
{
screenMemory[y][x] = color;
}
void main(void) {
int x, y, data;
int offset = 0;
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);
sy = SCALE * (HEIGHT/2.0 - y) / (HEIGHT/2.0);
data = julia(sx, sy);
offset = ( x + y * WIDTH);
drawPixel(x,y,data);
}
}
}
Development future is in github / veekooFIN