用html做龙卷风特效,HTML5/Canvas 彩色龙卷风

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

window.requestAnimFrame = (function() {

return window.requestAnimationFrame ||

window.webkitRequestAnimationFrame ||

window.mozRequestAnimationFrame ||

window.oRequestAnimationFrame ||

window.msRequestAnimationFrame ||

function(callback) {

window.setTimeout(callback, 1000 / 60);

};

})();

var c = document.getElementById("canv");

c.width = window.innerWidth;

c.height = window.innerHeight;

var $ = c.getContext('2d');

run();

function run() {

window.requestAnimFrame(run);

draw();

};

var dx = 0,

dy = 0;

var circles = [];

var cols = ['hsla(169, 95%, 25%, 1)',

'hsla(109, 95%, 35%, 1)',

'hsla(59, 95%, 55%, 1)',

'hsla(34, 95%, 45%, 1)'

];

for (var i = 0; i <= 90; i++) {

var circle = {

t: Math.random() * 360,

dt: Math.random() * .2,

s: Math.random() * 10,

r: Math.ceil(Math.random() * 300),

dr: Math.ceil(Math.random() * 6),

c: cols[Math.floor(Math.random() * cols.length)]

};

circles.push(circle);

}

function draw() {

c.width = c.width;

for (var i in circles) {

var circle = circles[i];

circle.t += circle.dt;

circle.t %= 360;

dx = Math.sin(circle.t) * circle.s;

dy = Math.cos(circle.t) * circle.s;

$.globalAlpha = .6;

$.strokeStyle = circle.c;

$.beginPath();

for (var j = 0; j <= circle.dr; j++)

$.arc(c.width / 2 + dx, c.height / 2 + dy, circle.r + j, 0, 2 * Math.PI);

$.closePath();

$.stroke();

}

window.addEventListener('resize', function() {

c.width = w = window.innerWidth;

c.height = h = window.innerHeight;

c.style.position = 'absolute';

c.style.left = (window.innerWidth - w) *

.01 + 'px';

c.style.top = (window.innerHeight - h) *

.01 + 'px';

});

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值