Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { margin: 0; }
JavaScript
// using THREE.js, see cog icon on Codepen to see it added // most of this code is taken from // https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene // full screen scene const scene = new THREE.Scene() const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ) // render to HTML const renderer = new THREE.WebGLRenderer() renderer.setSize( window.innerWidth, window.innerHeight ) document.body.appendChild( renderer.domElement ) // make a 1x1x1 with 32 parts per face const geometry = new THREE.BoxGeometry(1, 1, 1, 32, 32, 32) // make a clock to add animation const clock = new THREE.Clock() // pass info to the shader const uniforms = { time: { value: clock.getElapsedTime() } } // this is the thing that changes the position of the shape const vert = ` // pass info about each edge to the frag shader varying vec2 v_uv; // get from uniforms uniform float time; // this is from https://github.com/dmnsgn/glsl-rotate/blob/master/rotation-3d-y.glsl mat3 rotation3dY(float angle) { float s = sin(angle); float c = cos(angle); return mat3( c, 0.0, -s, 0.0, 1.0, 0.0, s, 0.0, c ); } void main () { // overwrite the box position vec3 new_position = position.xyz; // rotate with a sine wave new_position *= rotation3dY( 3.141 / 2.0 * sin(position.y + time) ); // from https://threejs.org/docs/index.html?q=webgl#api/en/renderers/webgl/WebGLProgram gl_Position = projectionMatrix * modelViewMatrix * vec4(new_position, 1.0); // pass face info to the frag shader, "uv" is given to use by Three.js v_uv = uv; } ` // what color are the faces const frag = ` varying vec2 v_uv; uniform float time; void main () { vec2 uv = v_uv; // RGBA color, based on each face with blue channel having a sine wave gl_FragColor = vec4(uv.x, uv.y, 0.5 + 0.5 * sin(time), 1.0); } ` // make a shader material! const material = new THREE.ShaderMaterial({ uniforms: uniforms, vertexShader: vert, fragmentShader: frag }) const cube = new THREE.Mesh( geometry, material ) scene.add( cube ) camera.position.z = 2 function animate() { cube.rotation.x += 0.002 cube.rotation.y += 0.002 cube.rotation.z += 0.002 uniforms.time.value = clock.getElapsedTime() requestAnimationFrame( animate ) renderer.render( scene, camera ) } animate()
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>three立方体运动-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号