second
This commit is contained in:
parent
5f7fcb96ed
commit
01204dfa2f
34 changed files with 1498 additions and 0 deletions
3
terrain.js
Normal file
3
terrain.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import {GW,GH} from './engine.js';
|
||||
const stops=[[0,105,89,59],[.32,103,113,61],[.68,72,108,48],[1,41,80,40]];
|
||||
export function paintTerrain(tc,state,layer){const im=tc.createImageData(GW,GH);for(let i=0;i<GW*GH;i++){let r,g,b;if(layer==='moisture'){const m=state.moisture[i];r=23+m*26;g=43+m*80;b=44+m*101}else{const p=Math.min(1,state.plants[i]/.5);let k=0;while(k<2&&p>stops[k+1][0])k++;const lo=stops[k],hi=stops[k+1],f=(p-lo[0])/(hi[0]-lo[0]);r=lo[1]+(hi[1]-lo[1])*f;g=lo[2]+(hi[2]-lo[2])*f;b=lo[3]+(hi[3]-lo[3])*f}const j=i*4;im.data[j]=r;im.data[j+1]=g;im.data[j+2]=b;im.data[j+3]=255}tc.putImageData(im,0,0)}
|
||||
Loading…
Add table
Add a link
Reference in a new issue