-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (169 loc) · 6.89 KB
/
index.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!-- Based on @mrdoob's "Procedural City" http://mrdoob.com/lab/javascript/webgl/city/01/ -->
<html>
<head>
<title>City of Washington Monuments</title>
<style>
body {
background-color: #000000;
font-family: Monospace;
cursor: url(cursor.png), auto;
margin: 0;
overflow: hidden;
}
#instructions {
position: absolute;
top: 15px;
width: 100%;
color: #BBBBFF;
text-align: center;
}
</style>
</head>
<body>
<script src="../../lib/three.min.js"></script>
<script src="../../lib/FirstPersonControls.js"></script>
<script>
var scene, camera, renderer;
var light, controls;
var lastTime;
init();
animate();
function inside(point, vs) {
// via http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
var x = point[0], y = point[1];
var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = vs[i][0], yi = vs[i][1];
var xj = vs[j][0], yj = vs[j][1];
if (((yi > y) != (yj > y)) && (x < (xj - xi)*(y - yi)/(yj - yi) + xi)) inside = !inside;
}
return inside;
};
function addObelisk(hue, sat, lts) {
var obeliskGeometry = new THREE.Geometry();
var height = 1; // the Washington Monument is 169.29 meters high
var pyramidBase = 0.9*height;
var pyramidHalfWidth = 0.03*height;
var bottomHalfWidth = 0.05*height;
// Define each vertex:
// The bottom plane:
obeliskGeometry.vertices.push(new THREE.Vector3( bottomHalfWidth, 0, bottomHalfWidth));
obeliskGeometry.vertices.push(new THREE.Vector3( bottomHalfWidth, 0, -bottomHalfWidth));
obeliskGeometry.vertices.push(new THREE.Vector3(-bottomHalfWidth, 0, -bottomHalfWidth));
obeliskGeometry.vertices.push(new THREE.Vector3(-bottomHalfWidth, 0, bottomHalfWidth));
// Base of the pyramid:
obeliskGeometry.vertices.push(new THREE.Vector3( pyramidHalfWidth, pyramidBase, pyramidHalfWidth));
obeliskGeometry.vertices.push(new THREE.Vector3( pyramidHalfWidth, pyramidBase, -pyramidHalfWidth));
obeliskGeometry.vertices.push(new THREE.Vector3(-pyramidHalfWidth, pyramidBase, -pyramidHalfWidth));
obeliskGeometry.vertices.push(new THREE.Vector3(-pyramidHalfWidth, pyramidBase, pyramidHalfWidth));
// The tippy-top:
obeliskGeometry.vertices.push(new THREE.Vector3(0, height, 0));
// Create the faces:
// Floor:
obeliskGeometry.faces.push(new THREE.Face3(0, 2, 1), new THREE.Face3(0, 3, 2));
// The four main sides (each side is two triangles):
obeliskGeometry.faces.push(new THREE.Face3(0, 1, 5), new THREE.Face3(0, 5, 4));
obeliskGeometry.faces.push(new THREE.Face3(1, 2, 6), new THREE.Face3(1, 6, 5));
obeliskGeometry.faces.push(new THREE.Face3(2, 3, 7), new THREE.Face3(2, 7, 6));
obeliskGeometry.faces.push(new THREE.Face3(3, 0, 4), new THREE.Face3(3, 4, 7));
// Four sides of the pyramid:
obeliskGeometry.faces.push(new THREE.Face3(4, 5, 8));
obeliskGeometry.faces.push(new THREE.Face3(6, 7, 8));
obeliskGeometry.faces.push(new THREE.Face3(5, 6, 8));
obeliskGeometry.faces.push(new THREE.Face3(7, 4, 8));
obeliskGeometry.computeFaceNormals(); // required when using MeshNormalMaterial
var c1 = new THREE.Color();
var c2 = new THREE.Color();
c1.setHSL(hue, sat, lts);
c2.setHSL(hue, sat, lts - 0.2);
for (var i = 0; i < obeliskGeometry.faces.length; i++) {
if (i % 4 < 2) {
obeliskGeometry.faces[i].color.set(c1);
}
else {
obeliskGeometry.faces[i].color.set(c2);
}
}
return obeliskGeometry;
}
function init() {
dc = [
// Potomac shore by Maryland, going downstream
[0.399,0],[0.388,0.450],[0.385,0.145],[0.364,0.182],[0.367,0.229],[0.397,0.288],[0.465,0.391],
// Roosevelt Island
[0.453,0.391],[0.431,0.370],[0.408,0.433],[0.414,0.453],[0.422,0.442],[0.452,0.404],[0.453,0.391],
// Back to the Potomac shore
[0.465,0.391],[0.467,0.413],[0.436,0.452],[0.427,0.488],
// The Tidal Basin
[0.433,0.456],[0.447,0.550],[0.442,0.534],[0.453,0.523],[0.463,0.533],[0.475,0.531],[0.483,0.541],
[0.474,0.556],[0.480,0.575],[0.472,0.580],[0.458,0.568],[0.447,0.570],[0.436,0.573],
// Hains Point
[0.432,0.632],[0.389,0.749],[0.459,0.681],[0.470,0.651],[0.470,0.603],[0.477,0.588],
// Southeast Waterfront
[0.489,0.604],[0.489,0.674],[0.429,0.744],
// Anacostia shore (north)
[0.537,0.742],[0.575,0.790],[0.683,0.820],[0.774,0.800],
// Anacostia shore (south)
[0.688,0.840],[0.562,0.809],[0.528,0.767],[0.467,0.779],[0.428,0.771],
// Potomac shore
[0.163,0.968],[0.156,0.980],[0.180,1.000],
// Maryland border
[1.000,1.000],[1.000,0]
];
renderer = new THREE.WebGLRenderer({antialias: true, alpha: false});
renderer.setClearColor(0x202040);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(40, window.innerWidth/window.innerHeight, 1, 3000);
camera.position.x = 100;
camera.position.y = 32;
controls = new THREE.FirstPersonControls(camera);
controls.movementSpeed = 25;
controls.lookSpeed = 0.05;
controls.lookVertical = true;
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x000000, 0.0015); // color, density
light = new THREE.HemisphereLight(0xffffff , 0xffffff, 1); // skyColorHex, groundColorHex, intensity
scene.add(light);
var plane = new THREE.Mesh(new THREE.PlaneGeometry(400, 400), new THREE.MeshBasicMaterial({color: 0x101020}));
plane.rotation.x = -Math.PI/2;
scene.add(plane);
var city = new THREE.Geometry();
for (var i = 0; i < 3200; i ++) {
if (i == 0) {var geometry = addObelisk(0, 0, 1);} // make this one white
else {var geometry = addObelisk(Math.random(), 1, 0.6);} // rainbow colors
var building = new THREE.Mesh(geometry);
do {
building.position.x = Math.random();
building.position.z = Math.random();
} while (!inside([building.position.x, building.position.z], dc))
if (i == 0) {
// put white obelisk in location of actual Washington Monument
building.position.x = 0.500;
building.position.z = 0.535
building.scale.x = building.scale.z = 64;
building.scale.y = 64;
}
else {
building.scale.x = building.scale.z = building.scale.y = Math.random()*Math.random()*Math.random()*Math.random()*45 + 15;
}
building.position.x = Math.floor(building.position.x*400 - 200);
building.position.z = Math.floor(building.position.z*400 - 200);
var geometry = building.geometry;
THREE.GeometryUtils.merge(city, building);
}
var mesh = new THREE.Mesh(city, new THREE.MeshLambertMaterial({vertexColors: THREE.VertexColors}));
scene.add(mesh);
lastTime = window.performance ? performance.now() : Date.now();
}
function animate() {
requestAnimationFrame(animate);
var time = (window.performance ? performance.now() : Date.now())/1000;
controls.update(time - lastTime);
renderer.render(scene, camera);
lastTime = time;
}
</script>
<div id=instructions >click and hold to move forward</div>
</body>
</html>