-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolors.stx
More file actions
192 lines (177 loc) · 5.03 KB
/
colors.stx
File metadata and controls
192 lines (177 loc) · 5.03 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
<script server>
// Generate a random set of harmonious colors
function generatePalette() {
const palette = [];
// Base hue - random value between 0 and 360
const baseHue = Math.floor(Math.random() * 360);
// Create 8 colors based on the base hue
for (let i = 0; i < 8; i++) {
// Calculate a hue that's offset from the base
const hue = (baseHue + i * 45) % 360;
// Vary saturation and lightness
const saturation = 65 + Math.floor(Math.random() * 35);
const lightness = 45 + Math.floor(Math.random() * 30);
// Create the color object
const color = {
id: i,
name: `Color ${i + 1}`,
hsl: `hsl(${hue}, ${saturation}%, ${lightness}%)`,
hex: hslToHex(hue, saturation, lightness),
rgb: hslToRgb(hue, saturation, lightness),
contrastWithWhite: getContrastRatio(hslToRgb(hue, saturation, lightness), [255, 255, 255])
};
palette.push(color);
}
return palette;
}
// Convert HSL to Hex color
function hslToHex(h, s, l) {
const rgb = hslToRgb(h, s, l);
return `#${rgb[0].toString(16).padStart(2, '0')}${rgb[1].toString(16).padStart(2, '0')}${rgb[2].toString(16).padStart(2, '0')}`;
}
// Convert HSL to RGB
function hslToRgb(h, s, l) {
s /= 100;
l /= 100;
const k = n => (n + h / 30) % 12;
const a = s * Math.min(l, 1 - l);
const f = n => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
return [
Math.round(255 * f(0)),
Math.round(255 * f(8)),
Math.round(255 * f(4))
];
}
// Calculate contrast ratio between two RGB colors
function getContrastRatio(rgb1, rgb2) {
const getLuminance = rgb => {
const [r, g, b] = rgb.map(c => {
c /= 255;
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
});
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
};
const l1 = getLuminance(rgb1);
const l2 = getLuminance(rgb2);
const ratio = (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
return Math.round(ratio * 10) / 10;
}
const paletteTitle = 'stx Color Palette Generator'
const colorPalette = generatePalette()
const timestamp = new Date().toLocaleTimeString()
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>stx Dynamic Colors</title>
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 2rem;
line-height: 1.6;
}
header {
text-align: center;
margin-bottom: 2rem;
}
h1 {
font-size: 2.5rem;
margin-bottom: 0.5rem;
}
.palette {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1.5rem;
}
.color-card {
border-radius: 0.5rem;
overflow: hidden;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.color-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.color-preview {
height: 150px;
display: flex;
align-items: center;
justify-content: center;
color: white;
text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
font-weight: bold;
}
.color-info {
padding: 1rem;
background-color: white;
}
.color-name {
font-weight: bold;
margin-bottom: 0.5rem;
}
.color-hex {
font-family: monospace;
color: #666;
}
.color-rgb {
font-family: monospace;
font-size: 0.9rem;
color: #888;
margin-top: 0.5rem;
}
.contrast {
display: flex;
margin-top: 0.5rem;
font-size: 0.9rem;
}
.contrast-box {
width: 20px;
height: 20px;
border-radius: 4px;
margin-right: 0.5rem;
}
.dark-text {
color: black;
text-shadow: none;
}
.footer {
margin-top: 3rem;
text-align: center;
color: #666;
}
</style>
</head>
<body>
<header>
<h1>{{ paletteTitle }}</h1>
<p>Refresh the page or edit this file to generate new colors. Last updated: {{ timestamp }}</p>
</header>
<div class="palette">
@foreach (colorPalette as color)
<div class="color-card">
<div class="color-preview" style="background-color: {{ color.hex }}">
<span class="{{ color.contrastWithWhite < 4.5 ? 'dark-text' : '' }}">{{ color.name }}</span>
</div>
<div class="color-info">
<div class="color-name">{{ color.name }}</div>
<div class="color-hex">{{ color.hex }}</div>
<div class="color-rgb">{{ color.rgb.join(', ') }}</div>
<div class="contrast">
<div class="contrast-box" style="background-color: white; border: 1px solid #ddd;"></div>
Contrast: {{ color.contrastWithWhite }}:1
</div>
</div>
</div>
@endforeach
</div>
<div class="footer">
<p>Created with stx Templating Engine</p>
<p>Try modifying this file at <code>examples/colors.stx</code></p>
</div>
</body>
</html>