Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.comp.lang.javascript > #25
| Newsgroups | alt.comp.lang.javascript |
|---|---|
| Date | 2020-12-21 10:54 -0800 |
| Message-ID | <7b40f349-4f59-42df-b52b-1d07717a8781n@googlegroups.com> (permalink) |
| Subject | Interesting webpage background animation idea. |
| From | Robam Khrictjan <he12457@hotmail.com> |
<html>
<body style="background-color:black;">
<canvas id="canvas" width="600" height="600"></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=-360+2*precise(Math.random()*360);
ii-360+2*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;
if(ii-i<0) {
i=i+1-Math.round(Math.random()*2);
move=1;
} else if(ii-i>0) {
i=i+1-Math.round(Math.random()*2);
move=1;
} else {
i=-360+2*precise(Math.random()*360);
ii-360+2*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(); }, 1);
}
</script>
</body>
</html>
Kristjan Robam
Back to alt.comp.lang.javascript | Previous | Next | Find similar
Interesting webpage background animation idea. Robam Khrictjan <he12457@hotmail.com> - 2020-12-21 10:54 -0800
csiph-web