three实现三维螺旋动画效果代码
代码语言:html
所属分类:动画
代码描述:three实现三维螺旋动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap"); * { margin: 0; padding: 0; box-sizing: border-box; } html, body { overscroll-behavior-x: none; overscroll-behavior-y: none; } body { background: mediumaquamarine; color: #fff; position: relative; font-family: "Spectral", serif; font-size: 20px; overflow: hidden; } #canvas { width: 100vw; height: 100vh; } canvas { z-index: 0; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; } </style> </head> <body > <!-- using three.js --> <canvas id="canvas"></canvas> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.145.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.145.js"></script> <script > window.onload = function () { "use strict"; //////// three.js const canvas = document.getElementById("canvas"); let camera, scene, renderer, controls; let geometry, material, mesh; let ww, hh; let timeoutID = 0; const size = 3; const color = new THREE.Color("#FF7F50"); init(); animate(); function init() { ww = window.innerWidth; hh = window.innerHeight; //ww = document.body.clientWidth / 2 / window.devicePixelRatio; //hh = window.innerHeight; //hh = document.body.cliantHeight/window.devicePixelRatio; scene = new THREE.Scene(); renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true, alpha: true }); renderer.setPixelRatio(window.devicePixelRatio); //renderer.setSize(ww, hh); renderer.setSize(ww, hh, false); renderer.outputEncoding = THREE.sRGBEncoding; // camera = new THREE.PerspectiveCamera(40, ww / hh, 0.01, size * 30); //camera.position.set(0, size, size * 6); camera.position.set(0, -size * 5, 0); camera.lookAt(0, 0, 0); // AmbientLight const light = new THREE.AmbientLight(0xffffff, 0.5); scene.add(light); // DirectionalLight const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); directionalLight.position.set(0, size * 6, size * 5); scene.add(directionalLight); // Geometry geometry = new THREE.TorusKnotGeometry(size, size / 3, 100, 16); let material = new THREE.MeshStandardMaterial({ color: color, roughness: 0 }); mesh = new THREE.Mesh(geometry, material); //scene.add(mesh); ////////////// const radius = 0.3; //radius const scale = 12; //spread ratio let coil_twist = 10; //twist num /* */ class CoilCurve extends THREE.Curve { constructor(scale = 1) { super(); this.scale = scale; } getPoint(t, optionalTarget = new THREE.Vector3()) { const angle = t * Math.PI * 2 * coil_twist; const x = Math.sin(angle) * (1 - t) * this.scale; const y = t * this.scale; const z = Math.c.........完整代码请登录后点击上方下载按钮下载查看
网友评论0