programmering:farver1-js-code
<script> function RGB2Color(r,g,b) { return '#' + byte2Hex(r) + byte2Hex(g) + byte2Hex(b); } function byte2Hex(n) { var nybHexString="0123456789ABCDEF"; return String(nybHexString.substr((n>>4) & 0x0F,1))+ nybHexString.substr(n & 0x0F,1); } function rand(n) { return Math.floor((Math.random()*n)); } function draw() { var c=document.getElementById("canvas1"); var ctx=c.getContext("2d"); for (var i=0; i<h/2; i+=2) { ctx.fillStyle = RGB2Color(rand(256),rand(256),rand(256)); ctx.fillRect(i,i,w-i*2,h-i*2); } } var h=window.innerHeight*0.9; var w=window.innerWidth*0.9; document.getElementById("canvas1").width=w; document.getElementById("canvas1").height=h; var v=setInterval(draw,200); </script>
programmering/farver1-js-code.txt · Last modified: 2023/10/21 19:19 by 127.0.0.1