Plan 9 from Bell Labs’s /usr/web/sources/contrib/aiju/cell.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <draw.h>

enum {N = 100};
int A[N*N], B[N*N], *prev = A, *cur = B, mouse, tpx, tpy;

void
main()
{
	initdraw(0, 0, 0);
	tpx = screen->r.min.x;
	tpy = screen->r.min.y;
	memset(A, 0, sizeof A);
	mouse = open("/dev/mouse", OREAD);
	if(mouse == -1) sysfatal("open /dev/mouse: %r");
	while(1) {
		int i, *tmp;
		memcpy(cur, prev, sizeof A);
		for(i=0;i<N*N;i++) {
			if(prev[i] > 3) {
				cur[i] -= 3;
				if(i >= N) cur[i-N]++;
				if(i > 0) cur[i-1]++;
				if(i <= N*N-N) cur[i+N]++;
				if(i < N*N) cur[i+1]++;
			}
		}
		for(i=0;i<N*N;i++) {
			int x, y;
			x = i % N;
			y = i / N;
			draw(screen, Rect(tpx+x,tpy+y,tpx+x+1,tpy+y+1), screen->display->black, 0, ZP);
		}
		tmp = cur;
		cur = prev;
		prev = tmp;
		sleep(100);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].