-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwiceasclever2.html
More file actions
202 lines (182 loc) · 5.29 KB
/
twiceasclever2.html
File metadata and controls
202 lines (182 loc) · 5.29 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
<html>
<style>
body {
height: 180mm;
width: 287mm;
margin: 0;
}
#backgroundImg,
#backgroundImg2 {
height: 100%;
width: auto;
position: relative;
}
#myCanvas {
position: absolute;
top: 0;
left: 0;
}
#myCanvas2 {
position: absolute;
top: 0;
left: 442;
}
#seed {
position: absolute;
left: 170;
top: 1;
}
</style>
<head>
<title>Twice as clever custom</title>
<script src="seedrandom.js"></script>
</head>
<body>
<img
id="backgroundImg"
src="TwiceAsCleverChallenge1.png"
alt="Twice as Clever"
/>
<canvas id="myCanvas"></canvas>
<img
id="backgroundImg2"
src="TwiceAsCleverChallenge1.png"
alt="Twice as Clever"
/>
<canvas id="myCanvas2"></canvas>
<input
type="text"
id="seed"
name="seed"
value="Em2024"
onblur="changeSeed()"
/>
<script>
// var seed = "Em2024";
let randomGen = new Math.seedrandom(
document.getElementById("seed").value
);
function changeSeed() {
var seedLocal = document.getElementById("seed").value;
console.debug("Seed changed to: " + seedLocal);
randomGen = new Math.seedrandom(document.getElementById("seed").value);
Render();
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(randomGen() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
const shuffleArray = (array) => {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(randomGen() * (i + 1));
const temp = array[i];
array[i] = array[j];
array[j] = temp;
}
};
function printGrey(context, arr, row, color) {
context.fillStyle = color;
shuffleArray(arr);
for (let i = 0; i < arr.length; i++) {
context.fillText(arr[i], 24 + i * 30, 284 + (row - 1) * 30);
}
}
function printYellow(context, arr) {
context.fillStyle = "black";
shuffleArray(arr);
for (let i = 0; i < arr.length; i++) {
context.fillText(
arr[i],
292 + (i % 3) * 37,
254 + Math.floor(i / 3) * 37
);
}
}
function printYellowCircles(context) {
var circles = [];
for (let i = 0; i < 4; i++) {
var number = getRandomInt(0, 11);
while (circles.includes(number)) {
number = getRandomInt(0, 11);
}
circles.push(number);
}
for (const circle of circles) {
context.beginPath();
context.arc(
298 + (circle % 3) * 37,
248 + Math.floor(circle / 3) * 37,
15,
0,
2 * Math.PI
);
context.lineWidth = 2;
context.strokeStyle = "black";
context.stroke();
}
}
function printGreen(context, arr) {
context.font = "20px Arial";
context.fillStyle = "LightGray";
shuffleArray(arr);
for (let i = 0; i < arr.length; i++) {
context.fillText("x" + arr[i], 33 + i * 33.5, 526);
}
}
function printPink(context, arr, startPos) {
context.font = "20px Arial";
context.fillStyle = "LightGray";
shuffleArray(arr);
for (let i = 0; i < arr.length; i++) {
if (arr[i] !== 0) {
context.fillText("\u2265" + arr[i], startPos + 33 + i * 33, 580);
}
}
}
function printSeed(context) {
context.font = "14px Arial";
context.fillStyle = "DimGray";
context.fillText(
"Seed: " + document.getElementById("seed").value,
290,
18
);
}
function Render() {
var canvas = document.getElementById("myCanvas");
canvas.width = 438;
canvas.height = 589;
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
var canvas2 = document.getElementById("myCanvas2");
canvas2.width = 438;
canvas2.height = 589;
var ctx2 = canvas2.getContext("2d");
ctx2.font = "30px Arial";
var pinkNumbers = [2, 3, 4, 0, 5, 4, 3, 2, 0, 3, 4, 5];
printPink(ctx, pinkNumbers, 0);
printPink(ctx2, pinkNumbers, 0);
var greenNumbers = [2, 2, 2, 1, 3, 3, 3, 2, 3, 1, 4, 1];
printGreen(ctx, greenNumbers);
printGreen(ctx2, greenNumbers);
var yellowNumbers = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6];
printYellow(ctx, yellowNumbers);
printYellowCircles(ctx);
printYellow(ctx2, yellowNumbers);
printYellowCircles(ctx2);
var greyNumbers = ["?", 1, 2, 3, 4, 5, 6];
printGrey(ctx, greyNumbers, 1, "DarkOrange");
printGrey(ctx, greyNumbers, 2, "blue");
printGrey(ctx, greyNumbers, 3, "green");
printGrey(ctx, greyNumbers, 4, "HotPink");
printGrey(ctx2, greyNumbers, 1, "DarkOrange");
printGrey(ctx2, greyNumbers, 2, "blue");
printGrey(ctx2, greyNumbers, 3, "green");
printGrey(ctx2, greyNumbers, 4, "HotPink");
printSeed(ctx2);
}
changeSeed();
</script>
</body>
</html>