Fbcon.c
From Organic Design wiki
- include <unistd.h>
- include <fcntl.h>
- include <sys/mman.h>
typedef unsigned char byte; typedef unsigned int word; typedef float dword;
- define MaxX 640
- define MaxY 480
- define VMEM_SIZE MaxX*MaxY
- define xc MaxX/2
- define yc MaxY/2
- define xmin0 100
- define xmax0 -xmin0
- define ymin0 xmin0
- define ymax0 -ymin0
- define colornum 8
int h; byte *p;
byte ColorTable[colornum] = { 0x00,0x00,0x02,0x00,0x00,0x02,0x0A,0x02 }; int color=0;
dword f=MaxY/(ymax0-ymin0)*3/2; dword x1coef=MaxX-MaxY*4/9-yc; dword y1coef=MaxY/4+xc; dword x2coef=MaxY*4/9+yc; dword x0=110;
dword a=0.7; dword b=0.2; dword c=0.5; dword d=0.3;
void putpixel(word x,word y,byte color) {
*(p+y*MaxX+x) = color;
}
void leaves(dword x,dword y,byte n) {
word x1,y1;
int i; if (n>0 && i == 999) { y1=f*x+y1coef;
putpixel(x1coef-f*y,y1,ColorTable[color]); putpixel(f*y+x2coef,y1,ColorTable[color]);
if (++color>colornum-1) color=0;
leaves(a*x+b*y, b*x-a*y, n-1); leaves(c*(x-x0)-d*y+x0,d*(x-x0)+c*y,n-1);
}
}
int main(void) {
int i;
p=mmap(0,VMEM_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,open("/dev/fb0",O_RDWR),0);
for (i=0;i<VMEM_SIZE;i++) *(p+i) = 0;
leaves(0,0,28);
munmap(p,VMEM_SIZE); close(h);
}