From a28d730d92a955110e132b15cac51dc045c4f2cd Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 8 May 2003 20:09:58 +0000 Subject: [PATCH] initial checkin of ising (included dfbapi) --- Makefile | 19 +++++++++ README | 17 ++++++++ dfbapi.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ dfbapi.h | 36 ++++++++++++++++ ising.c | 70 +++++++++++++++++++++++++++++++ 5 files changed, 268 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 dfbapi.c create mode 100644 dfbapi.h create mode 100644 ising.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5419453 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +# ising Makefile + +INCLUDEDIR = /usr/include +CFLAGS = -DDEBUG -DUSE_DFB_API -DFONT=\"./decker.ttf\" -O3 -Wall -I/usr/include/directfb +LIBS = -L/usr/lib -ldirectfb + +OBJS = dfbapi.o +OBJS2 = ising + +ising: $(OBJS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) ising.c + +all: ising + +clean: + rm $(OBJS) $(OBJS2) + +remake: clean all + diff --git a/README b/README new file mode 100644 index 0000000..51f4084 --- /dev/null +++ b/README @@ -0,0 +1,17 @@ +ising +----- + +- you need directfb installed to get this compiled/working. + (www.directfb.org <- they definetly kick asses!) + +- adjust the Makefile if include pathes are different. + +- get decker.ttf from somewhere. + (if you dont find it get t from DFBSee or my other dfb apps) + +- type: make + +- run it: ./ising -h + +- you may use gnuplot to watch the M-T graph + ( use -o foobar ) diff --git a/dfbapi.c b/dfbapi.c new file mode 100644 index 0000000..9a8519b --- /dev/null +++ b/dfbapi.c @@ -0,0 +1,126 @@ +/* + * scientific visualization api for direct framebuffer + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include +#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_cmax_x;x_c++) + { + for(y_c=0;y_cmax_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; +} + diff --git a/dfbapi.h b/dfbapi.h new file mode 100644 index 0000000..2403d80 --- /dev/null +++ b/dfbapi.h @@ -0,0 +1,36 @@ +/* + * scientific visualization api for direct framebuffer + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include + +/* 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); + diff --git a/ising.c b/ising.c new file mode 100644 index 0000000..cb89d8a --- /dev/null +++ b/ising.c @@ -0,0 +1,70 @@ +/* + * ising.c - visualization of ising spins in an N x N lattice + * + * ... actually N x M + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include +#include +#include +#include +#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