Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.comp.lang.javascript > #23

Something awesome

Newsgroups alt.comp.lang.javascript
Date 2020-12-21 10:08 -0800
Message-ID <d84dc652-3702-4da0-94ab-b3e2a0882afen@googlegroups.com> (permalink)
Subject Something awesome
From Robam Khrictjan <he12457@hotmail.com>

Show all headers | View raw


<html>
<body>
<canvas id="canvas" width="300" height="300"></canvas>

<script>
function precise(x) {
  return Number.parseFloat(x).toPrecision(2);
}
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var img = new Image();

img.src = "pict.jpeg"; 

var i=0;
var ii=precise(Math.random()*360);    
var count=0;
function draw() {
    if(count>10) {
       count=0;
       i=precise(Math.random()*360);    
       ii=precise(Math.random()*360);      
    }
    count++;
    var move=0;
    if(i>360) i=0;
    if(ii>360) ii=0;
    if(i<-361) i=0;
    if(ii<-361) ii=0;
    
    console.log(i+" "+ii);
    if(Math.abs(ii-i)<180) {
       i=i+1;
       move=1;
    } else if(Math.abs(ii-i)>180) {
       i=i-1;
       move=1;
    } else {
       ii=precise(Math.random()*360);    
    }
    if(move==1) {
      ctx.clearRect(0, 0, canvas.width*1.5, canvas.height*1.5);   
      ctx.save();
      ctx.translate(canvas.width/2,canvas.height/2);
      ctx.rotate(i*Math.PI/180);
      ctx.drawImage(img,-img.width/2,-img.width/2);
      ctx.restore();
    }
}

img.onload = function(){

   setInterval(function(){ draw(); }, 50);

}
</script>

</body>
</html>



K R

Back to alt.comp.lang.javascript | Previous | Next | Find similar


Thread

Something awesome Robam Khrictjan <he12457@hotmail.com> - 2020-12-21 10:08 -0800

csiph-web