html5 漫画效果,HTML5 卡通动画里面常见的大爆炸动画特效

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

"use strict";

// @see: https://en.wikipedia.org/wiki/Superformula

var canvas = document.querySelector("canvas"),

context = canvas.getContext("2d");

var SCALE = 150;

var VALUES = [];

for (var index = 0; index < 30; index++) {

VALUES.push(Math.random() * 20000 + 100);

}

function superformula(phi, a, b, m, n1, n2, n3) {

return Math.pow(Math.pow(Math.abs(Math.cos(m * phi / 4) / a), n2) + Math.pow(Math.abs(Math.sin(m * phi / 4) / b), n3), -1 / n1);

}

function renderFormula(now, t1, t2, t3, i) {

var s1 = now / t1;

var s2 = now / t2;

var s3 = now / t3;

var a = Math.abs(Math.sin(s1));

var b = Math.abs(Math.sin(s1));

var m = Math.abs(Math.sin(s2) * 50);

var n1 = Math.abs(Math.sin(s3) * 50);

var n2 = Math.abs(Math.sin(s2) * 50);

var n3 = Math.abs(Math.sin(s1) * 50);

context.beginPath();

for (var index = 0; index < 360; index++) {

var radius = superformula(index / 360 * Math.PI * 2, a, b, m, n1, n2, n3);

var x = Math.cos(index / 360 * Math.PI * 2) * radius * SCALE;

var y = Math.sin(index / 360 * Math.PI * 2) * radius * SCALE;

if (index === 0) {

context.moveTo(x, y);

} else {

context.lineTo(x, y);

}

}

context.closePath();

context.globalCompositeOperation = "lighten";

context.shadowColor = "#0cf";

context.shadowBlur = 32;

context.lineWidth = i;

context.strokeStyle = "#fff";

context.stroke();

}

function update() {}

function render(now) {

var s1 = now / 1000;

var s2 = now / 250;

var s3 = now / 500;

var a = Math.abs(Math.sin(s1));

var b = Math.abs(Math.sin(s1));

var m = Math.abs(Math.sin(s2) * 50);

var n1 = Math.abs(Math.sin(s3) * 50);

var n2 = Math.abs(Math.sin(s2) * 50);

var n3 = Math.abs(Math.sin(s1) * 50);

context.clearRect(0, 0, canvas.width, canvas.height);

context.save();

context.translate(canvas.width * 0.5, canvas.height * 0.5);

for (var index = 0; index < VALUES.length; index += 3) {

renderFormula(now, VALUES[index], VALUES[index + 1], VALUES[index + 2], index + 1);

}

context.restore();

}

function frame(now) {

update();

render(now);

window.requestAnimationFrame(frame);

}

function resize() {

canvas.width = window.innerWidth;

canvas.height = window.innerHeight;

}

window.requestAnimationFrame(frame);

window.addEventListener("resize", resize);

window.dispatchEvent(new Event("resize"));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值