代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="zh-Hans-cn">
<head>
<meta charset="UTF-8">
<title>WHITE ALBUM</title>
<style>
body {
background: #000000;
margin: 0;
}
canvas {
width: 100%;
height: 100%;
}
</style>
<script src="node_modules/three/build/three.min.js"></script>
</head>
<body>
<div id="snow"></div>
<script>
(() => {
'use strict'
let container
let camera, scene, renderer
init()
animate()
function init () {
const textureLoader = new THREE.TextureLoader()
const geometry = new THREE.Geometry()
const snow = textureLoader.load('snow.png')
const snowSizes = [5, 10]
camera = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 1, 3000)
scene = new THREE.Scene()
renderer = new THREE.WebGLRenderer()
container = document.getElementById('snow')
camera.position.z = 1000
for (let i = 0; i < 1000; i++) {
let vertex = new THREE.Vector3()
vertex.x = Math.random() * 2000 - 1000
vertex.y = Math.random() * 2000 - 1000
vertex.z = Math.random() * 2000 - 1000
geometry.vertices.push(vertex)
}
snowSizes.forEach((size, i) => {
scene.add(new THREE.Points(geometry, new THREE.PointsMaterial({
size,
map: snow,
blending: THREE.AdditiveBlending,
depthTest: false,
transparent: true
})))
})
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize(window.innerWidth, window.innerHeight)
container.appendChild(renderer.domElement)
window.addEventListener('resize', onWindowResize, false)
}
function onWindowResize () {
windowHalfX = window.innerWidth / 2
windowHalfY = window.innerHeight / 2
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
renderer.setSize(window.innerWidth, window.innerHeight)
}
function animate () {
requestAnimationFrame(animate)
render()
}
function render () {
let time = Date.now() * 0.00008
camera.position.y += camera.position.y * 0.5
camera.lookAt(scene.position)
for (let i = 0; i < scene.children.length; i++) {
scene.children[i].rotation.x = time
scene.children[i].rotation.y = time
}
renderer.render(scene, camera)
}
})()
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。