JavaScript
语言:
JaveScriptBabelCoffeeScript
确定
var canvas = document.createElement("canvas"),
c = canvas.getContext("2d");
var w = canvas.width = window.innerWidth,
h = canvas.height = window.innerHeight;
c.fillStyle = "rgb(10,10,10)";
c.fillRect(0, 0, w, h);
document.body.appendChild(canvas);
var x = w / 2,
y = h / 2,
vel = 0,
vel1 = 0,
size = 50,
grow = 0,
a1 = 20,
b1 = 100,
c1 = 0.1,
d1 = 15;
function drawParticle() {
for (i = 0; i < 100; i++) {
c.beginPath();
c.fillStyle = "white";
c.strokeStyle = "rgb(255,200,200)";
c.lineWidth = "0.5";
x += a1 * Math.sin(b1 * vel) + c1 * vel * Math.cos(d1 * vel);
y += a1 * Math.cos(b1 * vel) - c1 * vel * Math.sin(d1 * vel);
var dist = Math.sqrt((x - w / 2) * (x - w / 2) + (y - h / 2) * (y - h / 2));
vel += 0.26;
c.arc(x, y, Math.abs(20 * Math.sin(dist / 20)), 0, 2 * Math.PI);
c.stroke();
}
}
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
function loop() {
c.fillStyle = "rgba(0,0,0,0)";
c.fillRect(0, 0, w, h);
window.requestAnimFrame(loop);
drawParticle();
}
loop();