Skip to content

Commit 2894559

Browse files
committed
Minor cleanup
1 parent 87b7161 commit 2894559

File tree

5 files changed

+51
-39
lines changed

5 files changed

+51
-39
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.env
3+
twitter/data
4+
twitter/

website/index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
<!-- ending -->
3737
<div class="ui-popup-container disabled">
3838
<div class=ui-popup>
39+
<!-- Thank you for playing -->
3940
<div class=section>
4041
<h1>Thank you for playing!</h1>
4142
<p>Follow <a href="https://twitter.com/Puzzle_fy" target=_blank>@Puzzle_fy</a> on twitter</p>
4243
</div>
44+
<!-- Puzzle generator -->
4345
<div class="section container">
4446
<h2>Generate your puzzle</h2>
45-
<!--<p>Make your own puzzle and share it with your friends!</p>-->
47+
<p hidden>Make your own puzzle and share it with your friends!</p>
4648
<input type="text" placeholder="Image link" id=url> <input type="number" placeholder="Width" min=0 id=cols> x <input type="number" placeholder="Height" min=0 id=rows>
4749
<br><br>
4850
<div>
@@ -51,6 +53,7 @@ <h2>Generate your puzzle</h2>
5153
<button type="button" class=twitter onclick="shareGenerate()"><i class="fab fa-twitter"></i></button>
5254
</div>
5355
</div>
56+
<!-- Zombiecraft -->
5457
<div id=zombiecraft>
5558
<img src=https://zc.stephcraft.net/assets/image/zombiecraft-logo.png>
5659
<p>Do you like Minecraft and Call of Duty zombies? If so, then join this epic Minecraft server without any mods!</p>
@@ -60,6 +63,7 @@ <h2>Generate your puzzle</h2>
6063
<a href="https://zc.stephcraft.net/twitter" target=_blank><button type="button" class=twitter><i class="fab fa-twitter"></i></button></a>
6164
</div>
6265
</div>
66+
<!-- Play again -->
6367
<div class=section>
6468
<a id=again><button type="button">Play again</button></a>
6569
<a id=share target=_blank><button type="button" class=twitter><i class="fab fa-twitter"></i></button></a>
@@ -114,6 +118,7 @@ <h2>Generate your puzzle</h2>
114118

115119
<!-- scripts -->
116120
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.js"></script>
121+
<script src=plugins/clipboard.js></script>
117122
<script src=plugins/transform.js></script>
118123
<script src=plugins/cors.js></script>
119124
<script src=jigsaw.js></script>

website/meta.js

+2-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const params = new URLSearchParams(window.location.search)
22

3+
// dynamic image meta
34
document.querySelector('meta[property="og:image"]').setAttribute("content", params.get('image'))
45

56
// disable scroll
@@ -32,39 +33,4 @@ function setupLinks() {
3233
function isEncoded(uri) {
3334
uri = uri || ''
3435
return uri !== decodeURIComponent(uri)
35-
}
36-
37-
function fallbackCopyTextToClipboard(text) {
38-
var textArea = document.createElement("textarea");
39-
textArea.value = text;
40-
41-
// Avoid scrolling to bottom
42-
textArea.style.top = "0";
43-
textArea.style.left = "0";
44-
textArea.style.position = "fixed";
45-
46-
document.body.appendChild(textArea);
47-
textArea.focus();
48-
textArea.select();
49-
50-
try {
51-
var successful = document.execCommand('copy');
52-
var msg = successful ? 'successful' : 'unsuccessful';
53-
console.log('Fallback: Copying text command was ' + msg);
54-
} catch (err) {
55-
console.error('Fallback: Oops, unable to copy', err);
56-
}
57-
58-
document.body.removeChild(textArea);
59-
}
60-
function copyTextToClipboard(text) {
61-
if (!navigator.clipboard) {
62-
fallbackCopyTextToClipboard(text);
63-
return;
64-
}
65-
navigator.clipboard.writeText(text).then(function() {
66-
console.log('Async: Copying to clipboard was successful!');
67-
}, function(err) {
68-
console.error('Async: Could not copy text: ', err);
69-
});
70-
}
36+
}

website/plugins/clipboard.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function fallbackCopyTextToClipboard(text) {
2+
var textArea = document.createElement("textarea");
3+
textArea.value = text;
4+
5+
// Avoid scrolling to bottom
6+
textArea.style.top = "0";
7+
textArea.style.left = "0";
8+
textArea.style.position = "fixed";
9+
10+
document.body.appendChild(textArea);
11+
textArea.focus();
12+
textArea.select();
13+
14+
try {
15+
var successful = document.execCommand('copy');
16+
var msg = successful ? 'successful' : 'unsuccessful';
17+
console.log('Fallback: Copying text command was ' + msg);
18+
} catch (err) {
19+
console.error('Fallback: Oops, unable to copy', err);
20+
}
21+
22+
document.body.removeChild(textArea);
23+
}
24+
25+
function copyTextToClipboard(text) {
26+
if (!navigator.clipboard) {
27+
fallbackCopyTextToClipboard(text);
28+
return;
29+
}
30+
navigator.clipboard.writeText(text).then(function() {
31+
console.log('Async: Copying to clipboard was successful!');
32+
}, function(err) {
33+
console.error('Async: Could not copy text: ', err);
34+
});
35+
}

website/script.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function setup() {
3737
canvas = createCanvas(windowWidth, windowHeight)
3838

3939
// p5*js plugins
40-
addScreenPositionFunction()
4140
// addCORSLoadImageFunction()
41+
addScreenPositionFunction()
4242

4343
prev = millis()
4444

@@ -106,6 +106,7 @@ function start() {
106106

107107
prev = millis()
108108

109+
// puzzle tiles generation
109110
tiles = puzzleify(tiles)
110111

111112
console.log('puzzleify: ', millis() - prev)
@@ -198,12 +199,13 @@ function draw() {
198199
return
199200
}
200201

201-
// base
202+
// scale and frame
202203
s = Math.min(width / img.width, height / img.height) * scl
203204
frame = parseInt((0.5 * frameCount) % numFrames(img))
204205

205206
background(Theme.background)
206207

208+
// transform
207209
translate(width/2, height/2)
208210
scale(s)
209211

0 commit comments

Comments
 (0)