Repository navigation
Expand file tree
/
Copy pathbuilding.html
More file actions
294 lines (256 loc) · 8.88 KB
/
Copy pathbuilding.html
File metadata and controls
294 lines (256 loc) · 8.88 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<style>
html, body {
margin: 0;
padding: 0;
border: 0;
}
* {
box-sizing: border-box;
}
.scene {
position: relative;
min-height: 100vh;
background-color: #A6CFFF;
}
.scene__price {
position: absolute;
background-color: #999;
color: #FFF;
top: 50px;
left: 50px;
padding: 20px;
border-radius: 30px;
font-size: 48px;
}
.scene__building {
background-image: linear-gradient(to bottom, transparent 50%, #e2d570 50%), linear-gradient(to right, #573098 50%, #e2d570 50%);
background-size: 30px 30px, 30px 30px;
background-position: 15px 15px;
height: 105px;
width: 105px;
min-width: 75px;
min-height: 75px;
max-width: 915px;
max-height: 615px;
position: absolute;
bottom: 30px;
left: 15%;
z-index: 5;
}
.scene__building__draggable {
top: -7px;
right: -7px;
width: 14px;
height: 14px;
border: 3px solid #573098;
position: absolute;
border-radius: 50%;
z-index: 10;
cursor: ne-resize;
animation: pulsate 1s ease-out infinite;
}
.scene__building__ceiling {
top: -5px;
left: -5px;
right: -5px;
background-color: #7a6021;
border: 1px solid #524016;
height: 5px;
position: absolute;
}
.scene__building__ceiling__chimney {
position: absolute;
top: -16px;
height: 15px;
left: 80%;
width: 10px;
background-color: #999;
}
.scene__building__ceiling__chimney__smoke {
display: block;
position: absolute;
top: 0;
left: 0;
margin-top: -40px;
margin-left: -30px;
height: 0px;
width: 0px;
border: 35px solid #4b4b4b;
border-radius: 50%;
opacity: 0;
transform: scale(0.2);
z-index: -1;
}
.scene__building__ceiling__chimney__smoke--1 {
animation: smokeL 10s 0s infinite;
}
.scene__building__ceiling__chimney__smoke--2 {
animation: smokeR 10s 1s infinite;
}
.scene__building__ceiling__chimney__smoke--3 {
animation: smokeL 10s 2s infinite;
}
.scene__building__ceiling__chimney__smoke--4 {
animation: smokeR 10s 3s infinite;
}
.scene__building__ceiling__chimney__smoke--5 {
animation: smokeL 10s 4s infinite;
}
.scene__building__ceiling__chimney__smoke--6 {
animation: smokeR 10s 5s infinite;
}
.scene__building__ceiling__chimney__smoke--7 {
animation: smokeL 10s 6s infinite;
}
.scene__building__ceiling__chimney__smoke--8 {
animation: smokeR 10s 7s infinite;
}
.scene__building__ceiling__chimney__smoke--9 {
animation: smokeR 10s 8s infinite;
}
.scene__building__ceiling__chimney__smoke--10 {
animation: smokeR 10s 9s infinite;
}
.scene__building__stairs {
position: absolute;
left: 0;
bottom: 0;
}
.scene__building__stairs:before {
content: "";
background-color: #7a6021;
display: block;
width: 15px;
height: 5px;
margin-left: -15px;
}
.scene__building__stairs:after {
content: "";
background-color: #7a6021;
display: block;
width: 20px;
height: 5px;
margin-left: -20px;
}
.scene__ground {
height: 30px;
left: 0;
right: 0;
bottom: 0;
position: absolute;
border-top: 1px solid #524016;
background-color: #7a6021;
z-index: 10;
}
@keyframes smokeL {
0% {
transform: scale(0.2) translate(0, 0);
}
10% {
opacity: 1;
transform: scale(0.2) translate(0, -5px);
}
100% {
opacity: 0;
transform: scale(1) translate(-20px, -130px);
}
}
@keyframes smokeR {
0% {
transform: scale(0.2) translate(0, 0);
}
10% {
opacity: 1;
transform: scale(0.2) translate(0, -5px);
}
100% {
opacity: 0;
transform: scale(1) translate(20px, -130px);
}
}
@-webkit-keyframes pulsate {
0% {
-webkit-transform: scale(0.1, 0.1);
opacity: 0.0;
}
50% {
opacity: 1.0;
}
100% {
-webkit-transform: scale(1.2, 1.2);
opacity: 0.0;
}
}
</style>
</head>
<body>
<div class="scene">
<div class="scene__price"></div>
<div class="scene__building">
<div class="scene__building__draggable"></div>
<div class="scene__building__ceiling">
<div class="scene__building__ceiling__chimney">
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--1"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--2"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--3"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--4"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--5"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--6"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--7"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--8"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--9"></div>
<div class="scene__building__ceiling__chimney__smoke scene__building__ceiling__chimney__smoke--10"></div>
</div>
</div>
<div class="scene__building__stairs"></div>
</div>
<div class="scene__ground"></div>
</div>
<script>
(function () {
'use strict';
const building = document.querySelector('.scene__building');
const draggable = document.querySelector('.scene__building__draggable');
const price = document.querySelector('.scene__price');
const grid = 30;
let startX, startY, startWidth, startHeight;
function calculatePrice() {
const width = building.offsetWidth;
const height = building.offsetHeight;
const buildingArea = width * height;
const gridArea = grid * grid;
const numBlocks = Math.floor(buildingArea / gridArea);
const priceDigits = Math.ceil(numBlocks / 10);
const pricetag = '$'.repeat(priceDigits);
price.innerHTML = pricetag;
}
function initDrag(e) {
startX = e.clientX;
startY = e.clientY;
startWidth = building.offsetWidth;
startHeight = building.offsetHeight;
document.documentElement.addEventListener('mousemove', doDrag, false);
document.documentElement.addEventListener('mouseup', stopDrag, false);
}
function doDrag(e) {
// Round to the nearest grid multiple + 15px for the wall padding
const newWidth = Math.floor((startWidth + e.clientX - startX) / grid) * grid + 15;
const newHeight = Math.floor((startHeight - e.clientY + startY) / grid) * grid + 15;
building.style.width = newWidth + 'px';
building.style.height = newHeight + 'px';
calculatePrice();
}
function stopDrag() {
document.documentElement.removeEventListener('mousemove', doDrag, false);
document.documentElement.removeEventListener('mouseup', stopDrag, false);
}
draggable.addEventListener('mousedown', initDrag, false);
calculatePrice();
})();
</script>
</body>
</html>