Skip to content

Instantly share code, notes, and snippets.

@diska
Created October 2, 2020 05:38
Show Gist options
  • Select an option

  • Save diska/3cc94448d63dbd343535cb703af0bc2c to your computer and use it in GitHub Desktop.

Select an option

Save diska/3cc94448d63dbd343535cb703af0bc2c to your computer and use it in GitHub Desktop.
WebGLでHELLOと表示するためなら手段を選ばないコード。
<canvas></canvas>
<script>
const hello=`
#...#.#####.#####.#####..###..
#...#.#.....#.....#.....#...#.
#####.####..#.....#.....#...#.
#...#.#.....#.....#.....#...#.
#...#.#####.#.....#......###..`;
let cx=document.querySelector("canvas").getContext("webgl");
cx.clearColor(0,0.3,0,1); cx.clear(0x4000);
cx.pixelStorei(cx.UNPACK_FLIP_Y_WEBGL,true);
cx.enable(cx.SCISSOR_TEST);
for(let i=0; i<31; i++)for(let j=0; j<8; j++){
if(hello.charAt(j*31+i)=="#"){
rect(i*4,j*4+8,6,4);
}
}
function rect(x,y, w=1, h=1){
cx.scissor(x,y, w,h); cx.clearColor(1,1,0,1); cx.clear(0x4000);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment