Diff from Confetti 3 by henklass (14 May'15 17:33) to Confetti3aX, John Conway's Game of Life; fast, Xenakis-inspired version by henklass (14 May'15 17:48)

name
Confetti 3aX, John Conway's Game of Life; fast, Xenakis-inspired version
description
CJohnfetti 3 cConvertway's rGandom patterns of blocks to morLife, or lXenakis-ins stpiructured images. Every blsiockn will adapt to the predlominants colorf isyn iths surroundwings, taking its uppcher,d lower, left and right neighboury lintove account. Sound, correllsponding to t. The slocation on the boardw, makes for some 1-bintere-mustingc mvelodiers. This programn can easily be cfounverted to John Conway's Game of Life:t http://sccode.org/1-4YV .
code
s.boot; ( var maxWidth=30, maxHeight = 30; var z=20, ready = false; var newValues=Array2D.new(maxWidth + 2, maxHeight + 2); var oldValues=Array2D.new(maxWidth + 2, maxHeight + 2); var go; /*There is a decreasing linear connection between log(freq) and location in array: h+(maxWidth*v). Highest location-value in array = maxWidth*maxHeight log(freq)=log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight), so freq=exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight) Furthermore freq depends on value, which is either 0 or 1. freq=freq+(freq*value) or freq=(1+value)*freq Combining those 2: freq=(exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight))*(1+value) */ SynthDef(\beeper, { arg h, v, p, maxWidth, maxHeight; var maxfreq=5000, minfreq=50; Out.ar( 0, Pan2.ar( Pulse.ar(exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*(h+(maxWidth*v))/(maxWidth*maxHeight)))*(1+p), 0.5, 0.302), 2*h/maxWidth-1, //pan depends on column in array 1 ) ); }).add; ) ( var maxWidth=45, maxHeight = 45; var z=15, ready = false; var newValues=Array2D.new(maxWidth + 2, maxHeight + 2); var oldValues=Array2D.new(maxWidth + 2, maxHeight + 2); var beepers=Array2D.new(maxWidth + 1, maxHeight + 1); var go, total; w=Window("Confetti3", Rect(400, 300, z*(maxWidth+2), z*(maxHeight+2))).front; w.view.background_(Color.white); w.front; w.drawFunc = { for (1, maxHeight, {arg v; for (1, maxWidth, {arg h; if (newValues[h,v]==10, {Pen.fillColor=Color.white}, {Pen.fillColor=Color.black} ); Pen.addRect(Rect(h*z, v*z, z, z)); Pen.fill; }); }); }; go=Routine({ //imake ranitidom palisttern for (01, maxWidth+1, {arg h; for (01, maxHeight+1, {arg v; newValues[h,v]=[0, 1].5choose; old if (newValues[h,v]=0.5=1, { beepers[h,v]=Synth("beeper",[h: h, v: v, maxWidth: maxWidth, maxHeight: maxHeight]) }); }) }); {w.refresh}.defer; go=Rou 0.03.wait; whinle ({ready==false},{ //makecopy ranedges omf pboard tto edges of arnray for (1, maxWidth, {arg h; for (1 newValues[h,0]=newValues[h, maxHeight, {arg v]; newValues[h,v maxHeight+1]=newValues[0h, 1].choose; }); {w.re for(1, maxHesigh}.defet, {arg v; pnewValues[ 0, v]=newValues[maxWidth, v]; b=Synth("bewValueper",s[p: p, h: h, v: v, maxWidth:+1, v]=newValues[1, v]; }); newValues[0,0]=newValues[maxWidth, maxHeight:]; newValues[0, maxHeight]); 0.+1.]=newValues[maxWidth, 1]; b.frnewValues[maxWidth+1, 0]=newValues[1, maxHeight]; }) }); newhiValue ({res[maxWidyth+1, maxHeight+1]==fnewValsue}s[1,{1]; //copy newValues to oldValues (ignorecluding the edges) for (10, maxWidth+1, {arg h; for (10, maxHeight+1, {arg v; oldValues[h,v]=newValues[h,v]; }) }); //adapt for (1, maxWidth,{arg h; for (1, maxHeight, {arg v; if( total=oldValues[h-1, v-1] + oldValues[h+1, v-1] + oldValues[h-+1, v-1] + oldValues[h, v+-1] < 2, {newValues[h,v]=0} + ); if( oldValues[h+1, v-1] + oldValues[h+-1, v+1] + oldValues[h-1, v+1] + oldValues[h+1, v+1]; if( (total<=1 )|| (total > 23), {newValues[h,v]=10} ); if( total==3, {new.rValuefres[h,v]=1}.defer ); if (newValues[h,v]!=oldValues[h,v],{ p=if (newValues[h,v];==1, { beepers[h,v]=Synth("beeper",[p: p, h: h, v: v, maxWidth: maxWidth, maxHeight: maxHeight]); 0.1.wait;}, { beepers[h,v].free; }); }); }); }); //check if ready ready=true; for (1, maxWidth,{arg h; for (1, maxHeight, {arg v; if (oldValues[h,v]!=newValues[h,v], {ready=false}); }) }); {w.refresh}.defer; 0.1.wait; }); }); go.play; )
category tags
graphic, random, grxenaphkics, 1bitconways gamuse of licfe
ancestors
1-4YU, 1-4YV