Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
JavaScript
/** *3D海洋效应与 Canvas2D * 您可以更改注释 "效果属性" 下的属性 */ // Init Context let c = document.createElement('canvas').getContext('2d') let postctx = document.body.appendChild(document.createElement('canvas')).getContext('2d') let canvas = c.canvas let vertices = [] // Effect Properties let vertexCount = 7000 let vertexSize = 3 let oceanWidth = 204 let oceanHeight = -80 let gridSize = 32; let waveSize = 16; let perspective = 100; // Common variables let depth = (vertexCount / oceanWidth * gridSize) let frame = 0 let { sin, cos, tan, PI } = Math // Render loop let loop = () => { let rad = sin(frame / 100) * PI / 20 let rad2 = sin(frame / 50) * PI / 10 frame++ if (postctx.canvas.width !== postctx.canvas.offsetWidth || postctx.canvas.height !== postctx.canvas.offsetHeight) { postctx.canvas.width = canvas.width = postctx.canvas.offsetWidth postctx.canvas.height = canvas.height = postctx.canvas.offsetHeight } c.fillStyle = `hsl(200deg, 100%, 2%)` c.fillRect(0, 0, canvas.width, canvas.height) c.save() c.translate(canvas.width / 2, canvas.height / 2) c.beginPath() vertices.forEach((vertex, i) => { let ni = i + oceanWidth let x = vertex[0] - frame % (gridSize * 2) let z = vertex[2] - frame * 2 % gridSize + (i % 2 === 0 ? gridSize / 2 : 0) let wave = (cos(frame / 45 + x / 50) - sin(frame / 20 + z / 50) + sin(frame / 30 + z*x / 10000)) let y = vertex[1] + wave * waveSize let a = Math.max(0, 1 - (Math.sqrt(x ** 2 + z ** 2)) / depth) let tx, ty, tz y -= oceanHeight // Transformation variables tx = x ty = y tz = z // Rotation Y tx = x * cos(rad) + z * sin(rad) tz = -x * sin(rad) + z * cos(rad) x = tx y = ty z = tz // Rotation Z tx = x * cos(rad) - y * sin(rad) ty = x * sin(rad) + y * cos(rad) x = tx; y = ty; z = tz; // Rotation X ty = y * cos(rad2) - z * sin(rad2) tz = y * sin(rad2) + z * cos(rad2) x = tx; y = ty; z = tz; x /= z / perspective y /= z / perspective if (a < 0.01) return if (z < 0) return c.globalAlpha = a c.fillStyle = `hsl(${180 + wave * 20}deg, 100%, 50%)` c.fillRect(x - a * vertexSize / 2, y - a * vertexSize / 2, a * vertexSize, a * vertexSize) c.globalAlpha = 1 }) c.restore() // Post-processing postctx.drawImage(canvas, 0, 0) postctx.globalCompositeOperation = "screen" postctx.filter = 'blur(16px)' postctx.drawImage(canvas, 0, 0) postctx.filter = 'blur(0)' postctx.globalCompositeOperation = "source-over" requestAnimationFrame(loop) } // Generating dots for (let i = 0; i < vertexCount; i++) { let x = i % oceanWidth let y = 0 let z = i / oceanWidth >> 0 let offset = oceanWidth / 2 vertices.push([(-offset + x) * gridSize, y * gridSize, z * gridSize]) } loop()
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>3D 粒子海洋-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号