-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (79 loc) · 2.61 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
<!DOCTYPE html>
<html>
<head>
<style>
* {
font: 4pt serif;
color: #aaa;
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome and Opera */
}
#terrain {
}
#terrain div {
display: flex;
padding: 0;
margin: 0;
text-align: center;
}
#terrain div div {
width: 2px;
height: 2px;
display: flex;
align-items: center;
justify-content: center;
}
#terrain div div:hover {
cursor: default;
background-color: orange;
}
</style>
<script defer="defer">
var World = World || {
rows: 24,
columns: 32,
init: function() {
var canvas = document.getElementById('canvas');
canvas.style.display='none';
var context = canvas.getContext('2d');
var image = new Image();
image.onload = function() {
canvas.width = image.width;
canvas.height = image.height;
context.drawImage(image, 0, 0);
var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
var terrainEl = document.createElement('div');
terrainEl.id = 'terrain';
document.body.appendChild(terrainEl);
for (var i=0; i<canvas.height; i++) {
var lineEl = document.createElement('div');
terrainEl.appendChild(lineEl);
for (var j=0; j<canvas.width; j++) {
var cellEl = document.createElement('div');
var idx = (i*canvas.width+j)*4;
var r = imageData.data[idx+0];
var g = imageData.data[idx+1];
var b = imageData.data[idx+2];
var bgColor = '#'+String("00" + r.toString(16)).slice(-2)+String("00" + g.toString(16)).slice(-2)+String("00" + b.toString(16)).slice(-2);
cellEl.style.backgroundColor = bgColor;
lineEl.appendChild(cellEl);
}
}
};
image.src = 'panamera.jpg';
}
}
</script>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
<script>
World.init();
</script>
</html>