{
   "code" : "s.boot;\r\n\r\n(\r\n\r\n/*There is a decreasing linear connection between log(freq) and location in array: h+(maxWidth*v).\r\nHighest location-value in array = maxWidth*maxHeight\r\nlog(freq)=log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight), so\r\nfreq=exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight)\r\nFurthermore freq depends on value, which is either 0 or 1. \r\nfreq=freq+(freq*value) or freq=(1+value)*freq\r\nCombining those 2:\r\nfreq=(exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight))*(1+value)\r\n\r\n*/\r\n\r\nSynthDef(\\beeper, { arg h, v, maxWidth, maxHeight;\r\n\tvar maxfreq=5000, minfreq=50;\r\n\tOut.ar(\r\n\t\t0, \r\n\t\tPan2.ar(\r\n\t\t\tPulse.ar(exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight))), 0.5, 0.02), \r\n\t\t\t2*h/maxWidth-1, //pan depends on column in array\r\n\t\t\t1\r\n\t\t)\r\n\t);\r\n\t\r\n}).add;\r\n)\r\n\r\n(\r\nvar maxWidth=45, maxHeight = 45;\r\nvar z=15, ready = false;\r\nvar newValues=Array2D.new(maxWidth + 2, maxHeight + 2);\r\nvar oldValues=Array2D.new(maxWidth + 2, maxHeight + 2);\r\nvar beepers=Array2D.new(maxWidth + 1, maxHeight + 1);\r\nvar go, total;\r\n\r\n\r\n\r\nw=Window(\"Confetti3\", Rect(400, 300, z*(maxWidth+2), z*(maxHeight+2))).front;\r\nw.view.background_(Color.white);\r\nw.front;\r\n\r\nw.drawFunc = {\r\n\t\tfor (1, maxHeight, {arg v;\r\n\t\t\tfor (1, maxWidth, {arg h;\r\n\t\t\t\tif (newValues[h,v]==0, \r\n\t\t\t\t\t{Pen.fillColor=Color.white},\r\n\t\t\t\t\t{Pen.fillColor=Color.black}\r\n\t\t\t\t);\r\n\t\t\t\tPen.addRect(Rect(h*z, v*z, z, z));\r\n\t\t\t\tPen.fill;\r\n\t\t\t});\r\n\t\t});\r\n};\r\n\r\ngo=Routine({\r\n\t//make random pattern\r\n\tfor (1, maxWidth, {arg h;\r\n\t\tfor (1, maxHeight, {arg v;\r\n\t\t\tnewValues[h,v]=[0, 1].choose;\r\n\t\t\tif (newValues[h,v]==1, {\r\n\t\t\t\tbeepers[h,v]=Synth(\"beeper\",[h: h, v: v, maxWidth: maxWidth, maxHeight: maxHeight])\r\n\t\t\t});\r\n\t\t})\r\n\t});\r\n\t{w.refresh}.defer;\r\n\t0.03.wait;\r\n\twhile ({ready==false},{\r\n\t\t//copy edges of board to edges of array\r\n\t\tfor(1, maxWidth, {arg h;\r\n\t\t\tnewValues[h,0]=newValues[h, maxHeight];\r\n\t\t\tnewValues[h, maxHeight+1]=newValues[h, 1];\r\n\t\t});\r\n\t\tfor(1, maxHeight, {arg v;\r\n\t\t\tnewValues[ 0, v]=newValues[maxWidth, v];\r\n\t\t\tnewValues[maxWidth+1, v]=newValues[1, v];\r\n\t\t});\r\n\t\tnewValues[0,0]=newValues[maxWidth, maxHeight];\r\n\t\tnewValues[0, maxHeight+1]=newValues[maxWidth, 1];\r\n\t\tnewValues[maxWidth+1, 0]=newValues[1, maxHeight];\r\n\t\tnewValues[maxWidth+1, maxHeight+1]=newValues[1,1];\r\n\t\t//copy newValues to oldValues (including edges)\r\n\t\tfor (0, maxWidth+1, {arg h;\r\n\t\t\tfor (0, maxHeight+1, {arg v;\r\n\t\t\t\toldValues[h,v]=newValues[h,v];\r\n\t\t\t})\r\n\t\t});\r\n\t\t//adapt\r\n\t\tfor (1, maxWidth,{arg h; \r\n\t\t\tfor (1, maxHeight, {arg v;\r\n\t\t\t\ttotal=oldValues[h-1,v-1] + oldValues[h,v-1] + oldValues[h+1,v-1] + oldValues[h-1,v]+\t\t\t\t\t\toldValues[h+1,v] + oldValues[h-1,v+1] + oldValues[h,v+1] + oldValues[h+1,v+1];\r\n\t\t\t\tif(\r\n\t\t\t\t\t(total<=1 )|| (total > 3),\r\n\t\t\t\t\t{newValues[h,v]=0}\r\n\t\t\t\t);\r\n\t\t\t\tif(\r\n\t\t\t\t\ttotal==3,\r\n\t\t\t\t\t{newValues[h,v]=1}\r\n\t\t\t\t);\r\n\t\t\t\tif (newValues[h,v]!=oldValues[h,v],{\r\n\t\t\t\t\tif (newValues[h,v]==1, {\r\n\t\t\t\t\t\tbeepers[h,v]=Synth(\"beeper\",[h: h, v: v, maxWidth: maxWidth, maxHeight: maxHeight]);\r\n\t\t\t\t\t},\r\n\t\t\t\t\t{\r\n\t\t\t\t\tbeepers[h,v].free;\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t});\r\n\t\t//check if ready\r\n\t\tready=true;\r\n\t\tfor (1, maxWidth,{arg h;\r\n\t\t\tfor (1, maxHeight, {arg v;\r\n\t\t\t\tif (oldValues[h,v]!=newValues[h,v], {ready=false});\r\n\t\t\t})\r\n\t\t});\r\n\t\t{w.refresh}.defer;\r\n\t\t0.1.wait;\r\n\t});\r\n});\r\n\r\n\r\ngo.play;\r\n)",
   "is_private" : null,
   "id" : "1-4YW",
   "labels" : [
      "graphic",
      "random",
      "xenakis",
      "conways game of life"
   ],
   "ancestor_list" : [
      "1-4YU",
      "1-4YV"
   ],
   "description" : "John Conway's Game of Life, Xenakis-inspired version with lots of synths switched on by live cells.\r\nThe slow, 1-bit-music version can be found at http://sccode.org/1-4YV .",
   "author" : "henklass",
   "name" : "Confetti3aX, John Conway's Game of Life; fast, Xenakis-inspired version"
}
