World zzz905

Classes: DemoLiveLife DemoLiveLifeRedBlue DemoLiveLissajous FnordApp GameTroids

Methods: draw lifestep prepost: step

Classes

DemoLiveLife

lifestep
dx,dy= self delX, self delY. dx2,dy2= dx idiv: 2, dy idiv: 2. rx,ry= dx2 - 1, dy2 - 1. nextState = FOR(x: self numX)MAP( FOR(y: self numY)MAP( nei = 0. FOR(i: 3)DO( i = i - 1 + x. FOR(j: 3)DO( j = j - 1 + y. nei = nei + ((state at: i) at: j). ]. ]. "Notice cell x,y can count as a nei." IF((state at: x) at: y) THEN( OR(nei == 3; nei == 4;) ) ELSE( nei == 1 ). ]. ]. "Update state, unless embargo is in place." IF{embargo < Sys secs}THEN{state = nextState}. FOR(x: self numX)DO{ FOR(y: self numY)DO{ IF{(state at: x) at: y} THEN{ xx = x * dx + dx2. yy = y * dy + dy2. self green rect: (xx - rx, yy - ry) to: (xx + rx, yy + ry). } ELSE{ xx = x * dx + dx2. yy = y * dy + dy2. self black rect: (xx - rx, yy - ry) to: (xx + rx, yy + ry). } } }.

DemoLiveLifeRedBlue

lifestep
dx,dy= self delX, self delY. dx2,dy2= dx idiv: 2, dy idiv: 2. rx,ry= dx2 - 1, dy2 - 1. pop = popR = popB = 0. nextState = FOR{x: self numX} MAP{ xx = x * dx + dx2. FOR{y: self numY} MAP{ yy = y * dy + dy2. colored = 0. FOR(i: 3)DO{ i = i - 1 + x. FOR(j: 3)DO{ j = j - 1 + y. colored = colored + ((self state at: i) at: j). }. }. "Notice cell x,y can count as a colored". "Simple neighbor count (no color)". bw = colored % 10. old= (self state at: x) at: y. z= IF{old} THEN{ OR{bw == 3; bw == 4;} } ELSE{ bw == 2 }. IF{old} THEN{ rc = (old idiv: 10) % 10. bc = (old idiv: 100) % 10. } ELSE{ "Red & Blue counts". rc = (colored idiv: 10) % 10. bc = (colored idiv: 100) % 10. }. z= COND{ z == 0 , (clr = self black. 0); rc > bc, (pop=pop+1. popR=popR+1. clr = self red. 11); rc < bc, (pop=pop+1. popB=popB+1. clr = self blue. 101); 1 , (pop=pop+1. clr = self white. 1); }. clr rect: (xx - rx, yy - ry) to: (xx + rx, yy + ry). z. }. "next y" }. "next x" 'FINISHED lifeStep' say: (pop, popR, popB). self state: nextState.

DemoLiveLissajous

draw
w= se scr width / 2. h= se scr height / 2. self clear: 0. prev= w*2, h. n = 1000. start = Sys secs. FOR(i : n) DO( xy= i / 19 $ cos * w + w, i / 3 $ sin * h + h. self newInk: i $ line: prev to: xy $ fontSize: 24 $ text: i str sw: xy. prev= xy. self post. ). finish= Sys secs. time= finish - start. fps= n / time. msg= (n, ' frames / ', time, 's = ', fps, ' fps') jam. self white fontSize: 32 $ text: msg sw: (100,100).

FnordApp

prepost:
x = se gl ex / 2. y = se gl ey / 2. se gl light: x @ y @ 100. se gl eye: x @ y @ (x - y)abs. se gl look: 100 - y @ 100 - x @ 0. " se gl ambient: 0.3 @0.3@0.3 . "

GameTroids

step
se clear: COND{ship ttl < 0, 400; aa len < 1, 40; 1, 555;}. FOR{ast: aa} DO{ ast step: se. ast draw: se. }. FOR{bul: bb} DO{ bul step: se. bul draw: se. }. ship step: se. ship draw: se. "frames per sec" se white text: ((se scr fps ifNil:[0]) fmt: '%.2f fps') str sw: (20,40). se post. "check collisions." FOR{ast: aa} DO{ FOR{bul: bb} DO{ dx= ast px - bul px $abs. dy= ast py - bul py $abs. IF{dx+dy < ast sz + bul sz} THEN{ ast ttl: -1. bul ttl: -1. }. }. dx= ast px - ship px $abs. dy= ast py - ship py $abs. IF{dx+dy < ast sz + ship sz} THEN{ ship ttl: -1. ship ink: se red. }. }. "Cleanup expired asteroids." aa= FOR{a: aa}MAP{a}IF{a ttl > 0}. "Cleanup expired bullets." bb= FOR{b: bb}MAP{b}IF{b ttl > 0}.

Method CrossReference

draw
DemoLiveLissajous  
lifestep
DemoLiveLife   DemoLiveLifeRedBlue  
prepost:
FnordApp  
step
GameTroids