Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Followers!
css
html, body { height: 100%; } body { background-image: radial-gradient(ellipse at center, #2c0c00 8.0%, #000 100.0%); background-size: 160% 160%; background-position: 50% 50%; overflow: hidden; } h1 { position: relative; z-index: 1; color: rgb(255, 94, 30); font-family: 'Luckiest Guy', sans-serif; font-size: min(8vw, 64px); text-align: center; top: 65vh; } img { display: none; }
JavaScript
console.clear(); //////////// // CONFIG // //////////// // Affects number of cubes generated const DENSITY = 1; const LAYERS = 5; // Colors are in rgb format const COLORS = [ [1.000, 0.655, 0.231], [1.000, 0.365, 0.114], [0.898, 0.078, 0.392], [0.424, 0.5, 0.114] ]; const GAMMA = 1.8; const CLEAR_COLOR = [0, 0, 0, 0]; // Time in seconds for all cubes to wrap around once. const SCROLL_TIME = 10; // Radians per second const ROTATE_MIN = 0.5; const ROTATE_MAX = 4.2; // Meters const SIZE_MIN = 0.032; const SIZE_MAX = 0.064; // Randomize placement (meters) const OFFSET_JITTER = 0.025; // Camera controls const CAMERA_DISTANCE = 3.5; const CAMERA_FOV = 0.7; const CAMERA_NEAR = 1; const CAMERA_FAR = 100; //////////////////////// // COMPUTED CONSTANTS // //////////////////////// // Number of cubes on each axis const COUNT_X = Math.floor(32 * DENSITY); const COUNT_Y = Math.floor(16 * DENSITY); const COUNT_Z = Math.floor(LAYERS); const COUNT_TOTAL = COUNT_X * COUNT_Y * COUNT_Z; // Bounding volume dimensions (meters) const BOUND_WIDTH = 2; const BOUND_HEIGHT = COUNT_Y / COUNT_X * BOUND_WIDTH; const BOUND_DEPTH = COUNT_Z / COUNT_X * BOUND_WIDTH; ////////////////// // MATH HELPERS // ////////////////// const TAU = Math.PI * 2; const random = (min, max) => Math.random() * (max - min) + min; const interpolate = (a, b, mix) => (b - a) * mix + a; ///////////////// // APPLICATION // ///////////////// const regl = createREGL({ extensions: ['angle_instanced_arrays'] }); const textTexture = regl.texture({ format: 'rgb', data: document.querySelector('img'), mag: 'linear', min: 'linear' }); const viewMatrix = mat4.fromTranslation([], [0, 0.25, -CAMERA_DISTANCE]); const projectionMatrix = []; const projectionViewMatrix = []; // Gamma correct colors COLORS.forEach(c => { c[0] = Math.pow(c[0], GAMMA); c[1] = Math.pow(c[1], GAMMA); c[2] = Math.pow(c[2], GAMMA); }); // Color of each cube const colors = new Float32Array(3 * COUNT_TOTAL); // Position of each cube const offsets = new Float32Array(3 * COUNT_TOTAL); // Base scale of each cube const scales = new Float32Array(COUNT_TOTAL); // Axis of rotation for each cube const rotationAxes = new Float32Array(3 * COUNT_TOTAL); // Rotation angle for each cube const angles = new Float32Array(COUNT_TOTAL); // Rotation speed for each cube (radians/s) const rotationSpeeds = new Float32Array(COUNT_TOTAL); // `angleBuffer` will be updated each frame, to animate rotations const angleBuffer = regl.buffer({ data: angles, type: 'float', usage: 'dynamic' }); // Generate all data. // Some buffers have a stride of 1, others have a stride of 3. let i = 0; let i3 = 0; for (let x=0; x
{ return time % SCROLL_TIME / SCROLL_TIME * BOUND_WIDTH; }, u_projectionViewMatrix: ({ viewportWidth, viewportHeight }) => { const aspectRatio = viewportWidth / viewportHeight; let finalFovY = CAMERA_FOV; // On narrow screens, widen FOV (zoom out) if (aspectRatio < 1) { finalFovY = interpolate(CAMERA_FOV / aspectRatio, CAMERA_FOV, 0.5); // Prevent FOV from getting too wide and approaching 180 degrees finalFovY = Math.min(finalFovY, 0.8*Math.PI); } mat4.perspective(projectionMatrix, finalFovY, aspectRatio, CAMERA_NEAR, CAMERA_FAR); mat4.multiply(projectionViewMatrix, projectionMatrix, viewMatrix); return projectionViewMatrix; } }, count: 36, instances: COUNT_TOTAL }); // Animation loop let lastTime = -1; regl.frame(({ time }) => { const timeDelta = lastTime === -1 ? 0 : time - lastTime; lastTime = time; regl.clear({ color: CLEAR_COLOR }); for (let i=0; i
TAU) { angle -= TAU; } angles[i] = angle; } angleBuffer.subdata(angles); draw(); }); ////////////////// // DATA HELPERS // ////////////////// function getCubeVertices() { const ltf = [-1, 1, 1]; const ltb = [-1, 1, -1]; const lbf = [-1, -1, 1]; const lbb = [-1, -1, -1]; const rtf = [1, 1, 1]; const rtb = [1, 1, -1]; const rbf = [1, -1, 1]; const rbb = [1, -1, -1]; return [ // top ltf, ltb, rtb, rtb, rtf, ltf, // bottom lbb, lbf, rbf, rbf, rbb, lbb, // left ltb, ltf, lbb, lbb, ltf, lbf, // right rbf, rtf, rtb, rtb, rbb, rbf, // front lbf, ltf, rtf, rtf, rbf, lbf, // back rtb, ltb, lbb, lbb, rbb, rtb ]; } function getCubeNormals() { const up = [0, 1, 0]; const down = [0, -1, 0]; const left = [-1, 0, 0]; const right = [1, 0, 0]; const front = [0, 0, 1]; const back = [0, 0, -1]; return [ // top up, up, up, up, up, up, // bottom down, down, down, down, down, down, // left left, left, left, left, left, left, // right right, right, right, right, right, right, // front front, front, front, front, front, front, // back back, back, back, back, back, back ]; }
粒子
时间
文字
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号