Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body, html { margin: 0; } canvas { display: block; background-color: rgba(102,237,253,1.00); }
JavaScript
"use strict"; class Vector { constructor(x, y) { this.x = x; this.y = y; } add(v) { return new Vector( this.x + v.x, this.y + v.y); } addTo(v) { this.x += v.x; this.y += v.y; } sub(v) { return new Vector( this.x - v.x, this.y - v.y); } subFrom(v) { this.x -= v.x; this.y -= v.y; } mult(n) { return new Vector(this.x * n, this.y * n); } multTo(n) { this.x *= n; this.y *= n; return this; } div(n) { return new Vector(this.x / n, this.y / n); } setAngle(angle) { var length = this.getLength(); this.x = Math.cos(angle) * length; this.y = Math.sin(angle) * length; } setLength(length) { var angle = this.getAngle(); this.x = Math.cos(angle) * length; this.y = Math.sin(angle) * length; } getAngle() { return Math.atan2(this.y, this.x); } getLength() { return Math.sqrt(this.x * this.x + this.y * this.y); } getLengthSq() { return this.x * this.x + this.y * this.y; } distanceTo(v) { return this.sub(v).getLength(); } copy() { return new Vector(this.x, this.y); } equals(v) { return this.x == v.x && this.y == v.y; } } let canvas; let ctx; let w, h; let size; let circles; class Circle { constructor(r) { this.r = r; let nrOfPoints = 24; this.points = []; for (let circlePoint = 0; circlePoint < nrOfPoints; circlePoint++) { let angle = Math.PI * 2 / nrOfPoints * circlePoint; let x = Math.cos(angle) * r; let y = Math.sin(angle) * r; this.points.push(new Vector(x, y)); } } move() { let deltaAngle = 0.05 * this.r / size; this.points.forEach(p => { let x2 = Math.cos(deltaAngle) * p.x - Math.sin(deltaAngle) * p.y; let y2 = Math.sin(deltaAngle) * p.x + Math.cos(deltaAngle) * p.y; p.x = x2; p.y = y2; }); }} class Circles { constructor(nrOfCircles) { this.init(nrOfCircles); } init(nrOfCircles) { this.circles = new Array(nrOfCircles); let s = size / nrOfCircles * 0.45; for (let i = 0; i < nrOfCircles; i++) { let r = i * s + s; this.circles[i] = new Circle(r); } } move() { this.circles.forEach(c => c.move()); } draw() { for (let circle = 0; circle < this.circles.length - 1; circle++) { let nrOfPoints = Math.min(this.circles[circle].points.length, this.circles[circle + 1].points.length); for (let i = 0; i < nrOfPoints; i++) { ctx.beginPath(); ctx.moveTo(this.circles[circle].points[i].x, this.circles[circle].points[i].y); ctx.lineTo(this.circles[circle + 1].points[i].x, this.circles[circle + 1].points[i].y); ctx.stroke(); ctx.beginPath(); ctx.arc(this.circles[circle].points[i].x, this.circles[circle].points[i].y, 3, 0, Math.PI * 2); ctx.fill(); ctx.beginPath(); ctx.arc(this.circles[circle + 1].points[i].x, this.circles[circle + 1].points[i].y, 3, 0, Math.PI * 2); ctx.fill(); } } }} function setup() { canvas = document.querySelector("#canvas"); ctx = canvas.getContext("2d"); reset(); window.addEventListener("resize", reset); } function reset() { w = canvas.width = window.innerWidth; h = canvas.height = window.innerHeight; size = Math.min(w, h); ctx.translate(w / 2, h / 2); setupCircles(); } function setupCircles() { circles = new Circles(5); } function draw() { requestAnimationFrame(draw); ctx.clearRect(-w / 2, -h / 2, w, h); circles.draw(); circles.move(); } setup(); draw();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas线条旋转动画-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号