Skip to content

Commit 4b3b584

Browse files
👍
1 parent 6859b32 commit 4b3b584

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

assets/color.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ function color(imgSrc){
55
img.height = 1000;
66
console.log(img)
77
var rgb = getAverageRGB(img);
8-
return "rgb(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ")"
8+
return "rgb(" + Math.floor(convertRange(rgb.r, [ 0, 255 ], [ 0, 200 ] )) + ", " + Math.floor(convertRange(rgb.g, [ 0, 255 ], [ 0, 200 ] )) + ", " + Math.floor(convertRange(rgb.b, [ 0, 255 ], [ 0, 200 ] )) + ")"
9+
}
10+
function convertRange( value, r1, r2 ) {
11+
return ( value - r1[ 0 ] ) * ( r2[ 1 ] - r2[ 0 ] ) / ( r1[ 1 ] - r1[ 0 ] ) + r2[ 0 ];
912
}
1013

1114
function getAverageRGB(imgEl) {

assets/legendary.png

706 KB
Loading

html/game.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ <h1 class="win2" style="display: none">
5555
{
5656
name: "Lemon",
5757
pics: ["url('lemon1.jpg')", "url('lemon2.jpg')", "url('lemon3.jpg')", "url('lemon4.jpg')"],
58-
key: "KeyL"
58+
key: "Digit2"
5959
},
6060
{
6161
name: "Banana",
6262
pics: ["url('banana1.jpg')", "url('banana2.jpg')", "url('banana3.jpg')", "url('banana4.jpg')"],
63-
key: "KeyB"
63+
key: "Digit1"
6464
},
6565
{
6666
name: "Lime",
6767
pics: ["url('lime1.jpg')", "url('lime2.jpg')", "url('lime3.jpg')", "url('lime4.jpg')"],
68-
key: "KeyI"
68+
key: "Digit4"
6969
},
7070
{
7171
name: "Orange",
7272
pics: ["url('orange1.jpg')", "url('orange2.jpg')", "url('orange3.jpg')", "url('orange4.jpg')"],
73-
key: "KeyO"
73+
key: "Digit3"
7474
}
7575
]
7676
var out = []; // Initialise array of names of fruits
@@ -87,17 +87,20 @@ <h1 class="win2" style="display: none">
8787
}
8888
var current = {};
8989
function getImageFromName(name) {
90+
if (name.startsWith("url")){
91+
return name
92+
}
9093
var out = {}; // Initialise array of names of fruits
9194
for (var i = 0; i < fruits.length; i++){ // Go throught fruit objects
9295
out[fruits[i].name] = choose(fruits[i].pics)
9396
}
9497
return out[name]
9598
}
9699
setTimeout(function(){
97-
initPic(getImageFromName(choose(out)), choose(out)) // Set a random background and text
100+
initPic(getImageFromName(choose(out)), choose(out)) // Set a random background and text
98101
}, 200)
99102

100-
function choose(choices) { // Makes a random choice from Array, eg. [1,2,5] => 1 or 2 or 5
103+
function choose(choices) { // Makes a random choice from Array, eg. [1,2,5] => 1 or 2 or 5
101104
var index = Math.floor(Math.random() * choices.length);
102105
return choices[index];
103106
}
@@ -116,6 +119,13 @@ <h1 class="win2" style="display: none">
116119
function initPic(pic, word) { // Function that sets the background and word
117120
$("html").css("background-image", pic); // TODO: Random location for word?
118121
$(".words").text(word);
122+
var rARE = Math.random;
123+
console.log(rARE)
124+
if (rARE > 0.9) {
125+
126+
console.log("Yay")
127+
pic = "url('legendary.png')"
128+
}
119129
$(".words").css("color", color(pic.replace("url('", "").replace("')", "")));
120130
randomMove($(".words")) // CHANGED: Now moves text each time
121131
current.pic = pic;

storage/leaderboard.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"Jeff","score":0},{"name":"Jay","score":6},{"name":"Jay","score":53},{"name":"Yipee","score":181},{"name":"Banana","score":16},{"name":"Points","score":10},{"name":"Yayy","score":108}]
1+
[{"name":"Jeff","score":0},{"name":"Jay","score":6},{"name":"Jay","score":53},{"name":"Yipee","score":181},{"name":"Banana","score":16},{"name":"Points","score":10},{"name":"Yayy","score":108},{"name":"Jay","score":21},{"name":"Eoin","score":38},{"name":"Matthew","score":29},{"name":"Matthew","score":49}]

0 commit comments

Comments
 (0)