1 Star 0 Fork 0

Changkey/Snowfall

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.html 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
Changkey 提交于 2017-11-09 15:02 . 新建 index.html
<!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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/changkey/snowfall.git
[email protected]:changkey/snowfall.git
changkey
snowfall
Snowfall
master

搜索帮助