Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Canvas not supported.
Pattern
css
* { font-family: 'arial black', Helvetica, verdana, monospace, sans-serif; letter-spacing: 0.2rem; margin: 0; padding: 0; color: #FFF; overflow: hidden; } body { position: relative; } canvas#canvas { display: block; background: #000; } span#logo { display: inline-block; width: 1rem; height: 1rem; border-radius: 50%; background: #CC2F3B; margin-right: 0.4rem; } h1 { position: absolute; top: 1.6rem; left: 1.6rem; font-size: 1.6rem; } h2 { background: rgba(0, 0, 0, 0.7); position: absolute; top: 0; right: 1.6rem; height: 100%; text-align: center; font-size: 1rem; padding: 0.8rem; -webkit-writing-mode: vertical-rl; -ms-writing-mode: tb-rl; writing-mode: vertical-rl; }
JavaScript
(function () { 'use strict'; window.addEventListener('load', function () { var canvas = document.getElementById('canvas'); if (!canvas || !canvas.getContext) { return false; } /******************** Random Number ********************/ function rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } /******************** Change Title ********************/ var title = document.getElementById('title'); title.textContent = 'KIKKOUHANABISHI / ?甲花菱'; /******************** Var ********************/ var ctx = canvas.getContext('2d'); var X = canvas.width = window.innerWidth; var Y = canvas.height = window.innerHeight; var mouseX = null; var mouseY = null; var shapeNum; var shapes = []; var height = 200; var dist = Math.cos(30 * Math.PI / 180) * height; var rad = Math.PI * 2 / 6; var ease = 0.3; var friction = 0.9; var style = { black: 'black', white: 'white', lineWidth: 5, }; X > Y ? shapeNum = X / dist : shapeNum = Y / (height / 2 + height / 4); /******************** Animation ********************/ window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function(cb) { setTimeout(cb, 17); }; /******************** Shape ********************/ function Shape(ctx, x, y, i, j) { this.ctx = ctx; this.init(x, y, i, j); } Shape.prototype.init = function(x, y, i, j) { this.x = x; this.y = y; this.i = i; this.j = j; this.xi = rand(0, X); this.yi = rand(0, Y); this.r = height / 2; this.dia = Math.sqrt(this.r * this.r + this.r * this.r); this.v = { x: 0, y: 0 }; this.a = 0; this.rad = this.a * Math.PI / 180; }; Shape.prototype.draw = function() { var ctx = this.ctx; ctx.save(); ctx.strokeStyle = style.white; ctx.lineWidth = style.lineWidth; ctx.beginPath(); for (var i = 0; i < 6; i++) { var x = Math.sin(i * rad); var y = Math.cos(i * rad); if (i === 0) ctx.moveTo(x * this.r + this.xi, y * this.r + this.yi); ctx.lineTo(x * this.r + this.xi, y * this.r + this.yi); } ctx.closePath(); ctx.stroke(); ctx.lineWidth = style.lineWidth / 2; ctx.beginPath(); for (var i = 0; i < 6; i++) { var x = Math.sin(i * rad); var y = Math.cos(i * rad); if (i === 0) ctx.moveTo(x * this.r / 1.5 + this.xi, y * this.r / 1.5 + this.yi); ctx.lineTo(x * this.r / 1.5 + this.xi, y * this.r / 1.5 + this.yi); } ctx.closePath(); ctx.stroke(); ctx.translate(this.xi, this.yi); ctx.rotate(Math.tan(this.rad)); ctx.translate(-this.xi, -this.yi); ctx.lineWidth = 0; ctx.fillStyle = style.white; for (var i = 0; i < 4; i++) { ctx.translate(this.xi, this.yi); ctx.rotate(90 * Math.PI / 180); ctx.translate(-this.xi, -this.yi); ctx.beginPath(); ctx.moveTo(this.xi, this.yi); ctx.quadraticCurveTo(this.xi - this.r / 4, this.yi - this.r / 4, this.xi, this.yi - this.r / 2); ctx.quadraticCurveTo(this.xi + this.r / 4, this.yi - this.r / 4, this.xi, this.yi); ctx.closePath(); ctx.fill(); } ctx.fillStyle = style.black; for (var i = 0; i < 4; i++) { ctx.translate(this.xi, this.yi); ctx.rotate(90 * Math.PI / 180); ctx.translate(-this.xi, -this.yi); ctx.beginPath(); ctx.moveTo(this.xi, this.yi); ctx.quadraticCurveTo(this.xi - this.r / 8, this.yi - this.r / 8, this.xi, this.yi - this.r / 3); ctx.quadraticCurveTo(this.xi + this.r / 8, this.yi - this.r / 8, this.xi, this.yi); ctx.closePath(); ctx.fill(); } ctx.beginPath(); ctx.fillStyle = style.white; ctx.arc(this.xi, this.yi, this.r / 20, 0, Math.PI * 2, false); ctx.fill(); ctx.restore(); }; Shape.prototype.updatePosition = function() { this.v.x += (this.xi - this.x) * ease; this.v.y += (this.yi - this.y) * ease; this.v.x *= friction; this.v.y *= friction; this.xi -= this.v.x / 100; this.yi -= this.v.y / 100; }; Shape.prototype.updateParams = function() { if (this.j % 2 === 0) { this.a += 1; } else { this.a -= 1; } this.rad = this.a * Math.PI / 180; }; Shape.prototype.render = function() { this.updateParams(); this.updatePosition(); this.draw(); }; for (var i = 0; i < shapeNum + 1; i++) { for (var j = 0; j < shapeNum + 1; j++) { if (X > Y) { if (j * dist - dist - dist > Y) break; } else { if (j * (height / 2 + height / 4) - (height / 2 + height / 4) > Y) break; } var s; if (j % 2 !== 0) { s = new Shape(ctx, dist * i + dist / 2, (height / 2 + height / 4) * j, i, j); } else { s = new Shape(ctx, dist * i, (height / 2 + height / 4) * j, i, j); } shapes.push(s); } } /******************** Render ********************/ function render() { ctx.clearRect(0, 0, X, Y); for (var i = 0; i < shapes.length; i++) { shapes[i].render(i); } requestAnimationFrame(render); } render(); /******************** Event ********************/ function onResize() { X = canvas.width = window.innerWidth; Y = canvas.height = window.innerHeight; X > Y ? shapeNum = X / dist : shapeNum = Y / (height / 2 + height / 4); shapes = []; for (var i = 0; i < shapeNum + 1; i++) { for (var j = 0; j < shapeNum + 1; j++) { if (X > Y) { if (j * dist - dist - dist > Y) break; } else { if (j * (height / 2 + height / 4) - (height / 2 + height / 4) > Y) break; } var s; if (j % 2 !== 0) { s = new Shape(ctx, dist * i + dist / 2, (height / 2 + height / 4) * j, i, j); } else { s = new Shape(ctx, dist * i, (height / 2 + height / 4) * j, i, j); } shapes.push(s); } } } window.addEventListener('resize', function() { onResize(); }); }); })();
粒子
时间
文字
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号