Linux folks,

Here's my small GUI program. It uses the framebuffer device to produce
a graph of the iteration time (ie. lower is better). It assumes a couple
of things:

1. You already have framebuffer set up.
2. You're running mprime v19.
3. You know what you're doing. (Don't come running to me if you need help
   compiling, setting up your framebuffer device etc.)
4. Your fb device is using 32 bpp (NOT 24, 16, or 8 bpp...)
5. You like weird colours.

Run (after compilation):

./mprime -d | itermeter

Every time mprime would normally output a line, a flashy bar comes up.
If your X resolution is the same as your fb resolution (and if you run
32 bpp in X), try switching to X for a bit of a weird effect :-)

Don't expect this to ever be ready for a general release. It's just a
piece of crap that I smacked together in 10-15 minutes. (Hope nobody
minds about my 3K-attachment -- the file wasn't that big, so I didn't
bother to FTP upload it etc.)

/* Steinar */
-- 
Homepage: http://members.xoom.com/sneeze/
/*
 * made by Sesse 24.9.99 
 * no copyrights as of current -- have fun
 */
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

/* w/h = actual width/height */
/* fw = virtual width */ 
/* fbdev = framebuffer device */

#define w 800
#define fw 1024
#define h 600 
#define fbdev "/dev/fb0"

void main(void)
{
        int fd = open(fbdev, O_RDWR);
        int i = 16;
        char *buf = mmap(NULL, fw*h*4, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
        float max = 1.0f;

        memset(buf, 0, fw*h*4); 

        while (!(feof(stdin))) {
                int ijunk;
                float fjunk, iter_time;

                int y, x, p;
                float barheight;

                scanf("Iteration: %d / %d [%f%%].  Per iteration time: %f sec. (%d 
clocks)",
                        &ijunk, &ijunk, &fjunk, &iter_time, &ijunk);
                do {} while (getchar() != '\n');

                if (iter_time > max) iter_time = max; 

                barheight = (float)iter_time/(float)(max)*(float)(h-32);
                p = 0;

                for (y = h-16; y > h-16-barheight; y--) {
                        int rcomp = 0, gcomp = 0, bcomp = 0;
                        float val = (float)(++p) / barheight;

                        /* 0/4: 100% red */
                        /* 1/4: 50/50 red/green */
                        /* 2/4: 100% green */
                        /* 3/4: 50/50 green/blue */
                        /* 4/4: 100% blue */
                        if (val < 0.5f) {
                                rcomp = 255 - (val * 512.0f);
                        }
                        if ((val > 0.25f) && (val < 0.5f)) {
                                gcomp = (val - 0.25f) * 1024.0f;
                        }
                        if ((val > 0.5f) && (val < 0.75f)) {
                                gcomp = 255 - ((val - 0.5f) * 1024.0f);
                        }
                        if (val > 0.5f) {
                                bcomp = (val - 0.5f) * 512.0f;
                        }
                        
                        buf[4*fw*y + 4*i] = buf[4*fw*y + 4*i + 1] = buf[4*fw*y + 4*i + 
2] =
                        buf[4*fw*y + 4*(i+16)] = buf[4*fw*y + 4*(i+16) + 1] = 
buf[4*fw*y + 4*(i+16) + 2] =
                                0xff;
 
                        buf[4*fw*y + 3] = buf[4*fw*y + 4*(i+16) + 3] = 0;

                        for (x = i+1; x < i+16; x++) {
                                buf[4*fw*y + 4*x    ] = bcomp;
                                buf[4*fw*y + 4*x + 1] = gcomp;
                                buf[4*fw*y + 4*x + 2] = rcomp;
                                buf[4*fw*y + 4*x + 3] = 0;
                        }
                }
                /* draw vertical top line */
                memset(buf + 4*fw*(h-16-(int)barheight) + 4*i, 0xff, 64);

                i %= w-34; 
                i += 16;
        }
        
        close(fd);
}

Reply via email to