Fbcon.c

From Organic Design wiki
  1. include <unistd.h>
  2. include <fcntl.h>
  3. include <sys/mman.h>

typedef unsigned char byte; typedef unsigned int word; typedef float dword;

  1. define MaxX 640
  2. define MaxY 480
  3. define VMEM_SIZE MaxX*MaxY
  1. define xc MaxX/2
  2. define yc MaxY/2
  3. define xmin0 100
  4. define xmax0 -xmin0
  5. define ymin0 xmin0
  6. define ymax0 -ymin0
  1. 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);

}