Skip to content

Commit 74b6ae8

Browse files
Color Works
1 parent 9606544 commit 74b6ae8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

assets/color.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
function color(imgSrc){
22
var img = document.createElement('img');
33
img.src = imgSrc;
4+
img.width = 1000;
5+
img.height = 1000;
6+
console.log(img)
47
var rgb = getAverageRGB(img);
5-
return rgb
8+
return "rgb(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ")"
69
}
710

811
function getAverageRGB(imgEl) {
@@ -29,6 +32,7 @@ function getAverageRGB(imgEl) {
2932
data = context.getImageData(0, 0, width, height);
3033
} catch(e) {
3134
/* security error, img on diff domain */alert('x');
35+
console.log(e)
3236
return defaultRGB;
3337
}
3438

html/game.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ <h1 class="win2" style="display: none">
7171
function initPic(pic, word) {
7272
$("html").css("background-image", pic);
7373
$(".words").text(word);
74+
$(".words").css("color", color(pic.replace("url('", "").replace("')", "")))
7475
current.pic = pic;
7576
current.word = word;
7677
}

0 commit comments

Comments
 (0)