--- /dev/null
+/*
+ * scientific visualization api for direct framebuffer
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include "dfbapi.h"
+
+/* two dimensional lattice */
+
+int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l,int x,int y)
+{
+ DFBSurfaceDescription surface_dsc;
+ DFBFontDescription font_dsc;
+
+ d2_l->max_x=x;
+ d2_l->max_y=y;
+
+ DirectFBInit(argc,&argv);
+ DirectFBCreate(&(d2_l->dfb));
+ d2_l->dfb->SetCooperativeLevel(d2_l->dfb,DFSCL_FULLSCREEN);
+
+ surface_dsc.flags=DSDESC_CAPS;
+ surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
+ d2_l->dfb->CreateSurface(d2_l->dfb,&surface_dsc,&(d2_l->p_surface));
+ d2_l->p_surface->GetSize(d2_l->p_surface,&(d2_l->s_width),&(d2_l->s_height));
+
+ font_dsc.flags=DFDESC_HEIGHT;
+ font_dsc.height=d2_l->max_y*((d2_l->s_height)/(d2_l->max_y))/20; /* 20 ? */
+ d2_l->dfb->CreateFont(d2_l->dfb,FONT,&font_dsc,&(d2_l->font));
+ d2_l->p_surface->SetFont(d2_l->p_surface,d2_l->font);
+
+ d2_l->fakt_y=(d2_l->s_height)/(d2_l->max_y+(2*Y_GAP));
+ d2_l->fakt_x=(d2_l->s_height)/(d2_l->max_x+X_GAP); /* bullshit, i can't imagine atm */
+ d2_l->info_x=d2_l->fakt_x*d2_l->max_x+2*X_GAP;
+ d2_l->info_y=Y_GAP;
+ d2_l->info_w=d2_l->s_width-d2_l->info_x-2*X_GAP;
+ d2_l->info_h=d2_l->max_y*d2_l->fakt_y;
+
+ if((d2_l->s_height<(d2_l->max_y+2*Y_GAP)) || (d2_l->s_height<(d2_l->max_x+X_GAP)))
+ {
+ puts("resolution too low!");
+ return -1;
+ } else return 1;
+}
+
+int d2_lattice_release(d2_lattice *d2_l)
+{
+ d2_l->font->Release(d2_l->font);
+ d2_l->p_surface->Release(d2_l->p_surface);
+ d2_l->dfb->Release(d2_l->dfb);
+
+ return 1;
+}
+
+int d2_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b)
+{
+ if((*status)&RED)
+ {
+ *r=0xff;
+ *g=0;
+ *b=0;
+ } else
+ {
+ *r=0;
+ *g=0;
+ *b=0xff;
+ }
+
+ return 1;
+}
+
+int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v)
+{
+ int x_c,y_c;
+ int i;
+ unsigned char r,g,b,a;
+
+ a=0xff; /* no alpha blending */
+
+ for(x_c=0;x_c<d2_l->max_x;x_c++)
+ {
+ for(y_c=0;y_c<d2_l->max_y;y_c++)
+ {
+ d2_lattice_get_color((*d2_l).status+x_c+y_c*d2_l->max_x,&r,&g,&b);
+ if(x_c==x && y_c==y)
+ {
+ r=0xff;
+ g=0xff;
+ b=0;
+ }
+ d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
+ d2_l->p_surface->DrawRectangle(d2_l->p_surface,
+ x_c*d2_l->fakt_x+X_GAP,
+ y_c*d2_l->fakt_y+Y_GAP,
+ d2_l->fakt_x,d2_l->fakt_y);
+ }
+ }
+ r=0xff;
+ g=0xff;
+ b=0;
+ /* clear info box */
+ d2_l->p_surface->SetColor(d2_l->p_surface,0,0,0,0);
+ d2_l->p_surface->FillRectangle(d2_l->p_surface,
+ d2_l->info_x,d2_l->info_y,
+ d2_l->info_w,d2_l->info_h);
+ d2_l->p_surface->SetColor(d2_l->p_surface,r,g,b,a);
+ d2_l->p_surface->DrawRectangle(d2_l->p_surface,
+ d2_l->info_x,d2_l->info_y,
+ d2_l->info_w,d2_l->info_h);
+ d2_l->p_surface->SetColor(d2_l->p_surface,0x80,0x80,0xff,0xff);
+ for(i=1;i<=arg_c;i++)
+ {
+ d2_l->p_surface->DrawString(d2_l->p_surface,arg_v[1],-1,
+ d2_l->info_x+d2_l->fakt_x,
+ d2_l->info_y+d2_l->fakt_x+(i-1)*d2_l->fakt_x,
+ DSTF_LEFT);
+ }
+ /* now we flip all to surface */
+ d2_l->p_surface->Flip(d2_l->p_surface,NULL,0);
+
+ return 1;
+}
+
--- /dev/null
+/*
+ * scientific visualization api for direct framebuffer
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <directfb.h>
+
+/* two dimensional lattice */
+
+#define X_GAP 5
+#define Y_GAP X_GAP
+#define RED 1
+
+typedef struct __d2_lattice
+{
+ int max_x,max_y;
+ int s_height,s_width;
+ int fakt_x,fakt_y;
+ int info_x,info_y;
+ int info_w,info_h;
+ unsigned char *status; /* status&1 -> red, else blue */
+ IDirectFB *dfb;
+ IDirectFBSurface *p_surface;
+ IDirectFBFont *font;
+ IDirectFBInputDevice *keyboard;
+ IDirectFBEventBuffer *k_buffer;
+} d2_lattice;
+
+/* function prototypes */
+int d2_lattice_init(int *argc,char **argv,d2_lattice *d2_l,int x,int y);
+int d2_lattice_release(d2_lattice *d2_l);
+int d2_lattice_get_color(unsigned char *status,unsigned char *r,unsigned char *g,unsigned char *b);
+int d2_lattice_draw(d2_lattice *d2_l,int x,int y,int arg_c,char **arg_v);
+
--- /dev/null
+/*
+ * ising.c - visualization of ising spins in an N x N lattice
+ *
+ * ... actually N x M
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "dfbapi.h"
+
+#define X 50
+#define Y 50
+#define MAX_T 200
+
+int main(int argc, char **argv)
+{
+ unsigned char *atom;
+ int max_x,x_c,max_y,y_c;
+ int i,j;
+ unsigned int T;
+ double M;
+ double beta;
+ double delta_e;
+
+ /* display stuff */
+ d2_lattice d2_l;
+
+ /* we will parse argv later ... */
+ max_x=X;
+ max_y=Y;
+
+ d2_lattice_init(&argc,argv,&d2_l,max_x,max_y);
+
+ atom=(unsigned char *)(malloc(max_x*max_y*sizeof(unsigned char)));
+
+ d2_l.status=atom;
+
+ /* begin at T=0 M=1 situation */
+ memset(atom,0,max_x*max_y*sizeof(unsigned char));
+
+ for(T=1;T<MAX_T;T++)
+ {
+ beta=1.0/T; /* k_B = 1 */
+ /* do N*N itterations, we will need more */
+ for(i=0;i<max_x*max_y;i++)
+ {
+
+ for(x_c=0;x_c<max_x-1;x_c++)
+ {
+ for(y_c=0;y_c<max_y-1;y_c++)
+ {
+ delta_e=0;
+ // delta_e+=(-1*(int)(atom
+ }
+
+ }
+
+ }
+ d2_lattice_draw(&d2_l,0,0,0,NULL);
+ }
+
+ getchar();
+
+ return 1;
+}