-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogo.html
96 lines (82 loc) · 2.6 KB
/
logo.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
<html>
<body>
<script>
const intersect = (a, u, b, v) => {
const alpha = xprod([b[0]-a[0], b[1]-a[1]], v) / xprod(u, v);
// return a + alpha*u
return [a[0] + alpha * u[0], a[1] + alpha * u[1]];
}
const xprod = (u, v) => u[0]*v[1] - u[1]*v[0];
const roundValue = v => Math.round(1000 * v) / 1000;
const roundAny = v => Array.isArray(v) ? v.map(roundValue) :
typeof v === 'number' ? roundValue(v) :
v;
// quick template string to round values
const round = (s, ...args) => args.reduce((v, arg, i) => v + roundAny(arg) + s[i+1], s[0]);
// generate logo in a size*size viewBox
function genLogo(size = 100, alpha = 60, D = .9, d = 3) {
//2**.5*r + r + D * r = size * 2**.5/2
// r*(D + 1 + 2**.5) = size*2**.5/2
const r = size * 2**.5 / (2 * (D + 1 + 2**.5));
console.log(r);
const c1 = [r, size - r]; // center1
const c2 = [size - r, r]; // center2
const p1 = [
c1[0] + r * Math.cos((-45 + alpha / 2) * Math.PI/180),
c1[1] + r * Math.sin((-45 + alpha / 2) * Math.PI/180)
];
const p2 = [
c1[0] + r * Math.cos((-45 - alpha / 2) * Math.PI/180),
c1[1] + r * Math.sin((-45 - alpha / 2) * Math.PI/180)
];
const p3 = [
c2[0] + r * Math.cos((135 + alpha / 2) * Math.PI/180),
c2[1] + r * Math.sin((135 + alpha / 2) * Math.PI/180)
];
const p4 = [
c2[0] + r * Math.cos((135 - alpha / 2) * Math.PI/180),
c2[1] + r * Math.sin((135 - alpha / 2) * Math.PI/180)
];
const o1 = [
size / 2 - d / 2**.5,
size / 2 - d / 2**.5
];
const o2 = [
size / 2 + d / 2**.5,
size / 2 + d / 2**.5
];
const u1 = [
Math.cos((-135 + alpha / 2) * Math.PI/180),
Math.sin((-135 + alpha / 2) * Math.PI/180)
];
const u2 = [
Math.cos((45 - alpha / 2) * Math.PI/180),
Math.sin((45 - alpha / 2) * Math.PI/180)
];
const u3 = [
Math.cos((45 + alpha / 2) * Math.PI/180),
Math.sin((45 + alpha / 2) * Math.PI/180)
];
const u4 = [
Math.cos((-135 - alpha / 2) * Math.PI/180),
Math.sin((-135 - alpha / 2) * Math.PI/180)
];
const x1 = intersect(p1, u1, o2, [-1,1]);
const x2 = intersect(p2, u2, o1, [-1,1]);
const x3 = intersect(p3, u3, o1, [1,-1]);
const x4 = intersect(p4, u4, o2, [1,-1]);
// TODO use cubic bezier curves, smoother
return round`<svg viewBox="-3 -3 ${size+6} ${size+6}" height="300">
<defs>
<linearGradient id="g-red-org" x1="0" y1="1" x2="1" y2="0">
<stop offset="0%" stop-color="#cf1913"/>
<stop offset="100%" stop-color="#ef7013"/>
</linearGradient>
</defs>
<path fill="url(#g-red-org)" d="M${p1}A${r},${r},0,1,1,${p2} Q${x2},${o1} Q${x3},${p3} A${r},${r},0,1,1,${p4} Q${x4},${o2} Q${x1},${p1}" />
</svg>`;
}
document.body.innerHTML += genLogo();
</script>
</body>
</html>