Add fractal tree sample

This commit is contained in:
drmortalwombat 2022-09-12 22:30:26 +02:00
parent 8c19b1f148
commit 76f463daff
6 changed files with 75 additions and 0 deletions

View File

@ -586,6 +586,12 @@ The C64 has a hires graphics mode with 320x200 pixels. Oscar provides a library
Draws and clears lines with various patterns. Draws and clears lines with various patterns.
#### Draw lines "fractaltree.c"
Draws a recursive fractal tree.
![Fractal recursive tree](samples/hires/fractaltree.png)
#### Draw 3D wireframe "cube3d.c" #### Draw 3D wireframe "cube3d.c"
Draws a rotating 3D wireframe cube using draw (OR) and clear (AND) operations. The 3D operations are performed using 12.4 bit fixpoint math. Draws a rotating 3D wireframe cube using draw (OR) and clear (AND) operations. The 3D operations are performed using 12.4 bit fixpoint math.

View File

@ -0,0 +1,64 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <math.h>
#include <string.h>
#include <conio.h>
char * const Color = (char *)0xd000;
char * const Hires = (char *)0xe000;
Bitmap Screen;
ClipRect Clip = {0, 0, 320, 200};
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x01, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
void draw(float x, float y, float a, float s)
{
if (s < 6.0)
return;
float tx = x + cos(a) * s;
float ty = y + sin(a) * s;
bm_line(&Screen, &Clip, x, y, tx, ty, 0xff, LINOP_SET);
draw(tx, ty, a + 0.3, s * 0.9);
draw(tx, ty, a - 0.4, s * 0.8);
}
int main(void)
{
init();
draw(140, 199, PI * 1.5, 32);
done();
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -8,6 +8,8 @@
#include <gfx/bitmap.h> #include <gfx/bitmap.h>
#include <stdio.h> #include <stdio.h>
#pragma stacksize(1024)
#pragma region(main, 0x0a00, 0xc800, , , {code, data, bss, heap, stack} ) #pragma region(main, 0x0a00, 0xc800, , , {code, data, bss, heap, stack} )

View File

@ -4,3 +4,4 @@ call ..\..\bin\oscar64 lines.c -n
call ..\..\bin\oscar64 polygon.c -n call ..\..\bin\oscar64 polygon.c -n
call ..\..\bin\oscar64 bitblit.c -n call ..\..\bin\oscar64 bitblit.c -n
call ..\..\bin\oscar64 cube3d.c -n call ..\..\bin\oscar64 cube3d.c -n
call ..\..\bin\oscar64 fractaltree.c -n

View File

@ -4,6 +4,8 @@
// make space until 0x1000 by for the stack // make space until 0x1000 by for the stack
#pragma stacksize(0x0600)
#pragma region( stack, 0x0a00, 0x1000, , , {stack} ) #pragma region( stack, 0x0a00, 0x1000, , , {stack} )
// everything beyond will be code, data, bss and heap to the end // everything beyond will be code, data, bss and heap to the end