-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalbum.html
More file actions
144 lines (123 loc) · 5.3 KB
/
Copy pathalbum.html
File metadata and controls
144 lines (123 loc) · 5.3 KB
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
<html>
<head>
<meta charset='UTF-8'>
<style>
body {
overflow: hidden;
background-color: black;
color: white;
}
</style>
<script src="Three.min.js"></script>
<script src="stats.min.js"></script>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var mouseX = 0;
var mouseY = 0;
var scene;
var camera;
var stats;
var renderer;
var group;
var particle = [];
var url = [
'http://t2.baidu.com/it/u=2150538223,2127700832&fm=24&gp=0.jpg',
'http://t3.baidu.com/it/u=142795994,1996417330&fm=24&gp=0.jpg',
'http://t2.baidu.com/it/u=1982084051,1045668245&fm=24&gp=0.jpg',
'http://t1.baidu.com/it/u=1727521039,3859806791&fm=24&gp=0.jpg',
'http://t3.baidu.com/it/u=2448520404,1597185114&fm=24&gp=0.jpg',
'http://t1.baidu.com/it/u=575573417,2421018184&fm=24&gp=0.jpg',
'http://t3.baidu.com/it/u=2730298047,1503171658&fm=24&gp=0.jpg',
//'http://t3.baidu.com/it/u=492168775,1982551871&fm=24&gp=0.jpg',
//'http://t1.baidu.com/it/u=2232737286,3428187892&fm=24&gp=0.jpg',
'http://t3.baidu.com/it/u=2346644131,1897731929&fm=24&gp=0.jpg'
];
function onload() {
init();
animate();
}
function program(i) {
var len = url.length;
if ( !len ) return;
var src = url[i % len];
return function(context){
var image = new Image();
image.src = src;
var imageWidth = 150;
var imageHeight = 150 / image.width * image.height;
context.rotate(Math.PI);
context.drawImage(image, 50, 50, imageWidth, imageHeight);
}
}
function addParticle() {
for ( var i = 0; i < 100 ; i ++ ) {
particle[i] = new THREE.Particle(new THREE.ParticleCanvasMaterial({
color : Math.random() * 0x808080 + 0x808080,
program : program(i)
}))
particle[i].position.x = Math.random() * 2000 - 1000;
particle[i].position.y = Math.random() * 2000 - 1000;
particle[i].position.z = Math.random() * 2000 - 1000;
particle[i].scale.x = particle[i].scale.y = Math.random() + 1;
group.add(particle[i]);console.log(particle[i].position)
}
}
function removeParticle() {
for ( var i = 0; i < 100 ; i ++ ) {
group.remove(particle[i]);
}
}
function init() {
camera = new THREE.PerspectiveCamera(90, width / height, 5, 5000);
camera.position.z = 100;
scene = new THREE.Scene();
group = new THREE.Object3D();
scene.add(group);
addParticle();
document.onmousemove = mouseMove;
document.getElementById('btn').onclick = addPhoto;
renderer = new THREE.CanvasRenderer();
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = 0;
stats.domElement.style.right = 0;
document.body.appendChild(stats.domElement);
}
function animate() {
requestAnimationFrame(animate);
render();
stats.update();
}
function mouseMove(e) {
mouseX = e.clientX - width / 2;
mouseY = e.clientY - height / 2;
}
function addPhoto() {
if (url[0] == 'http://t2.baidu.com/it/u=2150538223,2127700832&fm=24&gp=0.jpg'){
url = [];
}
url.push(document.getElementById('url').value);
removeParticle();
addParticle();
}
function render() {
camera.position.x += (mouseX - camera.position.x) * 0.01;
camera.position.y += (mouseY - camera.position.y) * 0.01;
camera.lookAt( scene.position );
group.rotation.x += 0.001;
group.rotation.y += 0.001;
renderer.render(scene, camera);
}
</script>
</head>
<body onload="onload()">
<div>
<span>添加照片url</span>
<input type="url" id='url' style="width:600px"/>
<input type="button" id='btn' value='添加'/>
</div>
</body>
</html>