-
Notifications
You must be signed in to change notification settings - Fork 1
/
weheart.js
executable file
·72 lines (62 loc) · 2.17 KB
/
weheart.js
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
function weheart() {
var result = document.createElementNS("http://www.w3.org/2000/svg", 'g');
function randomColor() {
var r = 255 * Math.random() | 0;
var g = 255 * Math.random() | 0;
var b = 255 * Math.random() | 0;
return 'rgb(' + r + ',' + g + ',' + b + ')';
}
function newAtriumElement(rotation) {
var result = document.createElementNS("http://www.w3.org/2000/svg", 'path');
result.setAttribute('d', "m 0 0.333 a 0.333,0.333 0 1,1 0.666,0 h-0.666 z");
result.setAttribute('fill', randomColor() );
var rotationString = "rotate(" + rotation + "," + 0.333 + "," + 0.666 + ")";
result.setAttribute('transform', rotationString);
return result;
}
function newCenterElement() {
var result = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
result.setAttribute('x', "0");
result.setAttribute('y', "0.333");
result.setAttribute('width', "0.666");
result.setAttribute('height', "0.666");
result.setAttribute('fill', randomColor() );
var rotationString = "rotate(" + 45 + "," + 0.333 + "," + 0.666 + ")";
result.setAttribute('transform', rotationString);
return result;
}
result.leftAtrium = newAtriumElement(-45);
result.leftAtrium.id = "leftAtrium";
result.appendChild(result.leftAtrium);
result.rightAtrium = newAtriumElement(45);
result.rightAtrium.id = "rightAtrium";
result.appendChild(result.rightAtrium);
result.center = newCenterElement();
result.center.id = "center";
result.appendChild(result.center);
Object.defineProperty(result, 'leftFillColor', {
get: function() {
return this.leftAtrium.getAttribute('fill');
},
set: function(value) {
this.leftAtrium.setAttribute('fill', value);
}
});
Object.defineProperty(result, 'centerFillColor', {
get: function() {
return this.center.getAttribute('fill');
},
set: function(value) {
this.center.setAttribute('fill', value);
}
});
Object.defineProperty(result, 'rightFillColor', {
get: function() {
return this.rightAtrium.getAttribute('fill');
},
set: function(value) {
this.rightAtrium.setAttribute('fill', value);
}
});
return result;
}