python漂亮的螺旋_CANVAS 各种螺旋画出来的漂亮图案

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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值