three.js实现雨下小站

2023-12-31 04:59
文章标签 实现 js three 小站 雨下

本文主要是介绍three.js实现雨下小站,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

无图不欢,先上静态图
在这里插入图片描述
图片资源下载

<!DOCTYPE html>
<html>
<head><meta name="keywords" content="风舞红枫,前端技术,canvas"/><meta name="description" content="风舞红枫,前端技术,canvas,vue,react,node,个人博客"/><title>three.js演示</title><script type="text/javascript" src="three.js"></script><script type="text/javascript" src="OrbitControls.js"></script><style type="text/css">*{margin:0;padding:0;}canvas{display:block;}</style>
</head>
<body><div id="fwhf"></div><script type="text/javascript">window.onload = function(){class FwhfYZH{constructor(){this.init();	}init(){// 创建一个渲染器this.renderer = new THREE.WebGLRenderer({antialias: true});this.renderer.setSize(window.innerWidth,window.innerHeight);this.renderer.setClearColor('#222',1);document.getElementById("fwhf").append(this.renderer.domElement);//创建一个场景this.scene=new THREE.Scene();//创建一个相机this.camera=new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,0.1,1000);this.camera.position.x=80;this.camera.position.y=80;this.camera.position.z=120;this.camera.lookAt(this.scene.position);// this.help();this.umbrella(12);this.chair();this.advertisement();this.plane();this.rain();this.start();}help(){//三维辅助线var axes=new THREE.AxesHelper(40);this.scene.add(axes);}plane(){//平面var geometry = new THREE.PlaneGeometry( 80, 200, 20, 50 );var texture = new THREE.TextureLoader().load( "512-256.png" );var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var plane = new THREE.Mesh( geometry, material );plane.rotation.x = -Math.PI/2;this.scene.add( plane );}rain(){//雨this.rainArr = [];this.line = [];for(var i = 0 ; i < 160 ; i++){this.rainArr[i] = [this.rand(-40,40),this.rand(2,100),this.rand(-100,100)];}this.rainArr.forEach((item,index)=>{var geometry = new THREE.Geometry();var material = new THREE.LineBasicMaterial({vertexColors:true,linecap:'round'});var color1=new THREE.Color("rgba(166,166,166)");var color2=new THREE.Color("rgba(222,222,222)");var p1=new THREE.Vector3(item[0],item[1],item[2]);var p2=new THREE.Vector3(item[0],item[1]-1,item[2]);geometry.vertices.push(p1);geometry.vertices.push(p2);geometry.colors.push(color1,color2);this.line[index]=new THREE.Line(geometry,material);this.scene.add(this.line[index]);})}rainUpdate(speed){this.line.forEach((item,index)=>{item.position.y -= speed;if(item.geometry.vertices[1].y+item.position.y <= 0){item.position.y = 100-item.geometry.vertices[1].y;item.position.x = this.rand(-40-item.geometry.vertices[1].x,40-item.geometry.vertices[1].x);item.position.z = this.rand(-100-item.geometry.vertices[1].z,100-item.geometry.vertices[1].z);}})}umbrella(copies){var geometry = new THREE.Geometry();geometry.vertices.push( new THREE.Vector3( 0,54,0 ) );for(var i = 0 ; i < copies ; i++){geometry.vertices.push(new THREE.Vector3(20*Math.sin(360/copies*i*Math.PI/180)-20*Math.cos(360/copies*i*Math.PI/180),40,20*Math.sin(360/copies*i*Math.PI/180)+20*Math.cos(360/copies*i*Math.PI/180)));}for(var i = 1 ; i <= copies ; i++){if(i == copies){geometry.faces.push( new THREE.Face3( 0, i, 1 ) );}else{geometry.faces.push( new THREE.Face3( 0, i, i+1 ) );}}geometry.computeBoundingSphere();var material = new THREE.MeshBasicMaterial({color:0xff6666,side:THREE.DoubleSide});var umbrellaGeometry = new THREE.Mesh(geometry,material);this.scene.add(umbrellaGeometry);for(var i = 1 ; i <= copies ; i++){var geometryLine = new THREE.Geometry();var material = new THREE.LineBasicMaterial({vertexColors:true,linecap:'round'});var color1=new THREE.Color("rgba(255,255,255)");var color2=new THREE.Color("rgba(222,222,222)");var p1=new THREE.Vector3(0,54,0);var p2=geometry.vertices[i];geometryLine.vertices.push(p1);geometryLine.vertices.push(p2);geometryLine.colors.push(color1,color2);var line=new THREE.Line(geometryLine,material);this.scene.add(line);}var geometry = new THREE.CylinderGeometry( 0.5, 0.5, 54, 54 );var material = new THREE.MeshBasicMaterial( {color:'#FAF9DE'} );var cylinder = new THREE.Mesh( geometry, material );cylinder.position.y += 27;this.scene.add( cylinder );var geometry2 = new THREE.CylinderGeometry( 1, 1, 4, 4 );var material2 = new THREE.MeshBasicMaterial( {color: '#FFF2E2'} );var cylinder2 = new THREE.Mesh( geometry2, material2 );cylinder2.position.y += 2;this.scene.add( cylinder2 );}chair(){var geometry = new THREE.BoxGeometry( 1, 4, 1 );var texture = new THREE.TextureLoader().load( "256-256.png" );var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 2;box.position.x += 8;box.position.z += 10;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 4, 1 );var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 2;box.position.x += 8;box.position.z -= 10;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 10, 21 );var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 5;box.position.x += 2;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 1, 21);var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 4;box.position.x += 4;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 1, 21);var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 4;box.position.x += 6;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 1, 21);var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 4;box.position.x += 8;this.scene.add( box );var geometry = new THREE.BoxGeometry( 6, 1, 1);var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 4;box.position.x += 5.5;box.position.z += 10;this.scene.add( box );var geometry = new THREE.BoxGeometry( 6, 1, 1);var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 4;box.position.x += 5.5;box.position.z -= 10;this.scene.add( box );}advertisement(){var geometry = new THREE.BoxGeometry( 1, 28, 1);var material = new THREE.MeshBasicMaterial( {color:'pink'} );var box = new THREE.Mesh( geometry, material );box.position.y += 14;box.position.x -= 4;box.position.z -= 20;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 28, 1);var material = new THREE.MeshBasicMaterial( {color:'pink'} );var box = new THREE.Mesh( geometry, material );box.position.y += 14;box.position.x -= 4;box.position.z += 20;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 1, 40);var material = new THREE.MeshBasicMaterial( {color:'pink'} );var box = new THREE.Mesh( geometry, material );box.position.y += 26.5;box.position.x -= 4;this.scene.add( box );var geometry = new THREE.BoxGeometry( 1, 1, 40);var material = new THREE.MeshBasicMaterial( {color:'pink'} );var box = new THREE.Mesh( geometry, material );box.position.y += 16.5;box.position.x -= 4;this.scene.add( box );var geometry = new THREE.BoxGeometry( 0.4, 10, 40);var texture = new THREE.TextureLoader().load( "url.jpg" );var material = new THREE.MeshBasicMaterial( {map:texture,transparent:true,side:THREE.DoubleSide} );var box = new THREE.Mesh( geometry, material );box.position.y += 21.5;box.position.x -= 4;this.scene.add( box );}start(){this.controls = new THREE.OrbitControls(this.camera);this.controls.addEventListener('mousemove', this.renderer);this.controls.update();this.animate();}animate(){requestAnimationFrame( this.animate.bind(this) );this.controls.update();this.rainUpdate(1);this.renderer.render( this.scene, this.camera );}rand(n,m){var c = m - n + 1;return Math.floor(Math.random() * c + n);}}new FwhfYZH();}</script>
</body>
</html>

这篇关于three.js实现雨下小站的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/555006

相关文章

Oracle查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI

Python脚本实现自动删除C盘临时文件夹

《Python脚本实现自动删除C盘临时文件夹》在日常使用电脑的过程中,临时文件夹往往会积累大量的无用数据,占用宝贵的磁盘空间,下面我们就来看看Python如何通过脚本实现自动删除C盘临时文件夹吧... 目录一、准备工作二、python脚本编写三、脚本解析四、运行脚本五、案例演示六、注意事项七、总结在日常使用

Java实现Excel与HTML互转

《Java实现Excel与HTML互转》Excel是一种电子表格格式,而HTM则是一种用于创建网页的标记语言,虽然两者在用途上存在差异,但有时我们需要将数据从一种格式转换为另一种格式,下面我们就来看看... Excel是一种电子表格格式,广泛用于数据处理和分析,而HTM则是一种用于创建网页的标记语言。虽然两

Java中Springboot集成Kafka实现消息发送和接收功能

《Java中Springboot集成Kafka实现消息发送和接收功能》Kafka是一个高吞吐量的分布式发布-订阅消息系统,主要用于处理大规模数据流,它由生产者、消费者、主题、分区和代理等组件构成,Ka... 目录一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者一、Kaf

使用Python实现在Word中添加或删除超链接

《使用Python实现在Word中添加或删除超链接》在Word文档中,超链接是一种将文本或图像连接到其他文档、网页或同一文档中不同部分的功能,本文将为大家介绍一下Python如何实现在Word中添加或... 在Word文档中,超链接是一种将文本或图像连接到其他文档、网页或同一文档中不同部分的功能。通过添加超

windos server2022里的DFS配置的实现

《windosserver2022里的DFS配置的实现》DFS是WindowsServer操作系统提供的一种功能,用于在多台服务器上集中管理共享文件夹和文件的分布式存储解决方案,本文就来介绍一下wi... 目录什么是DFS?优势:应用场景:DFS配置步骤什么是DFS?DFS指的是分布式文件系统(Distr

NFS实现多服务器文件的共享的方法步骤

《NFS实现多服务器文件的共享的方法步骤》NFS允许网络中的计算机之间共享资源,客户端可以透明地读写远端NFS服务器上的文件,本文就来介绍一下NFS实现多服务器文件的共享的方法步骤,感兴趣的可以了解一... 目录一、简介二、部署1、准备1、服务端和客户端:安装nfs-utils2、服务端:创建共享目录3、服

C#使用yield关键字实现提升迭代性能与效率

《C#使用yield关键字实现提升迭代性能与效率》yield关键字在C#中简化了数据迭代的方式,实现了按需生成数据,自动维护迭代状态,本文主要来聊聊如何使用yield关键字实现提升迭代性能与效率,感兴... 目录前言传统迭代和yield迭代方式对比yield延迟加载按需获取数据yield break显式示迭

Python实现高效地读写大型文件

《Python实现高效地读写大型文件》Python如何读写的是大型文件,有没有什么方法来提高效率呢,这篇文章就来和大家聊聊如何在Python中高效地读写大型文件,需要的可以了解下... 目录一、逐行读取大型文件二、分块读取大型文件三、使用 mmap 模块进行内存映射文件操作(适用于大文件)四、使用 pand

python实现pdf转word和excel的示例代码

《python实现pdf转word和excel的示例代码》本文主要介绍了python实现pdf转word和excel的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录一、引言二、python编程1,PDF转Word2,PDF转Excel三、前端页面效果展示总结一