-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
179 lines (178 loc) · 6.27 KB
/
index.html
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
<html>
<head> </head>
<body>
<div id="settings" style="width: 100%; height: 10%">
<label for="#rotation">Rotation:</label>
<input
type="range"
id="rotation"
min="-360"
max="360"
step="1"
oninput="setFlag()"
/>
<label for="#animate_speed">Speed:</label>
<input
type="range"
id="animate_speed"
min="0.5"
max="10"
step="0.1"
oninput="setFlag()"
/>
<label for="#animate">Animate</label>
<input type="checkbox" id="animate" oninput="setFlag()"/>
<label for="#flag">Flag:</label>
<select id="flag" oninput="setFlag()"></select>
<label for="bg">Background Color</label>
<input type="color" id="bg" value="#ffffff" oninput="setFlag()" />
<a id="downloadlink" href="">Download</a>
</div>
<div id="svg_placeholder" style="width: 100%; height: 90%"></div>
<script>
const flags = {
rainbow: [
"#FF0018",
"#FFA52C",
"#FFFF41",
"#008018",
"#0000F9",
"#86007D",
],
trans: ["#5BCEFA", "#F5A9B8", "white", "#F5A9B8", "#5BCEFA"],
agender: ["black","#b9b9b9", "white", "#b8f483", "white", "#b9b9b9" ,"black"],
aromantic: ["black", "#a9a9a9","white", "#a7d379", "#3da542"],
asexual: ["black", "white", "#a3a3a3","purple"],
bisexual: ["#0038a8", "#9b4f96", "#d60270"],
demisexual: ["#D2D2D2", "#6E0070", "black", "white"],
gay: [
"#3d1a78",
"#5049cc",
"#7bade2",
"#ffffff",
"#98e8c1",
"#26ceaa",
"#078d70"
],
genderfluid: ["#ff75a2" , "white","#be18d6", "black", "#333ebd"],
genderqueer: ["#6b8e3b", "white", "#b57edc"],
lesbian_7: [
"#d52d00",
"#ef7627",
"#ff9a56",
"#ffffff",
"#d162a4",
"#b55690",
"#a30262",
],
lesbian_5: ["#A30262", "#D362A4", "#ffffff", "#FF9A56", "#D52D00"],
nonbinary: ["#2C2C2C", "#9C59D1", "#FCFCFC", "#FCF434"],
pansexual: ["#21b1ff", "#ffd800", "#ff218c"],
};
var gradients = {};
const flagSelector = document.getElementById("flag");
for (const flagId of Object.keys(flags)) {
const option = document.createElement("option");
option.innerText = flagId;
option.setAttribute("id", flagId);
flagSelector.appendChild(option);
}
function create_svg_element(tag, attrs = {}) {
let elem = document.createElementNS("http://www.w3.org/2000/svg", tag);
for (const key of Object.keys(attrs)) {
elem.setAttribute(key, attrs[key]);
}
return elem;
}
function setFlag() {
const bgColor = document.getElementById("bg").value;
document.getElementById("jh_logo").style.backgroundColor = bgColor;
document.bgColor = bgColor;
const flagElem = document.getElementById("flag");
const flag = flagElem.options[flagElem.selectedIndex].value;
const colors = flags[flag];
const flagContainer = document.getElementById("flagContainer");
while (flagContainer.firstChild) {
flagContainer.removeChild(flagContainer.lastChild);
}
const defs = document.querySelector("#jh_logo>defs");
while (defs.firstChild) {
defs.removeChild(defs.firstChild);
}
defs.appendChild(gradients[flag]);
flagContainer.appendChild(
create_svg_element("rect", {
x: -3.5,
y: -3.5,
width: 18,
height: 18,
style:
"fill:url(#gradient_" +
flag +
");fill-opacity:1;fill-rule:evenodd;",
})
);
const rotation = Number(document.getElementById("rotation").value);
const animate = document.getElementById("animate").checked;
const animate_speed = document.getElementById("animate_speed").value;
document
.getElementById("flagContainer")
.setAttribute("transform", `rotate(${rotation} 5.5 5.5)`);
if (animate){
const animation = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");
animation.setAttribute("xmlns", "http://www.w3.org/2000/svg");
animation.setAttribute("attributeName", "transform");
animation.setAttribute("attributeType", "XML");
animation.setAttribute("type", "rotate");
animation.setAttribute("from", `${rotation} 5.5 5.5`);
animation.setAttribute("to", `${rotation + 360} 5.5 5.5`);
animation.setAttribute("dur", `${animate_speed}s`);
animation.setAttribute("repeatCount", "indefinite");
document
.getElementById("flagContainer")
.appendChild(animation);
}
const linkElem = document.getElementById("downloadlink");
linkElem.setAttribute(
"href",
"data:image/svg+xml;base64," +
btoa(document.getElementById("svg_placeholder").innerHTML)
);
linkElem.setAttribute("download", `${flag}.svg`);
}
fetch("data/templates/inverted.svg")
.then((data) => data.text())
.then((data) => {
console.log(data);
for (const flagId of Object.keys(flags)) {
const gradient = create_svg_element("linearGradient", {
id: "gradient_" + flagId,
});
const colors = flags[flagId];
const step_size = 1 / colors.length;
var offset = 0;
colors.forEach((color, idx) => {
gradient.appendChild(
create_svg_element("stop", {
style: "stop-color:" + color + ";stop-opacity:1",
offset: offset,
id: flagId + idx + "_b",
})
);
gradient.appendChild(
create_svg_element("stop", {
style: "stop-color:" + color + ";stop-opacity:1",
offset: offset + step_size,
id: flagId + idx + "_e",
})
);
offset += step_size;
});
gradients[flagId] = gradient;
}
document.getElementById("svg_placeholder").innerHTML = data;
setFlag();
});
</script>
</body>
</html>