Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { display: grid; place-content: center; overflow: hidden; margin: 0; min-height: 100vh; background: #333333; } canvas { max-width: 90vmin; max-height: 90vmin; border-radius: .5em; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); background: #222222; }
JavaScript
const _C = document.getElementById('c') /* canvas element */, C = _C.getContext('2d') /* 2L canvas context */, D = _C.width /* edge length of canvas square */, O = -.5*D /* top left corner coordinate */, N = 20 /* numbers of rows/ columns */, NP = N*N /* total number of polygons */, L = D/N /* edge length of a grid cell */, R = .375*L /* max circumradius of in-cell polygon */, THEME = ['#89c8d1', '#25a9c2', '#1076b6', '#344676', '#c5cdd8', '#d6549c', '#ebaa4e', '#e6e9f0'], NT = THEME.length, OPTS = ['fill', 'stroke'], NO = OPTS.length, POLY = [], FN = ['line', 'move']; function rand(max = 1, min = 0, dec = 0) { return +(min + (max - min)*Math.random()).toFixed(dec) }; class RandPoly { constructor(i, j) { this.i = i; this.j = j; /* coordinates of circumcircle centre */ this.ox = O + (j + .5)*L; this.oy = O + (i + .5)*L; this.n = 3; /* number of polygon vertices */ this.β = 2*Math.PI/this.n; /* base angle corresponding to an edge */ this.f = 3; /* frequency */ this.δ = Math.round(Math.atan2(this.oy, this.ox)*180/Math.PI + (1 - Math.hypot(this.ox, this.oy)/Math.abs(O))*900); /* initial angular offset of pulse */ this.m = 1; /* multiplier, dummy value for now */ this.vx = []; /* vertex coordinates relative to circumcircle centre */ this.b = 0; /* paint bucket index */ this.o = 0; /* option index (0: fill, 1: stroke) */ /* populate array of vertices */ for(let i = 0; i < this.n; i++) { /* angle current vertex is ast */ let γ = (i + .5*(1 - this.n%2))*this.β - .5*Math.PI; this.vx.push([R*Math.cos(γ), R*Math.sin(γ)]) } } get coords() { if((this.δ + 720)%360 < this.f) { /* polygon scaled to (almost) nothing */ /* reset these values */ this.δ = 0; this.b = (this.b + 1)%NT; this.o = 1 - this.o; this.n += 1; if(this.n > 8) this.n = 3 this.β = 2*Math.PI/this.n; this.vx = []; for(let i = 0; i < this.n; i++) { let γ = (i + .5*(1 - this.n%2))*this.β - .5*Math.PI; this.vx.push([R*Math.cos(γ), R*Math.sin(γ)]) } } this.δ -= this.f; /* update offset */ this.m = .5*(1 - Math.cos(this.δ*Math.PI/180)); /* compute multiplier */ /* compute and return absolute vertex coordinates */ return this.vx.map(c => [ +(this.ox + this.m*c[0]).toFixed(2), +(this.oy + this.m*c[1]).toFixed(2) ]) } }; function draw() { C.clearRect(O, O, D, D); /* clean canvas before drawing again */ for(let i = 0; i < NT; i++) { let b = POLY.filter(c => c.b === i); /* polygons in current bucket */ for(let j = 0; j < NO; j++) { let o = b.filter(c => c.o === j); /* polygons with current option */ C[`${OPTS[j]}Style`] = THEME[i]; /* set stroke or fill */ C.beginPath(); o.forEach(c => { let coords = c.coords; /* current poly absolute coordinate array */ for(let k = 0; k <= c.n; k++) C[`${FN[0**k]}To`](...coords[k%c.n]) }); C.closePath(); C[OPTS[j]](); } } requestAnimationFrame(draw) }; function init() { for(let i = 0; i < N; i++) { for(let j = 0; j < N; j++) { POLY.push(new RandPoly(i, j)); } } C.translate(-O, -O) draw() }; init();
粒子
时间
文字
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号