Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body, html { position: absolute; margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #fff; user-select: none; } canvas { position: absolute; width: 100%; height: 100%; user-select: none; touch-action: none; content-zooming: none; background: #fff; cursor: pointer; }
JavaScript
"use strict"; const transform = { m: [], minSize: 0.001, stack: [], calls: [], shapes: [], box: [], reset () { this.m = [1, 0, 0, 1, 0, 0]; this.box = [0, 0, 0, 0]; this.shapes.length = 0; this.calls.length = 0; return this; }, rotate (v) { const m = this.m; const rad = Math.PI * v / 180; const cos = Math.cos(rad); const sin = Math.sin(rad); const r00 = cos * m[0] + sin * m[2]; const r01 = cos * m[1] + sin * m[3]; m[2] = cos * m[2] - sin * m[0]; m[3] = cos * m[3] - sin * m[1]; m[0] = r00; m[1] = r01; return this; }, translate (x, y = 0) { const m = this.m; m[4] += x * m[0] + y * m[2]; m[5] += x * m[1] + y * m[3]; return this; }, scale (x = 1, y = x) { const m = this.m; m[0] *= x; m[1] *= x; m[2] *= y; m[3] *= y; return this; }, exec (fn) { this.calls.push([fn, this.m.slice()]); return this; }, save () { this.stack.push(this.m.slice()); return this; }, restore () { this.m = this.stack.pop(); return this; }, SQUARE () { this.boundingBox(); this.shapes.push(this.m.slice()); return this; }, tooSmall () { const m = this.m; const x = m[0] * m[0] + m[1] * m[1]; const y = m[2] * m[2] + m[3] * m[3]; return x < this.minSize || y < this.minSize; }, boundingBox () { const m = this.m; if (m[4] < this.box[0]) this.box[0] = m[4]; else if (m[4] > this.box[2]) this.box[2] = m[4]; if (m[5] < this.box[1]) this.box[1] = m[5]; else if (m[5] > this.box[3]) this.box[3] = m[5]; }, render (ctx, w, h, margin = 0.9) { do { const step = this.calls.shift(); this.m = step[1]; step[0](); } while (this.calls.length); const scale = Math.min( margin * w / (this.box[2] - this.box[0]), margin * h / (this.box[3] - this.box[1]) ); const ox = (this.box[0] + this.box[2]) * 0.5 * scale; const oy = (this.box[3] + this.box[1]) * 0.5 * scale; for (const m of this.shapes) { ctx.setTransform( m[0] * scale, m[1] * scale, m[2] * scale, m[3] * scale, m[4] * scale - ox + w * 0.5, m[5] * scale - oy + h * 0.5 ); ctx.fillRect(-0.5, -0.5, 1, 1); } } }; //////////////////////////////////////////////// const canvas = document.querySelector("canvas"); const ctx = canvas.getContext("2d"); const branch = () => { transform.exec(bit).translate(1, 0).scale(0.999) if (Math.random() < 0.5) { transform.rotate(-3).exec(left); } else { transform.rotate(3).exec(right); } }; const left = () => { if (Math.random() * 5 < 4) { transform.save().translate(1, 0).scale(0.999).rotate(3).exec(left).restore(); transform.exec(bit); } else { transform.exec(split); } }; const right = () => { if (Math.random() * 5 < 4) { transform.save().translate(1, 0).scale(0.999).rotate(-3).exec(right).restore(); transform.exec(bit); } else { transform.exec(split); } }; const split = () => { if (transform.tooSmall()) return; transform.save().translate(0.8, -0.5).scale(0.6).rotate(-30).exec(branch).restore(); transform.exec(bit); transform.save().translate(0.8, 0.5).scale(0.6).rotate(30).exec(branch).restore(); }; const pixel = (x, y) => transform.save().translate(x, y).scale(0.16).SQUARE().restore(); const bit = () => { if (Math.random() > 0.5) { pixel(0, 0.4); pixel(0, 0.4); pixel(0, 0.2); pixel(0, 0); pixel(0, -0.2); pixel(0, -0.4); pixel(-0.2, -0.2); } else { pixel(0.4, 0.2); pixel(0.4, 0); pixel(0.4, -0.2); pixel(-0.4, 0.2); pixel(-0.4, 0); pixel(-0.4, -0.2); pixel(0.2, 0.4); pixel(0, 0.4); pixel(-0.2, 0.4); pixel(0.2, -0.4); pixel(0, -0.4); pixel(-0.2, -0.4); } }; const start = () => { const width = (canvas.width = canvas.offsetWidth * 2); const height = (canvas.height = canvas.offsetHeight * 2); ctx.clearRect(0, 0, width, height); ctx.fillStyle = "#446"; transform.reset().rotate(-90).scale(2).exec(branch); transform.render(ctx, width, height, 0.98); }; window.addEventListener("resize", start, false); ["click", "touchdown"].forEach(event => { document.addEventListener(event, start, false); }); start();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>二叉树-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号