-
Notifications
You must be signed in to change notification settings - Fork 0
/
webgl-textures-v1.0.min.js
12 lines (12 loc) · 1.11 KB
/
webgl-textures-v1.0.min.js
1
2
3
4
5
6
7
8
9
10
11
12
var TEXTURES={};function color(r,g,b,a){r=r?Math.min(Math.max(r,0),255):r;g=g?Math.min(Math.max(g,0),255):g;b=b?Math.min(Math.max(b,0),255):b;a=a?Math.min(Math.max(a,0),255):a;if(!r&&r!==0){console.error("ERROR: Color takes in at least one parameter.");return!1}
if(!g&&g!==0){return[r,r,r,255]}
if(!b&&b!==0){return[r,r,r,g]}
if(!a&&a!==0){return[r,g,b,255]}
return[r,g,b,a]};function palette(){let palette={};for(let i=0;i<arguments.length;i++){palette[i]=arguments[i]}
return palette};function map(){let map={value:[],width:0,height:0,};for(let i=0;i<arguments.length;i++){let segment;segment=arguments[i].split(",");if(!map.width){map.width=segment.length;map.height=arguments.length}
map.value=map.value.concat(segment)}
return map};function texture(name,map,palette){let texture={map:new Uint8ClampedArray(map.value.length*4),width:map.width,height:map.height,};for(let i=0;i<map.value.length;i++){if(!palette[+map.value[i]]){for(let j=0;j<4;j++){if(j===3){texture.map[i*4+j]=255;break}
texture.map[i*4+j]=0}
continue}
for(let j=0;j<4;j++){texture.map[i*4+j]=palette[+map.value[i]][j]}}
TEXTURES[name]=texture;return texture}