Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { margin: 0; padding: 0; } html, body { overflow: hidden; } body { position: relative; }
JavaScript
/* * Referenced / Generative Art - written by sir Matt Pearson. * File Name / fractal.js * Created Date / Aug 27, 2020 * Aurhor / Toshiya Marukubo * Twitter / https://twitter.com/toshiyamarukubo */ /* Common Tool. */ class Tool { // random number. static randomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } // random color rgb. static randomColorRGB() { return ( "rgb(" + this.randomNumber(0, 255) + ", " + this.randomNumber(0, 255) + ", " + this.randomNumber(0, 255) + ")" ); } // random color hsl. static randomColorHSL(hue, saturation, lightness) { return ( "hsl(" + hue + ", " + saturation + "%, " + lightness + "%)" ); } // gradient color. static gradientColor(ctx, cr, cg, cb, ca, x, y, r) { const col = cr + "," + cg + "," + cb; const g = ctx.createRadialGradient(x, y, 0, x, y, r); g.addColorStop(0, "rgba(" + col + ", " + (ca * 1) + ")"); g.addColorStop(0.5, "rgba(" + col + ", " + (ca * 0.5) + ")"); g.addColorStop(1, "rgba(" + col + ", " + (ca * 0) + ")"); return g; } } class Angle { constructor(angle) { this.a = angle; this.rad = this.a * Math.PI / 180; } incDec(num) { this.a += num; this.rad = this.a * Math.PI / 180; return this.rad; } } /* variable for canvas. */ let canvas; class Canvas { constructor(bool) { // create canvas. this.canvas = document.createElement("canvas"); // if on screen. if (bool === true) { this.canvas.style.position = 'relative'; this.canvas.style.display = 'block'; this.canvas.style.top = 0; this.canvas.style.left = 0; document.getElementsByTagName("body")[0].appendChild(this.canvas); } this.ctx = this.canvas.getContext("2d"); this.width = this.canvas.width = window.innerWidth; this.height = this.canvas.height = window.innerHeight; // mouse infomation. this.mouseX = null; this.mouseY = null; // sprite array and quantity. this.numChildren = 7; this.maxLevels = 5; this.trunk = []; } init() { this.trunk.push(new Branch(this.ctx, 1, 0, this.width / 2, this.height / 2)); } render() { //this.ctx.clearRect(0, 0, this.width, this.height); this.ctx.globalCompositeOperation = "darken"; this.ctx.globalAlpha = 0.1; this.ctx.fillStyle = "rgb(0,0,0)"; this.ctx.fillRect(0, 0, this.width, this.height); this.ctx.globalCompositeOperation = "source-over"; this.ctx.globalAlpha = 1; for (let i = 0; i < this.trunk.length; i++) { this.trunk[i].render(); } } resize() { this.trunk = []; this.width = this.canvas.width = window.innerWidth; this.height = this.canvas.height = window.innerHeight; this.numX = Math.floor(this.width / this.cellSize) + 2; this.numY = Math.floor(this.height / this.cellSize) + 2; this.init(); } } class Branch { constructor(ctx, lev, ind, ex, why) { this.ctx = ctx; this.level = lev; this.index = ind; this.x = ex; this.y = why; this.endX; this.endY; this.c = 'white'; this.a = new Angle(Tool.randomNumber(0, 360)); this.children = []; this.len = Tool.randomNumber(10, 100); if (this.level < canvas.maxLevels) { for (let i = 0; i < canvas.numChildren; i++) { this.children[i] = new Branch(this.ctx, this.level + 1, i, this.endX, this.endY); } } this.random = Tool.randomNumber(-1, 1) * Math.random(); } updateMe(ex, why) { this.x = ex; this.y = why; const rad = this.a.rad; this.endX = this.x + (this.len * Math.cos(rad)); this.endY = this.y + (this.len * Math.sin(rad)); for (let i = 0; i < this.children.length; i++) { this.children[i].updateMe(this.endX, this.endY); } this.a.incDec(this.random); } drawMe(ex, why) { if (this.level > 1) { const ctx = this.ctx; ctx.save(); ctx.lineWidth = 0.05; ctx.strokeStyle = this.c; ctx.beginPath(); ctx.moveTo(this.x, this.y); ctx.lineTo(this.endX, this.endY); ctx.stroke(); ctx.restore(); } for (let i = 0; i < this.children.length; i++) { this.children[i].drawMe(); } } render() { this.updateMe(canvas.width / 2, canvas.height / 2); this.drawMe(); } } (function () { "use strict"; window.addEventListener("load", function () { canvas = new Canvas(true); canvas.init(); function render() { window.requestAnimationFrame(function () { canvas.render(); render(); }); } render(); // event window.addEventListener("resize", function () { canvas.resize(); }, false); }); })();
粒子
时间
文字
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号