-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectGradient.html
More file actions
205 lines (189 loc) · 5.94 KB
/
projectGradient.html
File metadata and controls
205 lines (189 loc) · 5.94 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
203
204
205
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Gradient Generator</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-image: linear-gradient(to right, rgb(92,145,229), rgb(152,63,198));
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
transition: background-image 0.5s ease;
}
button {
padding: 12px 24px;
font-size: 18px;
border: none;
border-radius: 8px;
background-color: white;
color: #333;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
margin-bottom: 20px;
transition: transform 0.2s;
}
button:hover {
transform: scale(1.05);
}
h2 {
color: white;
}
.copyCode {
background-color: rgba(255,255,255,0.1);
color: white;
padding: 10px 20px;
border: 1px solid white;
border-radius: 8px;
margin-top: 10px;
cursor: pointer;
user-select: none;
transition: background-color 0.3s;
white-space: pre-wrap;
max-width: 90vw;
text-align: center;
}
.copyCode:hover {
background-color: rgba(255,255,255,0.2);
}
.copied {
background-color: rgba(0,255,0,0.2);
}
</style>
</head>
<body>
<button id="generateBtn">Generate Gradient</button>
<h2>Click below to copy CSS</h2>
<div class="copyCode" id="codeBox">
background-image: linear-gradient(to right, rgb(92,145,229), rgb(152,63,198));
</div>
<script>
// Array of color sets (arrays) without direction or alpha
const gradients = [
["rgb(92,145,229)", "rgb(152,63,198)"],
["#FF5F6D", "#FFC371"],
["#00C9FF", "#92FE9D"],
["#fc4a1a", "#f7b733"],
["#36D1DC", "#5B86E5"],
["#00F260", "#0575E6"],
["#e1eec3", "#f05053"],
["#DA4453", "#89216B"],
["#5433FF", "#20BDFF", "#A5FECB"],
["#c31432", "#240b36"],
["#FF512F", "#DD2476"],
["#24C6DC", "#514A9D"],
["#2193b0", "#6dd5ed"],
["#e65c00", "#F9D423"],
["#ff9966", "#ff5e62"],
["#de6262", "#ffb88c"],
["#56ab2f", "#a8e063"],
["#614385", "#516395"],
["#e52d27", "#b31217"],
["#283E51", "#485563"],
["#ff6e7f", "#bfe9ff"],
["#c2e59c", "#64b3f4"],
["#eecda3", "#ef629f"],
["#06beb6", "#48b1bf"],
["#dce35b", "#45b649"],
["#f4c4f3", "#fc67fa"],
["#c471f5", "#fa71cd"],
["#ff9a9e", "#fad0c4"],
["#89f7fe", "#66a6ff"],
["#fddb92", "#d1fdff"],
["#a1c4fd", "#c2e9fb"],
["#667eea", "#764ba2"],
["#ff758c", "#ff7eb3"],
["#ffecd2", "#fcb69f"],
["#a18cd1", "#fbc2eb"],
["#fcb045", "#fd1d1d", "#833ab4"],
["#74ebd5", "#ACB6E5"],
["#3a1c71", "#d76d77", "#ffaf7b"],
["#ffe259", "#ffa751"],
["#43cea2", "#185a9d"],
["#00dbde", "#fc00ff"],
["#7F00FF", "#E100FF"],
["#00c3ff", "#ffff1c"],
["#f7971e", "#ffd200"],
["#ff6a00", "#ee0979"],
["#2196f3", "#f44336"],
["#d53369", "#cbad6d"],
["#0099F7", "#F11712"],
["#870000", "#190A05"],
["#a73737", "#7a2828"],
["#2980b9", "#6dd5fa", "#ffffff"],
["#1a2a6c", "#b21f1f", "#fdbb2d"],
["#ff5f6d", "#ffc371"],
["#12c2e9", "#c471ed", "#f64f59"],
["#ff0084", "#33001b"],
["#f46b45", "#eea849"],
["#ddd6f3", "#faaca8"],
["#ff4e50", "#f9d423"],
["#355c7d", "#6c5b7b", "#c06c84"],
["#403A3E", "#BE5869"],
["#606c88", "#3f4c6b"],
["#0f2027", "#203a43", "#2c5364"]
];
// Possible directions
const directions = ["to right", "to left", "to bottom", "to top"];
// Helper: convert hex or rgb string to rgba string with alpha
// Supports rgb(...) and hex (#xxxxxx) formats
function addAlpha(color, alpha) {
alpha = alpha.toFixed(2);
if (color.startsWith("rgb(")) {
// rgb(r,g,b) -> rgba(r,g,b,a)
return color.replace("rgb(", "rgba(").replace(")", `,${alpha})`);
}
else if (color.startsWith("#")) {
// hex to rgba
let r, g, b;
if(color.length === 7) { // #RRGGBB
r = parseInt(color.slice(1,3), 16);
g = parseInt(color.slice(3,5), 16);
b = parseInt(color.slice(5,7), 16);
} else if(color.length === 4) { // #RGB shorthand
r = parseInt(color[1] + color[1], 16);
g = parseInt(color[2] + color[2], 16);
b = parseInt(color[3] + color[3], 16);
} else {
// fallback to white transparent
r = g = b = 255;
}
return `rgba(${r},${g},${b},${alpha})`;
}
// fallback, just append alpha
return color;
}
const generateBtn = document.getElementById("generateBtn");
const codeBox = document.getElementById("codeBox");
generateBtn.addEventListener("click", () => {
const gradientColors = gradients[Math.floor(Math.random() * gradients.length)];
const direction = directions[Math.floor(Math.random() * directions.length)];
// Apply random alpha [0.5 - 1.0] for each color
const colorsWithAlpha = gradientColors.map(color => {
const alpha = Math.random() * 0.5 + 0.5;
return addAlpha(color, alpha);
});
const css = `linear-gradient(${direction}, ${colorsWithAlpha.join(", ")})`;
document.body.style.backgroundImage = css;
codeBox.textContent = `background-image: ${css};`;
});
codeBox.addEventListener("click", () => {
const text = codeBox.textContent;
navigator.clipboard.writeText(text).then(() => {
codeBox.classList.add("copied");
codeBox.textContent = "Copied!";
setTimeout(() => {
codeBox.classList.remove("copied");
codeBox.textContent = `background-image: ${document.body.style.backgroundImage};`;
}, 1000);
});
});
</script>
</body>
</html>