-
Notifications
You must be signed in to change notification settings - Fork 3
/
square.html
203 lines (184 loc) · 9.22 KB
/
square.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Su Squares, cute squares you own and personalize</title>
<meta name="description" content="The first ERC-721 NFT. Cute squares you own and personalize.">
<link rel="stylesheet" href="assets/main.css?20210926">
</head>
<body>
<header>
<a id="logo" href="/"><img src="assets/logo-su-squares.svg" style="width:348px;height:57px;object-fit: cover;" alt="Su Squares logo"></a>
<span>
The first ERC-721 NFT
</span>
<a class="btn" href="white-paper">About us</a>
<a class="btn" href="buy">Buy</a>
<a class="btn" href="https://tools.tenthousandsu.com/personalize">Personalize</a>
<a class="btn" target="_blank" href="https://x.com/susquares">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-twitter-x" viewBox="0 0 16 16">
<path d="M12.6.75h2.454l-5.36 6.142L16 15.25h-4.937l-3.867-5.07-4.425 5.07H.316l5.733-6.57L0 .75h5.063l3.495 4.633L12.601.75Zm-.86 13.028h1.36L4.323 2.145H2.865l8.875 11.633Z"/>
</svg>
</a>
<a class="btn" target="_blank" href="https://discord.gg/6nTGNdjQ3B">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-discord"
viewBox="0 0 16 16">
<path
d="M13.545 2.907a13.227 13.227 0 0 0-3.257-1.011.05.05 0 0 0-.052.025c-.141.25-.297.577-.406.833a12.19 12.19 0 0 0-3.658 0 8.258 8.258 0 0 0-.412-.833.051.051 0 0 0-.052-.025c-1.125.194-2.22.534-3.257 1.011a.041.041 0 0 0-.021.018C.356 6.024-.213 9.047.066 12.032c.001.014.01.028.021.037a13.276 13.276 0 0 0 3.995 2.02.05.05 0 0 0 .056-.019c.308-.42.582-.863.818-1.329a.05.05 0 0 0-.01-.059.051.051 0 0 0-.018-.011 8.875 8.875 0 0 1-1.248-.595.05.05 0 0 1-.02-.066.051.051 0 0 1 .015-.019c.084-.063.168-.129.248-.195a.05.05 0 0 1 .051-.007c2.619 1.196 5.454 1.196 8.041 0a.052.052 0 0 1 .053.007c.08.066.164.132.248.195a.051.051 0 0 1-.004.085 8.254 8.254 0 0 1-1.249.594.05.05 0 0 0-.03.03.052.052 0 0 0 .003.041c.24.465.515.909.817 1.329a.05.05 0 0 0 .056.019 13.235 13.235 0 0 0 4.001-2.02.049.049 0 0 0 .021-.037c.334-3.451-.559-6.449-2.366-9.106a.034.034 0 0 0-.02-.019Zm-8.198 7.307c-.789 0-1.438-.724-1.438-1.612 0-.889.637-1.613 1.438-1.613.807 0 1.45.73 1.438 1.613 0 .888-.637 1.612-1.438 1.612Zm5.316 0c-.788 0-1.438-.724-1.438-1.612 0-.889.637-1.613 1.438-1.613.807 0 1.451.73 1.438 1.613 0 .888-.631 1.612-1.438 1.612Z" />
</svg>
</a>
</header>
<article>
<h1>Square #<span id="square-number">...</span></h1>
<div id="image"></div>
<dl>
<dt>Minted</dt>
<dd id="minted"></dd>
<dt>Personalized</dt>
<dd id="personalized"></dd> <!-- also show #X most recent -->
<dt>Title</dt>
<dd id="title"></dd>
<dt>Link</dt>
<dd id="link"></dd>
</dl>
<h2>Location</h2>
<div style="position:relative;height:1000px; zoom: 0.5">
<img id="theImage" src="build/wholeSquare.png" alt="All Su Squares" style="height:1000px; width:1000px">
<img id="arrow" src="assets/dr.png" alt="Location" style="height:100px; width:100px; position:absolute">
</div>
<h2>Emojified</h2>
<pre id="emojified"></pre>
<button class="btn" id="copy-emojified">Copy</button>
</article>
<footer>
<small>
No cookies. No analytics. Not responsible for content of linked sites. Images shown on homepage are © their
respective owners. This image <a target="_blank" href="https://github.com/su-squares/tenthousandsu.com/actions/workflows/load-from-blockchain.yml">refreshes hourly</a>. To the extent possible under law, Su Entriken has waived
all copyright and related or neighboring rights to the TenThousandSu.com website. This work is published from the
United States.
</small>
</footer>
<script>
// Get URL fragment
const squareNumber = parseInt(window.location.hash.substring(1));
const personalizations = fetch('build/squarePersonalizations.json').then(response => response.json());
const extras = fetch('build/squareExtra.json').then(response => response.json());
Promise.all([personalizations, extras]).then(([personalizations, extras]) => {
// Each personalization is [title, href] or null
// Each extra is [mintedBlock, updatedBlock, mainIsPersonalized, version] or null
// Arrays are zero indexed, but the first Su Square number is 1!
const elSquareNumber = document.getElementById("square-number");
elSquareNumber.innerText = squareNumber;
const elMinted = document.getElementById('minted');
elMinted.innerText = extras[squareNumber - 1] ? `Block ${extras[squareNumber - 1][0]}` : 'Not minted';
const elPersonalized = document.getElementById('personalized');
elPersonalized.innerText = extras[squareNumber - 1] ? `Block ${extras[squareNumber - 1][1]}` : 'Not personalized';
const elTitle = document.getElementById('title');
elTitle.innerText = personalizations[squareNumber - 1] ? personalizations[squareNumber - 1][0] : 'Not personalized';
const elLink = document.getElementById('link');
elLink.innerText = personalizations[squareNumber - 1] ? personalizations[squareNumber - 1][1] : 'Not personalized';
const elEmojified = document.getElementById('emojified');
// Set image
const row = Math.floor((squareNumber - 1) / 100); // 0 indexed
const col = (squareNumber - 1) % 100; // 0 indexed
const elImage = document.getElementById('image');
elImage.style.backgroundImage = 'url("build/wholeSquare.png")';
elImage.style.backgroundPosition = `-${col * 10}px -${row * 10}px`;
elImage.style.height = '10px';
elImage.style.width = '10px';
elImage.style.display = 'inline-block';
elImage.style.zoom = '20';
elImage.style.imageRendering = 'pixelated';
// Set arrow location, based on quadrant
const elArrow = document.getElementById('arrow');
if (row < 50) {
if (col < 50) {
elArrow.src = 'assets/ul.png';
elArrow.style.top = `${row * 10 + 10}px`;
elArrow.style.left = `${col * 10 + 10}px`;
} else {
elArrow.src = 'assets/ur.png';
elArrow.style.top = `${row * 10 + 10}px`;
elArrow.style.left = `${col * 10 - 100}px`;
}
} else {
if (col < 50) {
elArrow.src = 'assets/dl.png';
elArrow.style.top = `${row * 10 - 100}px`;
elArrow.style.left = `${col * 10 + 10}px`;
} else {
elArrow.src = 'assets/dr.png';
elArrow.style.top = `${row * 10 - 100}px`;
elArrow.style.left = `${col * 10 - 100}px`;
}
}
// Emoji squares and RGB values for ⬛⬜🟥🟧🟨🟩🟦🟪🟫
const emojis = [
{"emoji": "⬛", "red": 0, "green": 0, "blue": 0},
{"emoji": "⬜", "red": 255, "green": 255, "blue": 255},
{"emoji": "🟥", "red": 255, "green": 0, "blue": 0},
{"emoji": "🟧", "red": 255, "green": 165, "blue": 0},
{"emoji": "🟨", "red": 255, "green": 255, "blue": 0},
{"emoji": "🟩", "red": 0, "green": 128, "blue": 0},
{"emoji": "🟦", "red": 0, "green": 0, "blue": 255},
{"emoji": "🟪", "red": 128, "green": 0, "blue": 128},
{"emoji": "🟫", "red": 139, "green": 69, "blue": 19},
]
// Create canvas
const canvas = document.createElement('canvas');
canvas.width = 10;
canvas.height = 10;
// Add wholeSquare to canvas
const context = canvas.getContext('2d');
const image = new Image();
image.src = 'build/wholeSquare.png';
image.onload = function(){
context.drawImage(image, col * 10, row * 10, 10, 10, 0, 0, 10, 10);
// Get pixels
const imageData = context.getImageData(0, 0, 10, 10);
const pixels = imageData.data;
// Loop pixels
let emojiString = '';
for (let i = 0; i < pixels.length; i += 4) {
// Get pixel color
const red = pixels[i];
const green = pixels[i + 1];
const blue = pixels[i + 2];
// Find closest emoji
let closestEmoji = emojis[0];
let closestDistance = 195075;
for (let j = 0; j < emojis.length; j++) {
const emoji = emojis[j];
const distance = Math.sqrt(
Math.pow(emoji.red - red, 2) +
Math.pow(emoji.green - green, 2) +
Math.pow(emoji.blue - blue, 2)
);
if (distance < closestDistance) {
closestEmoji = emoji;
closestDistance = distance;
}
}
emojiString += closestEmoji.emoji;
// Add line break
if (i % 40 === 36) {
emojiString += "<br>";
}
}
// Set emoji string
elEmojified.innerHTML = emojiString;
}
// Copy emojified
const elCopyEmojified = document.getElementById('copy-emojified');
elCopyEmojified.addEventListener('click', () => {
const range = document.createRange();
range.selectNode(elEmojified);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
});
});
</script>
</body>
</html>