/** 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,4); for(Int slot=ws.next();slot>=0;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<0){ if(my<0){ sum=sum+wa*you.fire; }else if(my==0){ sum=sum+wm*you.fire; }else if(my>0){ sum=sum+wb*you.fire; } } } } return sum; } FireFlag getFire(Int s){ if(s>=thresh){ return 1; } return 0; } Void initSelf(){ Random rd; Weight w; wa=(Weight)rd.between((Int)w.minof,(Int)w.maxof); wm=(Weight)rd.between((Int)w.minof,(Int)w.maxof); wb=(Weight)rd.between((Int)w.minof,(Int)w.maxof); thresh=(Weight)rd.between((Int)w.minof,(Int)w.maxof); } Void changeColor(){ Random rd; red=rd.between(0,3)*80+rd.between(0,16); grn=rd.between(0,3)*80+rd.between(0,16); blu=rd.between(0,3)*80+rd.between(0,16); } 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(); } }