User Tools

Site Tools


programmering:farver2-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(color,color+20,color+50);
		    color=color+12;
		    ctx.fillRect(i,i,w-i*2,h-i*2);
		  } 
  }
  var h=window.innerHeight*0.9;
  var w=window.innerWidth*0.9;
  var color=0;
  document.getElementById("canvas1").width=w;
  document.getElementById("canvas1").height=h;

  var v=setInterval(draw,150);

</script>
programmering/farver2-js-code.txt · Last modified: 2023/10/21 19:19 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki