-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3_matrix1.html
217 lines (164 loc) · 7.25 KB
/
d3_matrix1.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
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
206
207
208
209
210
211
212
213
214
215
216
217
<html lang="en"><head>
<title>Blockchain Animation</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
html {
background: #0C0019;
color:grey;
}
.container {
display: flex;
align-items: center;
justify-content: center;
}
#myBox {
/*transform: scale(1) translate(10px, 20px) rotate(30deg);*/
transform: matrix(0.3592, -0.3065, 1.2019, 0.6834, 133.3929, 155.1232);
padding: 20px;
margin: 20px;
width: 120px;
background: limegreen;
opacity: 0.3;
color: white;
font-family: sans-serif;
}
output {
display: block;
font-family: monospace;
background: #eee;
padding: 20px;
}
#thing {
transform: scale(1) rotate(60deg) ;
}
</style>
</head>
<body>
<div id="thing">a</div>
<script>
var el = document.getElementById("thing");
var st = window.getComputedStyle(el, null);
var tr = st.getPropertyValue("-webkit-transform") ||
st.getPropertyValue("-moz-transform") ||
st.getPropertyValue("-ms-transform") ||
st.getPropertyValue("-o-transform") ||
st.getPropertyValue("transform") ||
"FAIL";
// With rotate(30deg)...
// matrix(0.866025, 0.5, -0.5, 0.866025, 0px, 0px)
console.log('Matrix: ' + tr);
document.write('Matrix: ' + tr+'</br>');
// rotation matrix - http://en.wikipedia.org/wiki/Rotation_matrix
var values = tr.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
var c = values[2];
var d = values[3];
var scale = Math.sqrt(a*a + b*b);
console.log('Scale: ' + scale);
document.write('Scale: ' + scale+'</br>');
// arc sin, convert from radians to degrees, round
var sin = b/scale;
// next line works for 30deg but not 130deg (returns 50);
// var angle = Math.round(Math.asin(sin) * (180/Math.PI));
var angle = Math.round(Math.atan2(b, a) * (180/Math.PI));
console.log('Rotate: ' + angle + 'deg');
document.write('Rotate: ' + angle + 'deg'+'</br>');
</script>
<div id="myBox">
My Box.
</div>
<output id="output"></output>
<script>
var e = "";
var style = "";
e = document.getElementById("myBox");
style = window.getComputedStyle(e).getPropertyValue("transform");
document.getElementById("output").innerText=style;
</script>
<script>
//Given an initial point, a slope, and length, find the next point
function findSlope(x0,y0,x1,y1){
var slope = (y1-y0)/(x1-x0);
console.log(slope);
return slope;
}
function findNextPoint(x0,y0,slope,segment_length){
var point ={};
point.x = x0+segment_length*Math.sqrt((1/(1+Math.pow(slope, 2))));
point.y = y0+slope*segment_length*Math.sqrt((1/(1+Math.pow(slope, 2))));
return point;
}
function findPerpendicularPoint(x0,y0,slope,segment_length){
var point ={};
var perpendicularSlope = -1/slope;
point.x = x0+segment_length*Math.sqrt((1/(1+Math.pow(perpendicularSlope, 2))));
point.y = y0+slope*segment_length*Math.sqrt((1/(1+Math.pow(perpendicularSlope, 2))));
return point;
}
</script>
<div class="container">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" height="99vh" viewBox="0 0 2000 1200" enable-background="new 0 0 2000 1200" xml:space="preserve">
<g>
<!--
<linearGradient id="SVGID_41_" x1="885.7858" x2="885.9467" y1="-920.6589" y2="-787.5014" gradientTransform="matrix(0.3592 -0.3065 1.2019 0.6834 1339.3929 1550.1232)" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0"></stop>
<stop offset="1" style="stop-color:#FFFFFF"></stop>
</linearGradient>
<polygon class="particlespoly" fill="url(#SVGID_41_)" points="733.6,720 683.4,767.8 491.1,643.4
555.6,608.9 " enable-background="new " opacity="0.25"></polygon>
-->
<linearGradient id="SVGID_42_" x1="1042.4587" x2="993.0236" y1="-985.6109" y2="-790.8901" gradientTransform="matrix(0.3592 -0.3065 1.2019 0.6834 1339.3929 1550.1232)" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0"></stop>
<stop offset="0.2113" style="stop-color:#FFD7DA;stop-opacity:0.2113"></stop>
<stop offset="0.4448" style="stop-color:#FFB1B8;stop-opacity:0.4448"></stop>
<stop offset="0.6617" style="stop-color:#FF969F;stop-opacity:0.6617"></stop>
<stop offset="0.8535" style="stop-color:#FF8690;stop-opacity:0.8535"></stop>
<stop offset="1" style="stop-color:#FF808B"></stop>
</linearGradient>
<polygon class="particlespoly" fill="url(#SVGID_42_)" points="777.3,682.4 718.3,724 493.5,577.2
556,537.9 " enable-background="new " opacity="0.75"></polygon>
<!--
<g id="redglowparticles">
<circle cx="548.8" cy="631.8" r="1.6" fill="#FFFFFF"></circle>
<circle cx="537.9" cy="613.6" r="1.6" fill="#FFFFFF"></circle>
<circle cx="606.4" cy="676" r="1.6" fill="#FFFFFF"></circle>
<circle cx="725.1" cy="657.4" r="1.6" fill="#FFFFFF"></circle>
<circle cx="542.7" cy="596.8" r="1.6" fill="#FFFFFF"></circle>
<circle cx="623.7" cy="724.8" r="1.6" fill="#FFFFFF"></circle>
<circle cx="696.2" cy="708" r="1.6" fill="#FFFFFF"></circle>
<circle cx="611.1" cy="610.4" r="1.6" fill="#FFFFFF"></circle>
<circle cx="564.1" cy="553.5" r="1.6" fill="#FFFFFF"></circle>
<circle cx="554.2" cy="589.4" r="1.6" fill="#FFFFFF"></circle>
<circle cx="670" cy="625" r="1.6" fill="#FFFFFF"></circle>
<ellipse cx="510.9" cy="630.2" fill="#FFFFFF" rx="3.2" ry="3.2" transform="matrix(0.3162 -0.9487 0.9487 0.3162 -248.554 915.582)"></ellipse>
</g>
<linearGradient id="SVGID_43_" x1="891.1575" x2="874.2567" y1="-968.8058" y2="-817.3937" gradientTransform="matrix(0.3592 -0.3065 1.2019 0.6834 1339.3929 1550.1232)" gradientUnits="userSpaceOnUse">
<stop offset="7.030000e-02" style="stop-color:#FFFFFF;stop-opacity:0"></stop>
<stop offset="1" style="stop-color:#FFFFFF"></stop>
</linearGradient>
<polygon class="particlespoly" fill="url(#SVGID_43_)" points="672,693.7 672,760.4 492.3,643.8
492.7,577.2 " enable-background="new " opacity="0.35"></polygon>
<linearGradient id="SVGID_44_" x1="889.0407" x2="876.6129" y1="-943.0591" y2="-831.72" gradientTransform="matrix(0.3592 -0.3065 1.2019 0.6834 1339.3929 1550.1232)" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0"></stop>
<stop offset="1" style="stop-color:#FFFFFF"></stop>
</linearGradient>
<polygon class="particlespoly" fill="url(#SVGID_44_)" points="672,717 672,736.3 492.3,619.6 492.7,600.5
" enable-background="new " opacity="0.35"></polygon>
<linearGradient id="SVGID_45_" x1="1096.1616" x2="1062.9662" y1="-979.2617" y2="-821.5145" gradientTransform="matrix(0.3592 -0.3065 1.2019 0.6834 1339.3929 1550.1232)" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0"></stop>
<stop offset="1" style="stop-color:#FFFFFF"></stop>
</linearGradient>
<polygon class="particlespoly" fill="url(#SVGID_45_)" points="733.3,655.8 732.3,668.5 555,550.9 555,537.7
" enable-background="new " opacity="0.2"></polygon>
<g class="particlespoly" opacity="0.25">
<polygon fill="#FFFFFF" points="602.1,626.4 605.2,611 632.9,608.1 636.4,604.4 601.7,607.7 597.7,629.2 "></polygon>
<polygon fill="#FFFFFF" points="594,618.4 597.2,603 625.4,599.5 628.3,596.3 593.7,599.7 589.7,621.2 "></polygon>
</g>
-->
</g>
</svg>
</div>
<script>
</script>
</body></html>