Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html><body onload="k=40;g=10;b=[];setInterval(function(){c=[];for(y=k*k;y--;){n=0;for(f=9;f--;)n+=b[(~~(y/k)+k+f%3-1)%k*k+(y+k+~~(f/3)-1)%k];c[y]=n==3||n-b[y]==3;r.fillStyle=b[y]?'red':'tan';r.fillRect(y%k*g,~~(y/k)*g,g-1,g-1)}if(v.nextSibling.checked)b=c},1);v=document.body.firstChild;v.width=v.height=g*k;v.addEventListener('click',function(e){b[~~((e.pageY-v.offsetTop)/g)*k+~~((e.pageX-v.offsetLeft)/g)]^=1},0);r=v.getContext('2d');for(y=k*k;y--;)b[y]=0"><canvas></canvas><input type="checkbox"/>Run</body></html>
- import time
- P=input()
- N=range(20)
- while 1:
- for i in N:print''.join(' *'[i*20+j in P]for j in N)
- time.sleep(.1);Q=[(p+d)%400 for d in(-21,-20,-19,-1,1,19,20,21)for p in P];P=set(p for p in Q if 2-(p in P)<Q.count(p)<4)
- echo "[8,29,47,48,49]" | ./life.py
- Manipulate[x=Switch[run,1,x,2,CellularAutomaton[{224,{2,{{2,2,2},{2,1,2},{2,2,2}}},
- {1,1}},x],3,Table[0,{k,40},{j,40}]];EventHandler[Dynamic[tds=Reverse[Transpose[x]];
- ArrayPlot[tds,Mesh->True]],{"MouseClicked":>(pos=Ceiling[MousePosition["Graphics"]];
- x=ReplacePart[x,pos->1-x[[Sequence@@pos]]];)}],{{run,3,""},{1->"||",2->">",3->"X"}}]
- ListAnimate@NestList[ImageFilter[If[3<=Total@Flatten@#<=3+#[[2]][[2]],1,0]&,#,1]&,Image[Round/@RandomReal[1,{200,200}]],99]
- #include <windows.h>
- #include<process.h>
- #define K ][(x+80)%20+(y+80)%20*20]
- #define H R.Event.MouseEvent.dwMousePosition
- #define J R.Event.MouseEvent.dwButtonState
- HANDLE Q,W;char*E[3],O;Y(x,y){return E[0 K;}U(x,y,l,v){E[l K=v;}I(){E[2]=E[1];E[1]=*E;*E=E[2];memset(E[1],0,400);}A(i,j,k,l,P){while(1){Sleep(16);for(i=0;i<20;++i)for(j=0;j<20;++j){COORD a={i,j};SetConsoleCursorPosition(Q,a);putchar(E[0][i+j*20]==1?'0':' ');}if(O){for(i=0;i<20;++i)for(j=0;j<20;++j){for(k=i-1,P=0;k<i+2;++k)for(l=j-1;l<j+2;++l){P+=Y(k,l);}U(i,j,1,P==3?1:Y(i,j)==1&&P==4?1:0);}I();}}}main(T,x,y,F,D){for(x=0;x<21;++x)puts("#####################");E[0]=malloc(800);E[1]=E[0]+400;I();I();W=GetStdHandle(-10);Q=GetStdHandle(-11);SetConsoleMode(W,24);INPUT_RECORD R;F=D=O=0;COORD size={80,25};SetConsoleScreenBufferSize(Q,size);_beginthread(A,99,0);while(1){ReadConsoleInput(W,&R,1,&T);switch(R.EventType){case 1:O=R.Event.KeyEvent.dwControlKeyState&128;break;case 2:switch(R.Event.MouseEvent.dwEventFlags){case 1:x=H.X;y=H.Y;case 0:F=J&1;D=J&2;}if(F)U(x,y,0,1);if(D)U(x,y,0,0);}}}
- import swing._
- import event._
- object L extends SimpleSwingApplication{import java.awt.event._
- import javax.swing._
- var(w,h,c,d,r)=(20,20,20,0,false)
- var x=Array.fill(w,h)(0)
- def n(y:Int,z:Int)=for(b<-z-1 to z+1;a<-y-1 to y+1 if(!(a==y&&b==z)))d+=x((a+w)%w)((b+h)%h)
- def top=new MainFrame with ActionListener{preferredSize=new Dimension(500,500)
- menuBar=new MenuBar{contents+=new Menu("C"){contents+={new MenuItem("Go/Stop"){listenTo(this)
- reactions+={case ButtonClicked(c)=>r= !r}}}}}
- contents=new Component{listenTo(mouse.clicks)
- reactions+={case e:MouseClicked=>var p=e.point
- x(p.x/c)(p.y/c)^=1
- repaint}
- override def paint(g:Graphics2D){for(j<-0 to h-1;i<-0 to w-1){var r=new Rectangle(i*c,j*c,c,c)
- x(i)(j)match{case 0=>g draw r
- case 1=>g fill r}}}}
- def actionPerformed(e:ActionEvent){if(r){var t=x.map(_.clone)
- for(j<-0 to h-1;i<-0 to w-1){d=0
- n(i,j)
- x(i)(j)match{case 0=>if(d==3)t(i)(j)=1
- case 1=>if(d<2||d>3)t(i)(j)=0}}
- x=t.map(_.clone)
- repaint}}
- val t=new Timer(200,this)
- t.start}}
- import swing._
- import event._
- object Life extends SimpleSwingApplication
- {
- import java.awt.event._
- import javax.swing._
- var(w,h,c,d,run)=(20,20,20,0,false)
- var x=Array.fill(w,h)(0)
- def n(y:Int,z:Int)=for(b<-z-1 to z+1;a<-y-1 to y+1 if(!(a==y&&b==z)))d+=x((a+w)%w)((b+h)%h)
- def top=new MainFrame with ActionListener
- {
- title="Life"
- preferredSize=new Dimension(500,500)
- menuBar=new MenuBar
- {
- contents+=new Menu("Control")
- {
- contents+={new MenuItem("Start/Stop")
- {
- listenTo(this)
- reactions+=
- {
- case ButtonClicked(c)=>run= !run
- }
- }}
- }
- }
- contents=new Component
- {
- listenTo(mouse.clicks)
- reactions+=
- {
- case e:MouseClicked=>
- var p=e.point
- if(p.x<w*c)
- {
- x(p.x/c)(p.y/c)^=1
- repaint
- }
- }
- override def paint(g:Graphics2D)
- {
- for(j<-0 to h-1;i<-0 to w-1)
- {
- var r=new Rectangle(i*c,j*c,c,c)
- x(i)(j) match
- {
- case 0=>g draw r
- case 1=>g fill r
- }
- }
- }
- }
- def actionPerformed(e:ActionEvent)
- {
- if(run)
- {
- var t=x.map(_.clone)
- for(j<-0 to h-1;i<-0 to w-1)
- {
- d=0
- n(i,j)
- x(i)(j) match
- {
- case 0=>if(d==3)t(i)(j)=1
- case 1=>if(d<2||d>3)t(i)(j)=0
- }
- }
- x=t.map(_.clone)
- repaint
- }
- }
- val timer=new Timer(200,this)
- timer.start
- }
- }
- using System.Windows.Forms;class G:Form{static void Main(){new G(25).ShowDialog();}
- public G(int z){var g=new Panel[z,z];var n=new int [z,z];int x,y,t;for(int i=0;i<z;
- i++)for(int j=0;j<z;j++){var p=new Panel{Width=9,Height=9,Left=i*9,Top=j*9,BackColor
- =System.Drawing.Color.Tan};p.Click+=(s,a)=>p.Visible=!p.Visible;Controls.Add(g[i,j]=
- p);}KeyUp+=(s,_)=>{for(int i=0;i<99;i++){for(x=0;x<z;x++)for(y=0;y<z;y++){t=0;for(int
- c=-1;c<2;c++)for(int d=-1;d<2;d++)if(c!=0||d!=0){int a=x+c,b=y+d;a=a<0?24:a>24?0:a;b=
- b<0?24:b>24?0:b;t+=g[a,b].Visible?0:1;}if(t==3||t>1&&!g[x,y].Visible)n[x,y]=1;if(t<2
- ||t>3)n[x,y]=0;}for(x=0;x<z;x++)for(y=0;y<z;y++)g[x,y].Visible=n[x,y]<1;Update();}};}}
- l=:[:+/(3 4=/[:+/(,/,"0/~i:1)|.])*.1,:]
- r =: (i.3 3) e. 1 2 3 5 8
- r
- 0 1 1 NB. A glider!
- 1 0 1
- 0 0 1
- R =: _1 _2 |. 5 7 {. r
- R
- 0 0 0 0 0 0 0 NB. Test board
- 0 0 0 1 1 0 0
- 0 0 1 0 1 0 0
- 0 0 0 0 1 0 0
- 0 0 0 0 0 0 0
- l R
- 0 0 0 0 0 0 0 NB. Single step
- 0 0 0 1 1 0 0
- 0 0 0 0 1 1 0
- 0 0 0 1 0 0 0
- 0 0 0 0 0 0 0
- import java.awt.Color._
- import swing._
- import event._
- import actors.Actor._
- new SimpleSwingApplication{var(y,r,b)=(200,false,Array.fill(20,20)(false))
- lazy val u=new Panel{actor{loop{if(r){b=Array.tabulate(20,20){(i,j)=>def^(i:Int)= -19*(i min 0)+(i max 0)%20
- var(c,n,r)=(0,b(i)(j),-1 to 1)
- for(x<-r;y<-r;if x!=0||y!=0){if(b(^(i+x))(^(j+y)))c+=1}
- if(n&&(c<2||c>3))false else if(!n&&c==3)true else n}};repaint;Thread.sleep(y)}}
- focusable=true
- preferredSize=new Dimension(y,y)
- listenTo(mouse.clicks,keys)
- reactions+={case e:MouseClicked=>val(i,j)=(e.point.x/10,e.point.y/10);b(i)(j)= !b(i)(j)case _:KeyTyped=>r= !r}
- override def paintComponent(g:Graphics2D){g.clearRect(0,0,y,y);g.setColor(red)
- for(x<-0 to 19;y<-0 to 19 if b(x)(y))g.fillRect(x*10,y*10,9,9)}}
- def top=new Frame{contents=u}}.main(null)
- 10 DEFINT A-Z:DEF SEG=&HB800:KEY OFF:COLOR 7,0:CLS:DEF FNP(X,Y)=PEEK((((Y+25)MOD 25)*80+((X+80)MOD 80))*2)
- 20 X=0:Y=0
- 30 LOCATE Y+1,X+1,1
- 40 S$=INKEY$:IF S$=""GOTO 40
- 50 IF S$=CHR$(13)GOTO 150
- 60 IF S$=" "GOTO 130
- 70 IF S$=CHR$(0)+CHR$(&H48)THEN Y=(Y-1+25)MOD 25:GOTO 30
- 80 IF S$=CHR$(0)+CHR$(&H50)THEN Y=(Y+1)MOD 25:GOTO 30
- 90 IF S$=CHR$(0)+CHR$(&H4B)THEN X=(X-1+80)MOD 80:GOTO 30
- 100 IF S$=CHR$(0)+CHR$(&H4D)THEN X=(X+1)MOD 80:GOTO 30
- 110 IF S$="c"THEN CLS:GOTO 20
- 120 GOTO 40
- 130 Z=PEEK((Y*80+X)*2):IF Z=42 THEN Z=32ELSE Z=42
- 140 POKE(Y*80+X)*2,Z:GOTO 40
- 150 LOCATE 1,1,0:ON KEY(1)GOSUB 320:KEY(1) ON
- 160 V!=TIMER+.5:FOR Y=0 TO 24:FOR X=0 TO 79:N=0
- 170 Z=FNP(X-1,Y-1):IF Z=42 OR Z=46 THEN N=N+1
- 180 Z=FNP(X,Y-1):IF Z=42 OR Z=46 THEN N=N+1
- 190 Z=FNP(X+1,Y-1):IF Z=42 OR Z=46 THEN N=N+1
- 200 Z=FNP(X-1,Y):IF Z=42 OR Z=46 THEN N=N+1
- 210 Z=FNP(X+1,Y):IF Z=42 OR Z=46 THEN N=N+1
- 220 Z=FNP(X-1,Y+1):IF Z=42 OR Z=46 THEN N=N+1
- 230 Z=FNP(X,Y+1):IF Z=42 OR Z=46 THEN N=N+1
- 240 Z=FNP(X+1,Y+1):IF Z=42 OR Z=46 THEN N=N+1
- 250 Z=PEEK((Y*80+X)*2):IF Z=32 THEN IF N=3 THEN Z=43
- 260 IF Z=42 THEN IF N<2 OR N>3 THEN Z=46
- 270 POKE(Y*80+X)*2,Z:NEXT:NEXT:FOR Y=0 TO 24:FOR X=0 TO 79:Z=PEEK((Y*80+X)*2):IF Z=46 THEN Z=32
- 280 IF Z=43 THEN Z=42
- 290 POKE(Y*80+X)*2,Z:NEXT:NEXT
- 300 IF TIMER<V!GOTO 300
- 310 IF INKEY$=""GOTO 160
- 320 SYSTEM
- 1000 REM Conway's Game of Life
- 1001 REM -
- 1002 REM Copyright (c) 2012 Thorsten "mirabilos" Glaser
- 1003 REM All rights reserved. Published under The MirOS Licence.
- 1004 REM -
- 1005 DEFINT A-Z:DEF SEG=&hB800
- 1006 KEY OFF:COLOR 7,0:CLS
- 1007 DEF FNP(X,Y)=PEEK((((Y+25) MOD 25)*80+((X+80) MOD 80))*2)
- 1010 PRINT "Initial setting mode, press SPACE to toggle, RETURN to continue"
- 1020 PRINT "Press C to clear the board, R to reset. OK? Press a key then."
- 1030 WHILE INKEY$="":WEND
- 1050 CLS
- 1065 DATA 3,3,4,3,5,3,6,3,7,3,8,3,3,4,4,4,5,4,6,4,7,4,8,4
- 1066 DATA 10,3,10,4,10,5,10,6,10,7,10,8,11,3,11,4,11,5,11,6,11,7,11,8
- 1067 DATA 11,10,10,10,9,10,8,10,7,10,6,10,11,11,10,11,9,11,8,11,7,11,6,11
- 1068 DATA 4,11,4,10,4,9,4,8,4,7,4,6,3,11,3,10,3,9,3,8,3,7,3,6
- 1069 DATA 21,0,22,1,22,2,21,2,20,2,-1,-1
- 1070 RESTORE 1065
- 1080 READ X,Y
- 1090 IF X=-1 GOTO 1120
- 1100 POKE (Y*80+X)*2,42
- 1110 GOTO 1080
- 1120 X=0:Y=0
- 1125 LOCATE Y+1,X+1,1
- 1130 S$=INKEY$
- 1140 IF S$="" GOTO 1130
- 1150 IF S$=CHR$(13) GOTO 1804
- 1160 IF S$=" " GOTO 1240
- 1170 IF S$=CHR$(0)+CHR$(&h48) THEN Y=(Y-1+25) MOD 25:GOTO 1125
- 1180 IF S$=CHR$(0)+CHR$(&h50) THEN Y=(Y+1) MOD 25:GOTO 1125
- 1190 IF S$=CHR$(0)+CHR$(&h4B) THEN X=(X-1+80) MOD 80:GOTO 1125
- 1200 IF S$=CHR$(0)+CHR$(&h4D) THEN X=(X+1) MOD 80:GOTO 1125
- 1210 IF S$="c" THEN CLS:GOTO 1120
- 1220 IF S$="r" GOTO 1050
- 1225 IF S$=CHR$(27) THEN END
- 1230 GOTO 1130
- 1240 Z=PEEK((Y*80+X)*2)
- 1250 IF Z=42 THEN Z=32 ELSE Z=42
- 1260 POKE (Y*80+X)*2,Z
- 1270 GOTO 1130
- 1804 LOCATE 1,1,0
- 1900 ON KEY(1) GOSUB 2300
- 1910 KEY(1) ON
- 2000 V!=TIMER+.5
- 2010 FOR Y=0 TO 24
- 2020 FOR X=0 TO 79
- 2030 N=0
- 2040 Z=FNP(X-1,Y-1):IF Z=42 OR Z=46 THEN N=N+1
- 2050 Z=FNP(X ,Y-1):IF Z=42 OR Z=46 THEN N=N+1
- 2060 Z=FNP(X+1,Y-1):IF Z=42 OR Z=46 THEN N=N+1
- 2070 Z=FNP(X-1,Y ):IF Z=42 OR Z=46 THEN N=N+1
- 2080 Z=FNP(X+1,Y ):IF Z=42 OR Z=46 THEN N=N+1
- 2090 Z=FNP(X-1,Y+1):IF Z=42 OR Z=46 THEN N=N+1
- 2100 Z=FNP(X ,Y+1):IF Z=42 OR Z=46 THEN N=N+1
- 2110 Z=FNP(X+1,Y+1):IF Z=42 OR Z=46 THEN N=N+1
- 2120 Z=PEEK((Y*80+X)*2)
- 2130 IF Z=32 THEN IF N=3 THEN Z=43
- 2140 IF Z=42 THEN IF N<2 OR N>3 THEN Z=46
- 2150 POKE (Y*80+X)*2,Z
- 2160 NEXT X
- 2170 NEXT Y
- 2200 FOR Y=0 TO 24
- 2210 FOR X=0 TO 79
- 2220 Z=PEEK((Y*80+X)*2)
- 2230 IF Z=46 THEN Z=32
- 2240 IF Z=43 THEN Z=42
- 2250 POKE (Y*80+X)*2,Z
- 2260 NEXT X
- 2270 NEXT Y
- 2280 IF TIMER<V! GOTO 2280
- 2290 IF INKEY$="" GOTO 2000
- 2300 SYSTEM
- ListAnimate[ArrayPlot/@CellularAutomaton[{224,{2,{{2,2,2},{2,1,2},
- {2,2,2}}},{1,1}},{RandomInteger[1,{9,9}],0},90]]
- [/f ARGUMENTS 0 get(r)file/n 20>>begin[/m
- n 1 sub/b[n{[n{f token pop}repeat]}repeat]/c 400
- n div/F{dup 0 lt{n add}if dup n ge{n sub}if}>>begin{0
- 1 m{dup 0 1 m{2 copy b exch get exch get 1 xor setgray
- c mul exch c mul c c rectfill dup}for pop pop}for
- showpage/b[0 1 m{/x exch def[0 1 m{/y exch def 0
- y 1 sub 1 y 1 add{F dup x 1 sub 1 x
- 1 add{F b exch get exch get 3 2 roll add exch
- dup}for pop pop}for b x get y get sub b x get y get
- 0 eq{3 eq{1}{0}ifelse}{dup 2 eq exch 3 eq
- or{1}{0}ifelse}ifelse}for]}for]def}loop
- [
- /f ARGUMENTS 0 get(r)file
- /n 20
- /sz 400
- %/r{rand 2147483647 div}
- >>begin
- [
- /m n 1 sub
- /b[
- %n{[n{r .15 le{1}{0}ifelse}repeat]}repeat
- n{[n{f token pop}repeat]}repeat
- ]
- /c sz n div
- /F{dup 0 lt{n add}if dup n ge{n sub}if}
- >>begin
- {
- 0 1 m{dup % y y
- 0 1 m{ % y y x
- 2 copy b exch get exch get 1 xor setgray
- c mul exch c mul c c rectfill
- dup
- }for pop pop}for
- pstack
- showpage
- /b[0 1 m{/x exch def
- [0 1 m{/y exch def
- 0
- y 1 sub 1 y 1 add{F dup %s y y
- x 1 sub 1 x 1 add{F %s y y x
- b exch get exch get %s y bxy
- 3 2 roll add exch %s+bxy y
- dup %s y y
- }for pop pop}for
- b x get y get sub
- b x get y get
- 0 eq{3 eq{1}{0}ifelse}{dup 2 eq exch 3 eq or{1}{0}ifelse}ifelse
- }for]
- }for]def
- }loop
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0
- 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0
- 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0
- 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0
- 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0
- 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0
- 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- (]+.&(3&=)+)+/((4&{.,(_4&{.))(>,{,~<i:1))&|.
- f =: 5 5 $ 0 1 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
- f
- 0 1 0 0 0
- 0 0 1 0 0
- 1 1 1 0 0
- 0 0 0 0 0
- 0 0 0 0 0
- f (]+.&(3&=)+)+/((4&{.,(_4&{.))(>,{,~<i:1))&|. f
- 0 0 0 0 0
- 1 0 1 0 0
- 0 1 1 0 0
- 0 1 0 0 0
- 0 0 0 0 0
- int h=22,t=24,i,j;int[][]w=new int[t][t],b=new int[t][t];int[]q={1,0,-1};void draw(){if(t<9){clear();for(i=2;i<h;i++){for(j=2;j<h;j++)w[i][j]=b[i][j];w[i][1]=w[i][21];w[i][h]=w[i][2];w[1][i]=w[21][i];w[h][i]=w[2][i];}for(i=1;i<23;i++)for(j=1;j<23;j++){t=-w[i][j];for(int s:q)for(int d:q)t+=w[i+s][j+d];b[i][j]=w[i][j]>0&(t<2|t>3)?0:t==3?1:b[i][j];}a();}}void keyPressed(){t=0;}void mousePressed(){int i=mouseX/5+2,j=mouseY/5+2;w[i][j]=b[i][j]=1;a();}void a(){for(i=0;i<h-2;i++)for(j=0;j<h-2;j++)if(w[i+2][j+2]==1)rect(i*5,j*5,5,5);}
- int h=22,t=24,i,j;
- int[][]w=new int[t][t],b=new int[t][t];
- int[]q={1,0,-1};
- void draw(){
- if(t<9){
- clear();
- for(i=2;i<h;i++){
- for(j=2;j<h;j++)
- w[i][j]=b[i][j];
- w[i][1]=w[i][21];
- w[i][h]=w[i][2];
- w[1][i]=w[21][i];
- w[h][i]=w[2][i];
- }
- for(i=1;i<23;i++)
- for(j=1;j<23;j++){
- t=-w[i][j];
- for(int s:q)
- for(int d:q)
- t+=w[i+s][j+d];
- b[i][j]=w[i][j]>0&(t<2|t>3)?0:t==3?1:b[i][j];
- }
- a();
- }
- }
- void keyPressed(){
- t=0;
- }
- void mousePressed(){
- int i=mouseX/5+2,j=mouseY/5+2;
- w[i][j]=b[i][j]=1;
- a();
- }
- void a(){
- for(i=0;i<h-2;i++)
- for(j=0;j<h-2;j++)
- if(w[i+2][j+2]==1)
- rect(i*5,j*5,5,5);
- }
- mapfile a
- for e in {0..863};{
- for i in {0..8};{
- [ "${a[(e/36+i/3-1)%24]:(e+i%3-1)%36:1}" == O ]&&((n++))
- }
- d=
- c=${a[e/36]:e%36:1}
- [ "$c" == O ]&&((--n==2))&&d=O
- ((n-3))||d=O
- b[e/36]+=$d
- n=
- }
- printf -vo %s\n "${b[@]}"
- echo "$o"
- exec $0<<<"$o"
- $ ./conway.sh << EOF
- O
- O
- OOO
- EOF
- O O
- OO
- O
- O
- O O
- OO
- man tr | tr [:alnum:] O | ./conway.sh
- from Tkinter import*
- import copy
- z=range
- F=50
- T=Tk()
- S=9
- f=[F*[0]for i in'7'*F]
- c=Canvas(T,bg='white',width=S*F,height=S*F)
- c.pack()
- def p(x,y,a):f[y][x]=f[y][x]or c.create_rectangle(x*S,y*S,x*S+S,y*S+S,fill='gray')if a else c.delete(f[y][x])
- r=1
- def R(e):global r;r=1-r
- exec("c.bind('<Button-%i>',lambda e:p(e.x/S,e.y/S,%i));c.bind('<B%i-Motion>',lambda e:p(e.x/S,e.y/S,%i));"*2%(1,1,1,1,3,0,3,0))
- c.bind('<Button-2>',R)
- def L():
- T.after(99,L)
- if r:return
- g=copy.deepcopy(f)
- for y in z(F):
- for x in z(F):
- n=8
- for j in z(-1,2):
- for i in z(-1,2):
- if i or j:n-=not g[(y+j)%F][(x+i)%F]
- if 1<n<4:
- if n==3and not g[y][x]:p(x,y,1)
- else:p(x,y,0)
- L()
- T.mainloop()
- from Tkinter import*
- import copy
- z=range
- F=50
- T=Tk()
- S=9
- f=[F*[0]for i in'7'*F]
- c=Canvas(T,bg='white',width=S*F,height=S*F)
- c.pack()
- def p(x,y,a):f[y][x]=f[y][x]or c.create_rectangle(x*S,y*S,x*S+S,y*S+S,fill='gray')if a else c.delete(f[y][x])
- r=1
- def R(e):global r;r=1-r
- exec("c.bind('<Button-%i>',lambda e:p(e.x/S,e.y/S,%i));c.bind('<B%i-Motion>',lambda e:p(e.x/S,e.y/S,%i));"*2%(1,1,1,1,3,0,3,0))
- c.bind('<Button-2>',R)
- def L():
- T.after(99,L)
- if r:return
- g=copy.deepcopy(f)
- for y in z(F):
- for x in z(F):
- n=8
- for j in z(-1,2):
- for i in z(-1,2):
- if i or j:n-=not g[(y+j)%F][(x+i)%F]
- if 1<n<4:
- if n==3and not g[y][x]:p(x,y,1)
- else:p(x,y,0)
- L()
- T.mainloop()
- /* Fill an array with 0's and 1's, and call g(array, width, height) to iterate */
- g=function(f,c,g,d,e,b,h){g=[];e=[c+1,c,c-1,1];for(b=c*c;b--;g[b]=3==d||f[b]&&2==d,d=0)for(h in e)d+=f[b+e[h]]+f[b-e[h]];return g}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement