-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
145 lines (113 loc) · 4.1 KB
/
example.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Emitter example</title>
<style>
body {
background: url(http://p1.pichost.me/i/58/1821109.jpg) no-repeat center center fixed;
height: 100vh;
}
.smoke-machine {
position: absolute;
width: 50px;
height: 50px;
background-color: #111;
border: 1px solid #444;
pointer: move;
}
</style>
</head>
<body>
<div>You can drag boxes! Hurray!</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
<script src="https://draggabilly.desandro.com/draggabilly.pkgd.min.js"></script>
<script src="dist/pieces.min.js"></script>
<script>
var emitters = [];
for (var x = 1; x < 6; x++) {
var element = createElement();
element.style.zIndex = x;
element.style.left = (x * 220) + 'px';
element.style.top = document.body.scrollHeight / 2 + 'px';
colors = [getRandom(0, 255), getRandom(0, 255), getRandom(0, 255)];
element.style.backgroundColor = 'rgb(' + colors.join(',') + ')';
var emitterElement = new pieces.EmitterElement(element, {
spawnInterval: 50,
maxLifeTime: 3000,
filters: {
colorize: {
colors: colors,
strength: 0.5
}
},
velocityX: getRandom(5, 2),
velocityY: x % 2 ? -2 : 2
});
new Draggabilly( element );
element.addEventListener('click', function () {
setupEmitter(emitterElement.emitter);
});
emitters.push(emitterElement);
}
var element = createElement();
element.style.left = '0px';
element.style.zIndex = 11;
var topEmitter = new pieces.EmitterElement(element, {
// zIndex: 10,
spawnInterval: 30,
maxLifeTime: 4000,
growFactor: 0.3,
endSize: 50,
velocityX: 10,
velocityY: 3
});
emitters.push(topEmitter);
var boxWidth = element.style.width,
viewWidth = document.body.scrollWidth - boxWidth,
moveBy = 3,
delta = 2;
element.style.top = '10px';
setupEmitter(topEmitter.emitter);
update();
function update() {
var left = parseInt(element.style.left);
if (left >= parseInt(viewWidth - boxWidth)){
delta = -moveBy;
}
if (left <= 0) {
delta = moveBy;
}
element.style.left = left + delta + 'px';
requestAnimationFrame(update);
}
function createElement() {
var element = document.createElement('div');
element.classList.add('smoke-machine');
document.body.appendChild(element);
return element;
}
function getRandom(from, to) {
return Math.round(Math.random() * to + from);
}
function setupEmitter (emitter) {
settingsScope = emitter.settings;
var gui = new dat.GUI();
var f1 = gui.addFolder('Emitter');
f1.add(settingsScope, 'spawnInterval');
f1.add(settingsScope, 'paused');
var f2 = gui.addFolder('Particle');
f2.add(settingsScope, 'maxLifeTime', 0, 10000);
f2.add(settingsScope, 'startSize', -10, 100);
f2.add(settingsScope, 'endSize', -10, 100);
f2.add(settingsScope, 'growFactor', 0, 1);
f2.add(settingsScope, 'rotationSpeed', 0, 10);
f2.add(settingsScope, 'velocityX', -10, 10);
f2.add(settingsScope, 'velocityXRandomFactor', 0, 10);
f2.add(settingsScope, 'velocityY', -10, 10);
f2.add(settingsScope, 'velocityYRandomFactor', 0, 10);
f2.open();
}
</script>
</body>
</html>