1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
<html>
<head>
<title>L-Systems.JS Playground</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://mrdoob.github.com/three.js/build/Three.js"></script>
<script src="bootstrap.min.js"></script>
<script src="lsys.js"></script>
<link rel="stylesheet" href="bootstrap.css" type="text/css"/>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div class="page">
<div class="container">
<div class="hero-unit">
<h1>L-Systems.JS</h1>
<p>Explore the power of L-Systems</p>
<p>
<a class="btn btn-large" href="http://github.com/yuvadm/lsys.js">L-Systems.JS on Github</a>
<a class="btn btn-primary btn-large" href="lsys.js">Download L-Systems.JS</a>
</p>
</div>
<div id="3dcontainer"></div>
</div>
</div>
<script>
var WIDTH = 800; //window.innerWidth;
var HEIGHT = 600; //window.innerHeight;
var container;
var scene, camera, renderer;
var mouseX = 0, mouseY = 0;
var windowHalfX = WIDTH / 2;
var windowHalfY = HEIGHT / 2;
init();
draw_axes();
draw_cube();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(20, WIDTH / HEIGHT, 1, 10000);
camera.position.z = 180;
scene.add(camera);
light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 0, 1 );
scene.add(light);
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize(WIDTH, HEIGHT);
container = document.getElementById('3dcontainer');
container.appendChild(renderer.domElement);
document.addEventListener('mousemove', onDocumentMouseMove, false);
}
function onDocumentMouseMove( event ) {
mouseX = (event.clientX - windowHalfX);
mouseY = (event.clientY - windowHalfY);
}
function draw_axes() {
var home = new THREE.Vector3(0,0,0);
var x_axis = [home, new THREE.Vector3(150,0,0)];
var y_axis = [home, new THREE.Vector3(0,150,0)];
var z_axis = [home, new THREE.Vector3(0,0,150)];
var axis_geometry = [
new THREE.Geometry(),
new THREE.Geometry(),
new THREE.Geometry()
];
axis_geometry[0] = new THREE.Shape(x_axis).createPointsGeometry();
axis_geometry[1] = new THREE.Shape(y_axis).createPointsGeometry();
axis_geometry[2] = new THREE.Shape(z_axis).createPointsGeometry();
var axis_material = [
new THREE.LineBasicMaterial({ color : 0xff0000 }),
new THREE.LineBasicMaterial({ color : 0x00ff00 }),
new THREE.LineBasicMaterial({ color : 0x0000ff })
];
var axis_line = [
new THREE.Line(axis_geometry[0], axis_material[0]),
new THREE.Line(axis_geometry[1], axis_material[1]),
new THREE.Line(axis_geometry[2], axis_material[2])
];
scene.add(axis_line[0]);
scene.add(axis_line[1]);
scene.add(axis_line[2]);
}
function draw_cube() {
var materials = [];
for (var i=0; i<6; i++) {
materials.push(new THREE.MeshBasicMaterial({
color : Math.random() * 0xffffff
}));
}
var cube = new THREE.Mesh(new THREE.CubeGeometry(5, 5, 5, 1, 1, 1, materials), new THREE.MeshFaceMaterial());
cube.position.x = 2.5;
cube.position.y = 2.5;
cube.position.z = 2.5;
scene.add(cube);
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
camera.position.x += (mouseX - camera.position.x) * 0.05;
camera.position.y += (-mouseY - camera.position.y) * 0.05;
camera.lookAt(scene.position);
renderer.render(scene, camera);
}
</script>
</body>
</html>
|