Repository navigation
Expand file tree
/
Copy pathvisualwall.html
More file actions
172 lines (134 loc) · 3.1 KB
/
Copy pathvisualwall.html
File metadata and controls
172 lines (134 loc) · 3.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Color Sorted Image Wall</title>
<style>
body {
margin: 0;
background: #111;
font-family: sans-serif;
}
#grid {
display: grid;
grid-template-columns: repeat(auto-fill, 100px);
grid-auto-rows: 100px;
gap: 2px;
padding: 2px;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
}
footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.8);
padding: 12px 20px;
backdrop-filter: blur(8px);
}
#search {
width: 100%;
padding: 10px 16px;
border: 1px solid #444;
border-radius: 6px;
background: #222;
color: #fff;
font-size: 16px;
outline: none;
}
#search:focus {
border-color: #666;
}
#search::placeholder {
color: #888;
}
</style>
</head>
<body>
<div id="grid"></div>
<footer>
<input type="text" id="search" placeholder="Search images...">
</footer>
<script>
// Sample image set (replace with your own later)
const imageUrls = Array.from({length: 60}, (_, i) =>
`https://picsum.photos/300?random=${i+1}`
);
// Get average color of image
function getAverageColor(img) {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 50;
canvas.height = 50;
ctx.drawImage(img, 0, 0, 50, 50);
const data = ctx.getImageData(0, 0, 50, 50).data;
let r = 0, g = 0, b = 0;
const count = data.length / 4;
for (let i = 0; i < data.length; i += 4) {
r += data[i];
g += data[i + 1];
b += data[i + 2];
}
return {
r: r / count,
g: g / count,
b: b / count
};
}
// Convert RGB → Hue
function rgbToHue(r, g, b) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
let h = 0;
if (max !== min) {
if (max === r) {
h = (60 * ((g - b) / (max - min)) + 360) % 360;
} else if (max === g) {
h = 60 * ((b - r) / (max - min)) + 120;
} else {
h = 60 * ((r - g) / (max - min)) + 240;
}
}
return h;
}
// Main loader
async function loadImages() {
const results = [];
for (let url of imageUrls) {
const img = new Image();
img.crossOrigin = "Anonymous";
img.src = url;
await new Promise(resolve => img.onload = resolve);
const color = getAverageColor(img);
const hue = rgbToHue(color.r, color.g, color.b);
results.push({ img, hue });
}
// Sort by hue
results.sort((a, b) => a.hue - b.hue);
// Render
const grid = document.getElementById("grid");
results.forEach(item => {
grid.appendChild(item.img);
});
}
loadImages();
// Search functionality
const searchInput = document.getElementById("search");
searchInput.addEventListener("input", (e) => {
const query = e.target.value.toLowerCase();
const images = document.querySelectorAll("#grid img");
images.forEach(img => {
const src = img.src.toLowerCase();
const alt = img.alt?.toLowerCase() || "";
const matches = src.includes(query) || alt.includes(query);
img.style.display = matches ? "" : "none";
});
});
</script>
</body>
</html>