diff options
author | Juha Vehviläinen <jusu@users.sourceforge.net> | 2002-08-25 18:55:02 +0000 |
---|---|---|
committer | Juha Vehviläinen <jusu@users.sourceforge.net> | 2002-08-25 18:55:02 +0000 |
commit | c4574a9fb0281ff3945ecb7eedf101680a7db6ba (patch) | |
tree | 96f9a662a89ce2580faf85517eb04b22968f4514 /Plugins | |
parent | bc948004f422d2380b936d4fb7e83409597555d9 (diff) |
*** empty log message ***
svn path=/trunk/Framestein/; revision=88
Diffstat (limited to 'Plugins')
-rw-r--r-- | Plugins/gol.c | 84 | ||||
-rw-r--r-- | Plugins/gol.dll | bin | 28672 -> 36864 bytes | |||
-rw-r--r-- | Plugins/gol.exp | bin | 567 -> 567 bytes | |||
-rw-r--r-- | Plugins/gol.lib | bin | 1908 -> 1908 bytes | |||
-rw-r--r-- | Plugins/gol.obj | bin | 1878 -> 1917 bytes | |||
-rw-r--r-- | Plugins/makefile | 6 | ||||
-rw-r--r-- | Plugins/pixels.h | 3 | ||||
-rw-r--r-- | Plugins/rowca.cpp | 107 | ||||
-rw-r--r-- | Plugins/rowca.dll | bin | 0 -> 110592 bytes | |||
-rw-r--r-- | Plugins/rowca.exp | bin | 0 -> 619 bytes | |||
-rw-r--r-- | Plugins/rowca.lib | bin | 0 -> 2042 bytes | |||
-rw-r--r-- | Plugins/rowca.obj | bin | 0 -> 57594 bytes |
12 files changed, 165 insertions, 35 deletions
diff --git a/Plugins/gol.c b/Plugins/gol.c index 89ff284..3349df2 100644 --- a/Plugins/gol.c +++ b/Plugins/gol.c @@ -1,8 +1,9 @@ - // -// Game of Life .. what a waste of time +// Conway's Game of Life .. also take a look at rowca.cpp // +// Currently only works with 16bit displays + #include <stdlib.h> #include <stdio.h> #include "plugin.h" @@ -10,40 +11,59 @@ #define BORN 1 #define DYING 2 -int dead = 0; - int aroundme(_frame f, int x, int y) { + pixel16 *p; 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++; + + p=scanline16(f, y-1); + if(p[x-1]) i++; + if(p[x]) i++; + if(p[x+1]) i++; + + p=scanline16(f, y); + if(p[x-1]) i++; + if(p[x+1]) i++; + + p=scanline16(f, y+1); + if(p[x-1]) i++; + if(p[x]) i++; + if(p[x+1]) i++; + return i; } -void setstate(_frame f, byte *t, int x, int y) +byte *t=0; +long size=0; + +void setstate(_frame f, 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; + 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; + if(f.pixelformat!=16) + { + printf("Sorry, gol works only on a 16bit display.\n"); + return; + } + + if(t && size != f.width*f.height) + { + free(t); + t=0; + } + + if(!t) + t = malloc(size = f.width*f.height); - t = malloc(f.width*f.height); memset(t, 0, f.width*f.height); for(y=2; y<f.height-3; y++) @@ -51,17 +71,17 @@ void perform_effect(struct frame f, struct args a) p = scanline16(f, y); for(x=2; x<f.width-3; x++) { - if(r16(p[x])>0) + if(p[x]) { - 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); + setstate(f, x-1, y-1); + setstate(f, x, y-1); + setstate(f, x+1, y-1); + setstate(f, x-1, y); + setstate(f, x, y); + setstate(f, x+1, y); + setstate(f, x-1, y+1); + setstate(f, x, y+1); + setstate(f, x+1, y+1); } } } @@ -74,16 +94,12 @@ void perform_effect(struct frame f, struct args a) switch(t[y*f.width+x]) { case BORN: - c = p[x]; - r = r16(c); - p[x] = rgbtocolor16(r>0 ? r : 255, g16(c), b16(c)); + p[x] = 5000; break; case DYING: - c = p[+x]; - p[x] = rgbtocolor16(0, g16(c), b16(c)); + p[x] = 0; break; } } } - free(t); } diff --git a/Plugins/gol.dll b/Plugins/gol.dll Binary files differindex dfd2fd6..611f227 100644 --- a/Plugins/gol.dll +++ b/Plugins/gol.dll diff --git a/Plugins/gol.exp b/Plugins/gol.exp Binary files differindex 2dcf523..a92581c 100644 --- a/Plugins/gol.exp +++ b/Plugins/gol.exp diff --git a/Plugins/gol.lib b/Plugins/gol.lib Binary files differindex c38fb4e..545210e 100644 --- a/Plugins/gol.lib +++ b/Plugins/gol.lib diff --git a/Plugins/gol.obj b/Plugins/gol.obj Binary files differindex e571ee0..d15fc1f 100644 --- a/Plugins/gol.obj +++ b/Plugins/gol.obj diff --git a/Plugins/makefile b/Plugins/makefile index 4e92a8a..8a1dd91 100644 --- a/Plugins/makefile +++ b/Plugins/makefile @@ -4,7 +4,8 @@ all: noize colortv subtract xbend bend gol shuffle green \ convolution compare darken deinterlace difference interlace lighten \ multiply overlay screen shadowcaster softlight \ rgbseek modgain traffic constrain eclipse eclipse02 eclipse03 \ - cga keyscreen rene cutout fromage rgbavg rgbavg02 + cga keyscreen rene cutout fromage rgbavg rgbavg02 \ + rowca dir *.dll @@ -181,3 +182,6 @@ rgbavg02: # # </PeRColate> # + +rowca: + cl rowca.cpp $(FLAGS) /GX /link $(EFFECT) diff --git a/Plugins/pixels.h b/Plugins/pixels.h index 4dd1264..9557ea8 100644 --- a/Plugins/pixels.h +++ b/Plugins/pixels.h @@ -54,6 +54,9 @@ public: __inline int eof() { return y==m_f.height ? 1 : 0; } void next(); + + __inline int width() { return m_f.width; } + __inline int height() { return m_f.height; } }; byte pixels::red() diff --git a/Plugins/rowca.cpp b/Plugins/rowca.cpp new file mode 100644 index 0000000..9012b67 --- /dev/null +++ b/Plugins/rowca.cpp @@ -0,0 +1,107 @@ +/* + Two dimensional cellular automata, where each iteration + adds a new row. + + Patterns that lead to a white cell are given as parameter, + forming the rule of the automata. + + Example: parameter "001-010-011-100" + + Starting from a singe cell, this would lead to: + + O + OOO + OO O + OO OOOO + OO O O + OO OOOO OOO + OO O O O + + etc. +*/ + +#include <iostream> +#include <string> +#include <vector> + +#include "plugin.h" +#include "pixels.h" + +using namespace std; + +vector<string> sv; + +void iterate(const char *arg); +void draw(const _frame &f); + +void perform_effect(_frame f, _args a) +{ + if(!a.s || !a.s[0]) return; + + if(strstr(a.s, "0") || strstr(a.s, "1")) iterate(a.s); else + if(strcmp(a.s, "draw")==0) draw(f); else + if(strcmp(a.s, "clear")==0) sv.clear(); +} + +void iterate(const char *arg) +{ + if(sv.empty()) + { + sv.push_back("00100"); // start with a single cell + } + + string s("00"), last=sv.back(), rule(arg); + int i; + + for(i=0; i<=last.size()-3; i++) + { + if( rule.find(last.substr(i, 3)) != rule.npos ) + s.append("1"); + else + s.append("0"); + } + + s.append("00"); + + sv.push_back(s); +} + +void draw(const _frame &f) +{ + if(sv.empty()) return; + + int x1=0, y1=0, x2=sv.back().size(), y2=sv.size(); + int i; + + pixels p(f); + int prevy=-1; + + float sourcex, sourcey; + string s; + + while(!p.eof()) + { + if(p.y != prevy) + { + sourcey = p.y / (float)p.height(); + s = sv[sourcey * y2]; + + // make s the size of x2 + i = (x2-s.size()) / 2; + s.insert(1, i, '0'); + s.append(i, '0'); + + prevy = p.y; + } + + sourcex = p.x / (float)p.width(); + + if( !s.compare(sourcex * x2, 1, "1") ) + p.putrgb(255, 255, 255); + else + p.putrgb(0, 0, 0); + + p.next(); + } + cout << "rows: " << y2 << " size of last row: " << x2 << endl; +} diff --git a/Plugins/rowca.dll b/Plugins/rowca.dll Binary files differnew file mode 100644 index 0000000..b3bdc17 --- /dev/null +++ b/Plugins/rowca.dll diff --git a/Plugins/rowca.exp b/Plugins/rowca.exp Binary files differnew file mode 100644 index 0000000..13b0af4 --- /dev/null +++ b/Plugins/rowca.exp diff --git a/Plugins/rowca.lib b/Plugins/rowca.lib Binary files differnew file mode 100644 index 0000000..f46b62c --- /dev/null +++ b/Plugins/rowca.lib diff --git a/Plugins/rowca.obj b/Plugins/rowca.obj Binary files differnew file mode 100644 index 0000000..cfc3f02 --- /dev/null +++ b/Plugins/rowca.obj |