THREE.js代码备份——canvas_lines(随机点、画线)
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js canvas - lines - random</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background-color: #000000;
margin: 0px;
overflow: hidden;
} a {
color:#0078ff;
}
</style>
</head>
<body> <script src="../build/three.js"></script> <script src="js/renderers/Projector.js"></script>
<script src="js/renderers/CanvasRenderer.js"></script> <script> var mouseX = 0, mouseY = 0, windowHalfX = window.innerWidth / 2,
windowHalfY = window.innerHeight / 2, SEPARATION = 200,
AMOUNTX = 10,
AMOUNTY = 10, camera, scene, renderer; init();
animate(); function init() { var container, separation = 100, amountX = 50, amountY = 50,
particles, particle; container = document.createElement('div');
document.body.appendChild(container); camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 100; scene = new THREE.Scene(); renderer = new THREE.CanvasRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement ); // particles var PI2 = Math.PI * 2;
var material = new THREE.SpriteCanvasMaterial( { color: 0x99ff99, //点的颜色
program: function ( context ) { context.beginPath();
context.arc( 0, 0, 0.5, 0, PI2, true ); //x,y,半径,startAngle,endAngle,anticlockwise
context.fill(); } } ); var geometry = new THREE.Geometry(); for ( var i = 0; i < 100; i ++ ) { particle = new THREE.Sprite( material );
particle.position.x = Math.random()*2 - 1; //应该是在1-65535之间取值,再x2
particle.position.y = Math.random() *2 - 1;
particle.position.z = Math.random() *2 - 1;
particle.position.normalize();
particle.position.multiplyScalar( Math.random() * 10 + 450 );//在原有的基础上扩大这么多倍(10以内的随机数+450)
particle.scale.x = particle.scale.y = 10;
scene.add( particle ); geometry.vertices.push( particle.position ); } // lines var line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0xffffff, opacity: 0.5 } ) );//颜色,不透明度
scene.add( line ); document.addEventListener( 'mousemove', onDocumentMouseMove, false );
document.addEventListener( 'touchstart', onDocumentTouchStart, false ); //触屏设备
document.addEventListener( 'touchmove', onDocumentTouchMove, false ); // 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 onDocumentMouseMove(event) { mouseX = event.clientX - windowHalfX;
mouseY = event.clientY - windowHalfY; } function onDocumentTouchStart( event ) { if ( event.touches.length > 1 ) { event.preventDefault(); mouseX = event.touches[ 0 ].pageX - windowHalfX;
mouseY = event.touches[ 0 ].pageY - windowHalfY; } } function onDocumentTouchMove( event ) { if ( event.touches.length == 1 ) { event.preventDefault(); mouseX = event.touches[ 0 ].pageX - windowHalfX;
mouseY = event.touches[ 0 ].pageY - windowHalfY; } } // function animate() { requestAnimationFrame( animate ); render(); } function render() { camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY + 200 - camera.position.y ) * .05;
camera.lookAt( scene.position ); renderer.render( scene, camera ); } </script>
</body>
</html>
THREE.js代码备份——canvas_lines(随机点、画线)的更多相关文章
- THREE.js代码备份——canvas - lines - colors(希尔伯特曲线3D、用HSL设置线颜色)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - l ...
- THREE.js代码备份——线框cube、按键、鼠标控制
<!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - g ...
- THREE.js代码备份——webgl - scene animation(通过加载json文件来加载动画和模型)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - sc ...
- THREE.js代码备份——webgl - geometry - dynamic(模拟海浪,通过时间(毫秒)来控制平面点的运动模拟海浪,鼠标控制写在另外的js中)
HTML: <!DOCTYPE html> <html lang="en"> <head> <title>three.js webg ...
- THREE.js代码备份——canvas - geometry - earth(球体贴纹理)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - g ...
- THREE.js代码备份——webgl - custom attributes [lines](自定义字体显示、控制字图的各个属性)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - cu ...
- THREE.js代码备份——webgl - materials - cube refraction [balls](以上下左右前后6张图片构成立体场景、透明球体效果)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - ma ...
- THREE.js代码备份——canvas_ascii_effect(以AscII码显示图形)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js - ASCII Ef ...
- 代码备份 | 博客侧边栏公告(支持HTML代码)(支持JS代码)
博客侧边栏公告(支持HTML代码)(支持JS代码) <div id='btnList'> <a class="ivu-btn ivu-btn-primary" h ...
随机推荐
- OC和JS之间的交互
OC和JS之间的交互 目录 对OC和JS之间交互的理解 JS调用OC OC调用JS 对OC和JS之间交互的理解 JS调用OC JS文件 function sendCommand(cmd,param){ ...
- javascript 拷贝
拷贝简单分为浅拷贝与深度拷贝,即给定一个对象,生成一个相同的对象. 浅拷贝 function copy(source,destiny){ destiny = destiny || {}; if(typ ...
- Collections.sort(List<T> Comparator) 自定义排序
Collections.sort(basicinfoList, new Comparator<MlisBasicinfo>() { @Override public int compare ...
- VS2005 命令窗口的使用
转自:http://www.cnblogs.com/RobotH/archive/2008/05/29/1209856.html 命令”窗口用于直接在 Visual Studio 集成开发环境 (ID ...
- [JavaEE] Hibernate OGM
Hibernate Object/Grid Mapper (OGM)这个项目能够为NoSQL数据库提供Java Persistence(JPA)支持.它复用了Hibernate Core引擎将实体持久 ...
- 从源码的角度解析View的事件分发
有好多朋友问过我各种问题,比如:onTouch和onTouchEvent有什么区别,又该如何使用?为什么给ListView引入了一个滑动菜单的功能,ListView就不能滚动了?为什么图片轮播器里的图 ...
- Linux下VI的使用
vi使用手册 VI是unix上最常用的文本编辑工具,作为unix软件测试人员,有必要熟练掌握它.进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filena ...
- LearnMVC5-AddAModel
本人是MVC新手,将从微软官网学习MVC并将看过的英文文档翻译成中文,由于本人英文水平不好,有翻译不准确.错误的地方万望指出,我看到后将会在第一时间修改.另外也希望这一系列文章能为后来者起到引导作用. ...
- android注解[Jake Wharton Butter Knife]
Introduction Annotate fields with @InjectView and a view ID for Butter Knife to find and automatical ...
- SharePoint 2010 配置基于MemberShip的身份验证
场景:通常需要为sharepoint打通其他的系统整合到sharepoint认证,ad通常是为内部域用户,外网访问的可以使用membership来登录,那么这个既可以内部用户访问,外部用户也可以访问 ...