From 4d64e4cd434426234a5c313c151cd79b6afc299e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juha=20Vehvil=C3=A4inen?= Date: Sat, 6 Jul 2002 17:50:18 +0000 Subject: *** empty log message *** svn path=/trunk/Framestein/; revision=27 --- Plugins/gol.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 Plugins/gol.c (limited to 'Plugins/gol.c') diff --git a/Plugins/gol.c b/Plugins/gol.c new file mode 100644 index 0000000..89ff284 --- /dev/null +++ b/Plugins/gol.c @@ -0,0 +1,89 @@ + +// +// Game of Life .. what a waste of time +// + +#include +#include +#include "plugin.h" + +#define BORN 1 +#define DYING 2 + +int dead = 0; + +int aroundme(_frame f, int x, int y) +{ + int i=0; + if(r16(scanline16(f, y-1)[x-1])>dead) i++; + if(r16(scanline16(f, y-1)[x])>dead) i++; + if(r16(scanline16(f, y-1)[x+1])>dead) i++; + if(r16(scanline16(f, y)[x-1])>dead) i++; + if(r16(scanline16(f, y)[x+1])>dead) i++; + if(r16(scanline16(f, y+1)[x-1])>dead) i++; + if(r16(scanline16(f, y+1)[x])>dead) i++; + if(r16(scanline16(f, y+1)[x+1])>dead) i++; + return i; +} + +void setstate(_frame f, byte *t, int x, int y) +{ + int i = aroundme(f, x, y); + + if(i<=1 || i>=4) t[y*f.width+x]=DYING; + else + if(i==3) t[y*f.width+x]=BORN; +} + +void perform_effect(struct frame f, struct args a) +{ + int x,y,i,r; + pixel16 *p, c; + byte *t; + + if(f.pixelformat!=16) return; + + t = malloc(f.width*f.height); + memset(t, 0, f.width*f.height); + + for(y=2; y0) + { + setstate(f, t, x-1, y-1); + setstate(f, t, x, y-1); + setstate(f, t, x+1, y-1); + setstate(f, t, x-1, y); + setstate(f, t, x, y); + setstate(f, t, x+1, y); + setstate(f, t, x-1, y+1); + setstate(f, t, x, y+1); + setstate(f, t, x+1, y+1); + } + } + } + + for(y=2; y0 ? r : 255, g16(c), b16(c)); + break; + case DYING: + c = p[+x]; + p[x] = rgbtocolor16(0, g16(c), b16(c)); + break; + } + } + } + free(t); +} -- cgit v1.2.1