dev:program_ulam
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dev:program_ulam [2015/06/01 18:07] – [Capitalization Matters] xychen | dev:program_ulam [2016/01/14 07:13] (current) – ackley | ||
|---|---|---|---|
| Line 21: | Line 21: | ||
| ==== EventWindow Indices ==== | ==== EventWindow Indices ==== | ||
| - | Left picture is an indices map within an EventWindow. | + | {{ : |
| - | {{: | + | |
| + | The '' | ||
| + | |||
| + | In general, when code is referring | ||
| ===== The ' | ===== The ' | ||
| Line 32: | Line 36: | ||
| EventWindow ew; | EventWindow ew; | ||
| Void behave(){ | Void behave(){ | ||
| - | ew[1]=ew[0]; | + | ew[1]=ew[0]; |
| } | } | ||
| } | } | ||
| Line 318: | Line 322: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ===== Node Elements ===== | ||
| + | We have some cool features in the new MFM simulator. One of them is that an Atom can change its color dynamically. We made this little '' | ||
| + | |||
| + | {{: | ||
| + | <code - Node.ulam> | ||
| + | /** | ||
| + | Node is a demo element. | ||
| + | \color #986 | ||
| + | \symbol Nd | ||
| + | \symmetries normal | ||
| + | */ | ||
| + | element Node{ | ||
| + | typedef Unsigned(6) SiteNum; | ||
| + | typedef Int(16) Coord; | ||
| + | typedef Unary(1) FireFlag; | ||
| + | typedef Int(4) Weight; | ||
| + | typedef Unsigned(8) ARGB[4]; | ||
| + | typedef Unsigned(8) ColorValue; | ||
| + | |||
| + | DebugUtils du; | ||
| + | EventWindow ew; | ||
| + | Once oc; | ||
| + | AtomUtils au; | ||
| + | Weight wa; | ||
| + | Weight wm; | ||
| + | Weight wb; | ||
| + | FireFlag fire; | ||
| + | Weight thresh; | ||
| + | ColorValue red; | ||
| + | ColorValue grn; | ||
| + | ColorValue blu; | ||
| + | |||
| + | Int getSum(){ | ||
| + | Int sum; | ||
| + | C2D mcd; | ||
| + | WindowServices ws; | ||
| + | ws.reset(1, | ||
| + | for(Int slot=ws.next(); | ||
| + | if(ew[slot] is Node){ | ||
| + | Atom a=ew[slot]; | ||
| + | Node you=(Node) a; | ||
| + | mcd=ew.getCoord((SiteNum)slot); | ||
| + | Coord mx=mcd.getX(); | ||
| + | Coord my=mcd.getY(); | ||
| + | if(mx< | ||
| + | if(my< | ||
| + | sum=sum+wa*you.fire; | ||
| + | }else if(my==0){ | ||
| + | sum=sum+wm*you.fire; | ||
| + | }else if(my> | ||
| + | sum=sum+wb*you.fire; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | return sum; | ||
| + | } | ||
| + | FireFlag getFire(Int s){ | ||
| + | if(s> | ||
| + | return 1; | ||
| + | } | ||
| + | return 0; | ||
| + | } | ||
| + | Void initSelf(){ | ||
| + | Random rd; | ||
| + | Weight w; | ||
| + | wa=(Weight)rd.between((Int)w.minof, | ||
| + | wm=(Weight)rd.between((Int)w.minof, | ||
| + | wb=(Weight)rd.between((Int)w.minof, | ||
| + | thresh=(Weight)rd.between((Int)w.minof, | ||
| + | } | ||
| + | Void changeColor(){ | ||
| + | Random rd; | ||
| + | red=rd.between(0, | ||
| + | grn=rd.between(0, | ||
| + | blu=rd.between(0, | ||
| + | } | ||
| + | ARGB getColor(Unsigned selector){ | ||
| + | ColorUtils cu; | ||
| + | ARGB ret=cu.color(0xff00ff00u); | ||
| + | if(fire==1){ | ||
| + | ret[1]=red; | ||
| + | ret[2]=grn; | ||
| + | ret[3]=blu; | ||
| + | }else{ | ||
| + | ret=cu.color(0xff090806u); | ||
| + | } | ||
| + | return ret; | ||
| + | } | ||
| + | Void behave(){ | ||
| + | Int msum; | ||
| + | if(oc.new()){ | ||
| + | initSelf(); | ||
| + | du.printContext(); | ||
| + | } | ||
| + | msum=getSum(); | ||
| + | fire=getFire(msum); | ||
| + | changeColor(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | We use a '' | ||
| + | |||
| + | In the '' | ||
| + | |||
| + | Like other Neurons, our '' | ||
| + | |||
dev/program_ulam.1433182020.txt.gz · Last modified: 2015/06/01 18:07 by xychen
