circular-mirror 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +13 -135
- package/js/main.js +112 -103
- package/package.json +1 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2013-
|
|
3
|
+
Copyright (c) 2013-26 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,96 +1,19 @@
|
|
|
1
1
|
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
3
|
# circular-mirror
|
|
21
4
|
|
|
22
5
|
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/circular-mirror) [](https://www.npmjs.com/package/circular-mirror) [](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
|
23
6
|
|
|
24
7
|
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
|
25
8
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
9
|
> Simulates the reflections of a ray of light inside of a circular mirror.
|
|
33
10
|
|
|
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
|
-
## :question: Get Help
|
|
71
|
-
|
|
72
|
-
There are few ways to get help:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
|
77
|
-
2. For bug reports and feature requests, open issues. :bug:
|
|
78
|
-
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
11
|
## :memo: Documentation
|
|
87
12
|
|
|
88
|
-
|
|
89
13
|
### `round(num, decimals)`
|
|
90
14
|
Rounds a number.
|
|
91
15
|
|
|
92
16
|
#### Params
|
|
93
|
-
|
|
94
17
|
- **Number** `num`: The input number.
|
|
95
18
|
- **Number** `decimals`: How many decimals.
|
|
96
19
|
|
|
@@ -101,7 +24,6 @@ Rounds a number.
|
|
|
101
24
|
Sets a variable interval.
|
|
102
25
|
|
|
103
26
|
#### Params
|
|
104
|
-
|
|
105
27
|
- **Function** `callbackFunc`: The callback function.
|
|
106
28
|
- **Number** `timing`: The interval value.
|
|
107
29
|
|
|
@@ -112,7 +34,6 @@ Sets a variable interval.
|
|
|
112
34
|
Draws a circle on the canvas.
|
|
113
35
|
|
|
114
36
|
#### Params
|
|
115
|
-
|
|
116
37
|
- **Number** `x`: The x value.
|
|
117
38
|
- **Number** `y`: The y value.
|
|
118
39
|
- **Number** `r`: The radius value.
|
|
@@ -123,7 +44,6 @@ Draws a circle on the canvas.
|
|
|
123
44
|
Draws a line on the canvas.
|
|
124
45
|
|
|
125
46
|
#### Params
|
|
126
|
-
|
|
127
47
|
- **Number** `x1`: The source `x` value.
|
|
128
48
|
- **Number** `y1`: The source `y` value.
|
|
129
49
|
- **Number** `x2`: The target `x` value.
|
|
@@ -135,7 +55,6 @@ Draws a line on the canvas.
|
|
|
135
55
|
Draws an arrow on the canvas.
|
|
136
56
|
|
|
137
57
|
#### Params
|
|
138
|
-
|
|
139
58
|
- **Object** `context`: The canvas context.
|
|
140
59
|
- **Number** `fromx`: The source `x` value.
|
|
141
60
|
- **Number** `fromy`: The source `y` value.
|
|
@@ -155,7 +74,6 @@ This function appends the DOM handlers.
|
|
|
155
74
|
This is a **hack**. This roundes the angle in a format that is supported by the application.
|
|
156
75
|
|
|
157
76
|
#### Params
|
|
158
|
-
|
|
159
77
|
- **Number** `angle`: The angle that should be rounded.
|
|
160
78
|
|
|
161
79
|
#### Return
|
|
@@ -165,7 +83,6 @@ This is a **hack**. This roundes the angle in a format that is supported by the
|
|
|
165
83
|
Checks if the angle is supported.
|
|
166
84
|
|
|
167
85
|
#### Params
|
|
168
|
-
|
|
169
86
|
- **Number** `angle`: The angle that should be checked.
|
|
170
87
|
|
|
171
88
|
#### Return
|
|
@@ -175,14 +92,12 @@ Checks if the angle is supported.
|
|
|
175
92
|
Shows an error message.
|
|
176
93
|
|
|
177
94
|
#### Params
|
|
178
|
-
|
|
179
95
|
- **String** `message`: The error message.
|
|
180
96
|
|
|
181
97
|
### `start(point, callback)`
|
|
182
98
|
Draws the lines on the canvas.
|
|
183
99
|
|
|
184
100
|
#### Params
|
|
185
|
-
|
|
186
101
|
- **Point** `point`: The current point.
|
|
187
102
|
- **Function** `callback`: The callback function.
|
|
188
103
|
|
|
@@ -196,7 +111,6 @@ Radius ---> |? ? ?|
|
|
|
196
111
|
Length of segments ---> ------------
|
|
197
112
|
|
|
198
113
|
#### Params
|
|
199
|
-
|
|
200
114
|
- **Object** `A:`: first point
|
|
201
115
|
- **Object** `B:`: second point
|
|
202
116
|
- **Object** `R:`: radius of big circle
|
|
@@ -206,7 +120,6 @@ Length of segments ---> ------------
|
|
|
206
120
|
The function that returns ONLY the first point.
|
|
207
121
|
|
|
208
122
|
#### Params
|
|
209
|
-
|
|
210
123
|
- **Object** `m`:
|
|
211
124
|
- **Object** `x1`:
|
|
212
125
|
- **Object** `y1`:
|
|
@@ -222,73 +135,38 @@ Function that returns a point giving the angle
|
|
|
222
135
|
Verify if the numbers are correct.
|
|
223
136
|
If not, return an false value.
|
|
224
137
|
|
|
138
|
+
## :question: Get Help
|
|
225
139
|
|
|
140
|
+
There are a few ways to get help:
|
|
226
141
|
|
|
142
|
+
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long as you add a link to your Stack Overflow question.
|
|
143
|
+
2. For bug reports and feature requests, open issues. :bug:
|
|
144
|
+
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
227
145
|
|
|
146
|
+
## :yum: How to Contribute
|
|
228
147
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
## :yum: How to contribute
|
|
239
148
|
Have an idea? Found a bug? See [how to contribute][contributing].
|
|
240
149
|
|
|
150
|
+
## :sparkling_heart: Support My Projects
|
|
241
151
|
|
|
242
|
-
|
|
243
|
-
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
|
|
244
|
-
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
|
|
245
|
-
|
|
246
|
-
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
|
|
152
|
+
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute it (even resell it).
|
|
247
153
|
|
|
154
|
+
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are a few ways you can do it:
|
|
248
155
|
|
|
249
156
|
- Starring and sharing the projects you like :rocket:
|
|
250
|
-
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you
|
|
157
|
+
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you for years if you buy me one. :grin: :book:
|
|
251
158
|
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
|
|
252
159
|
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
|
|
253
|
-
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
254
|
-
|
|
255
|
-

|
|
160
|
+
- **Bitcoin**—You can send me bitcoins at this address (or by scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
256
161
|
|
|
162
|
+

|
|
257
163
|
|
|
258
164
|
Thanks! :heart:
|
|
259
165
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
166
|
## :scroll: License
|
|
284
167
|
|
|
285
168
|
[MIT][license] © [Ionică Bizău][website]
|
|
286
169
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
170
|
[license]: /LICENSE
|
|
293
171
|
[website]: https://ionicabizau.net
|
|
294
172
|
[contributing]: /CONTRIBUTING.md
|
|
@@ -298,5 +176,5 @@ Thanks! :heart:
|
|
|
298
176
|
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
|
|
299
177
|
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
|
|
300
178
|
[patreon]: https://www.patreon.com/ionicabizau
|
|
301
|
-
[amazon]:
|
|
179
|
+
[amazon]: https://amzn.eu/hRo9sIZ
|
|
302
180
|
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
|
package/js/main.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
$(document).ready(function () {
|
|
4
2
|
|
|
5
3
|
// Constants
|
|
6
4
|
var ERROR_MESSAGES = {
|
|
7
|
-
NOT_SUPPORTED: "The angle is not supported yet."
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
NOT_SUPPORTED: "The angle is not supported yet."
|
|
6
|
+
, NEGATIVE_ANGLE: "The angle is negative. Put a positive one less than 90 degrees."
|
|
7
|
+
, INVALID_ANGLE: "The angle cannot be 90 degrees or greater."
|
|
10
8
|
};
|
|
11
9
|
|
|
12
10
|
// Globals
|
|
13
|
-
var canvas,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
yO,
|
|
24
|
-
variableInterval,
|
|
25
|
-
delay;
|
|
11
|
+
var canvas, context
|
|
12
|
+
, cWidth, cHeight
|
|
13
|
+
, lineColor = "#2980b9"
|
|
14
|
+
, r
|
|
15
|
+
, marginLeft
|
|
16
|
+
, xP, yP
|
|
17
|
+
, xO, yO
|
|
18
|
+
, variableInterval
|
|
19
|
+
, delay
|
|
20
|
+
;
|
|
26
21
|
|
|
27
22
|
// Utils
|
|
28
23
|
/**
|
|
@@ -49,12 +44,12 @@ $(document).ready(function () {
|
|
|
49
44
|
* @param {Number} timing The interval value.
|
|
50
45
|
* @return {Object} The object containing the variable interval methods.
|
|
51
46
|
*/
|
|
52
|
-
function setVariableInterval(callbackFunc, timing) {
|
|
47
|
+
function setVariableInterval (callbackFunc, timing) {
|
|
53
48
|
var variableInterval = {
|
|
54
49
|
interval: timing,
|
|
55
50
|
callback: callbackFunc,
|
|
56
51
|
stopped: false,
|
|
57
|
-
runLoop: function
|
|
52
|
+
runLoop: function() {
|
|
58
53
|
if (variableInterval.stopped) return;
|
|
59
54
|
|
|
60
55
|
var result = variableInterval.callback.call(variableInterval);
|
|
@@ -65,15 +60,15 @@ $(document).ready(function () {
|
|
|
65
60
|
|
|
66
61
|
variableInterval.loop();
|
|
67
62
|
},
|
|
68
|
-
stop: function
|
|
63
|
+
stop: function() {
|
|
69
64
|
this.stopped = true;
|
|
70
65
|
window.clearTimeout(this.timeout);
|
|
71
66
|
},
|
|
72
|
-
start: function
|
|
67
|
+
start: function() {
|
|
73
68
|
this.stopped = false;
|
|
74
69
|
return this.loop();
|
|
75
70
|
},
|
|
76
|
-
loop: function
|
|
71
|
+
loop: function() {
|
|
77
72
|
this.timeout = window.setTimeout(this.runLoop, this.interval);
|
|
78
73
|
return this;
|
|
79
74
|
}
|
|
@@ -139,7 +134,7 @@ $(document).ready(function () {
|
|
|
139
134
|
* @param {Number} toy The target `y` value.
|
|
140
135
|
* @return {undefined}
|
|
141
136
|
*/
|
|
142
|
-
function canvasArrow(context, fromx, fromy, tox, toy)
|
|
137
|
+
function canvasArrow(context, fromx, fromy, tox, toy){
|
|
143
138
|
context.beginPath();
|
|
144
139
|
var headlen = 5;
|
|
145
140
|
var angle = Math.atan2(toy - fromy, tox - fromx);
|
|
@@ -167,7 +162,7 @@ $(document).ready(function () {
|
|
|
167
162
|
context = canvas.getContext('2d');
|
|
168
163
|
|
|
169
164
|
context.save();
|
|
170
|
-
context.scale(1
|
|
165
|
+
context.scale(1,-1);
|
|
171
166
|
context.translate(300, -300);
|
|
172
167
|
|
|
173
168
|
cWidth = canvas.width;
|
|
@@ -195,6 +190,7 @@ $(document).ready(function () {
|
|
|
195
190
|
line(-200, 200, -200, -200, 2, "#c0392b");
|
|
196
191
|
}
|
|
197
192
|
|
|
193
|
+
|
|
198
194
|
/**
|
|
199
195
|
* draw
|
|
200
196
|
* Starts drawing the things.
|
|
@@ -209,9 +205,10 @@ $(document).ready(function () {
|
|
|
209
205
|
variableInterval.stop();
|
|
210
206
|
}
|
|
211
207
|
|
|
212
|
-
var angle = parseFloat($("#angleValue").val())
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
var angle = parseFloat($("#angleValue").val())
|
|
209
|
+
, err = badAngle(angle)
|
|
210
|
+
, A = null
|
|
211
|
+
;
|
|
215
212
|
|
|
216
213
|
if (err) {
|
|
217
214
|
return showError(err);
|
|
@@ -233,7 +230,7 @@ $(document).ready(function () {
|
|
|
233
230
|
|
|
234
231
|
// Another hack.
|
|
235
232
|
if (angle > 84.7) {
|
|
236
|
-
angle = 84.7
|
|
233
|
+
angle = 84.7
|
|
237
234
|
}
|
|
238
235
|
|
|
239
236
|
// Draw the lines
|
|
@@ -255,7 +252,7 @@ $(document).ready(function () {
|
|
|
255
252
|
$("#angleValue").focus();
|
|
256
253
|
|
|
257
254
|
// Keyboard shortcuts
|
|
258
|
-
$(document).on("keydown", function
|
|
255
|
+
$(document).on("keydown", function(e) {
|
|
259
256
|
|
|
260
257
|
// SHIFT ==> Draw
|
|
261
258
|
if (e.keyCode === 16) {
|
|
@@ -269,21 +266,21 @@ $(document).ready(function () {
|
|
|
269
266
|
});
|
|
270
267
|
|
|
271
268
|
// Draw
|
|
272
|
-
$("#angleValue").on("keydown", function
|
|
273
|
-
if
|
|
269
|
+
$("#angleValue").on("keydown", function(evt) {
|
|
270
|
+
if(evt.keyCode === 13) {
|
|
274
271
|
$("#drawButton").click();
|
|
275
272
|
}
|
|
276
273
|
});
|
|
277
274
|
|
|
278
275
|
// Reset button
|
|
279
|
-
$("#resetButton").on("click", function
|
|
276
|
+
$("#resetButton").on("click", function() {
|
|
280
277
|
$("#myCanvas").remove();
|
|
281
278
|
$("article .container").append("<canvas id='myCanvas' width='600' height='600'></canvas>");
|
|
282
279
|
init();
|
|
283
280
|
});
|
|
284
281
|
|
|
285
282
|
// Download button
|
|
286
|
-
$(".btn-download").on("click", function
|
|
283
|
+
$(".btn-download").on("click", function() {
|
|
287
284
|
var imageLink = canvas.toDataURL();
|
|
288
285
|
window.open(imageLink);
|
|
289
286
|
});
|
|
@@ -305,31 +302,40 @@ $(document).ready(function () {
|
|
|
305
302
|
|
|
306
303
|
angle = Math.abs(angle);
|
|
307
304
|
|
|
308
|
-
var data = [
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
305
|
+
var data = [
|
|
306
|
+
{
|
|
307
|
+
"angles": [0, 6, 10, 18, 30, 36, 40, 45, 50, 60, 70, 54],
|
|
308
|
+
"value": 20
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"angles": [2, 55, 58, 62, 63, 65],
|
|
312
|
+
"value": 100
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"angles": [3, 42, 15],
|
|
316
|
+
"value": 16
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"angles": [20, 22, 23, 29, 47, 51, 52, 57, 45.8],
|
|
320
|
+
"value": 130
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
"angles": [11, 48],
|
|
324
|
+
"value": 80
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
"angles": [7],
|
|
328
|
+
"value": 151
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"angles": [5, 9],
|
|
332
|
+
"value": 410
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"angles": [35, 49],
|
|
336
|
+
"value": 76
|
|
337
|
+
}
|
|
338
|
+
]
|
|
333
339
|
|
|
334
340
|
for (var i in data) {
|
|
335
341
|
if (data[i].angles.indexOf(angle) !== -1) {
|
|
@@ -411,32 +417,34 @@ $(document).ready(function () {
|
|
|
411
417
|
}
|
|
412
418
|
|
|
413
419
|
// First point
|
|
414
|
-
var xA = parseFloat(point.x)
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
420
|
+
var xA = parseFloat(point.x)
|
|
421
|
+
, yA = parseFloat(point.y)
|
|
422
|
+
, m = (yA / (200 + xA))
|
|
423
|
+
, firstP = firstPoint(m, xA, yA)
|
|
424
|
+
;
|
|
418
425
|
|
|
419
426
|
// Draw line
|
|
420
427
|
line(xA, yA, firstP.x, firstP.y, 2, lineColor);
|
|
421
428
|
|
|
422
429
|
// Update variables
|
|
423
430
|
var A = {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
431
|
+
x: xP
|
|
432
|
+
, y: yP
|
|
433
|
+
}
|
|
434
|
+
, B = firstP
|
|
435
|
+
, C = {}
|
|
436
|
+
, R = 200
|
|
437
|
+
, t = 0
|
|
438
|
+
, withTemp = 1000
|
|
439
|
+
, temp = {
|
|
440
|
+
x: A.x.toFixed(7)
|
|
441
|
+
, y: A.y.toFixed(7)
|
|
442
|
+
}
|
|
443
|
+
, pointP = JSON.stringify(temp)
|
|
444
|
+
, L = Math.sqrt(Math.pow((A.x - B.x), 2) + Math.pow((A.y - B.y), 2))
|
|
445
|
+
;
|
|
438
446
|
|
|
439
|
-
variableInterval = setVariableInterval(function
|
|
447
|
+
variableInterval = setVariableInterval(function() {
|
|
440
448
|
interval = this.interval;
|
|
441
449
|
|
|
442
450
|
// Get the next point
|
|
@@ -444,8 +452,8 @@ $(document).ready(function () {
|
|
|
444
452
|
|
|
445
453
|
// Convert to string the next point
|
|
446
454
|
temp = {
|
|
447
|
-
x: C.x
|
|
448
|
-
|
|
455
|
+
x: C.x
|
|
456
|
+
, y: C.y
|
|
449
457
|
};
|
|
450
458
|
|
|
451
459
|
var strC = JSON.stringify(temp);
|
|
@@ -464,7 +472,8 @@ $(document).ready(function () {
|
|
|
464
472
|
|
|
465
473
|
if (!drawValue.code) {
|
|
466
474
|
line(B.x, B.y, C.x, C.y, 2, lineColor);
|
|
467
|
-
}
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
468
477
|
if (drawValue.code == 1) {
|
|
469
478
|
variableInterval.stop();
|
|
470
479
|
callback(drawValue.message);
|
|
@@ -488,6 +497,7 @@ $(document).ready(function () {
|
|
|
488
497
|
t++;
|
|
489
498
|
}, delay);
|
|
490
499
|
|
|
500
|
+
|
|
491
501
|
// Point P
|
|
492
502
|
circle(xP, yP, 2, 3, '#003300');
|
|
493
503
|
}
|
|
@@ -508,23 +518,20 @@ $(document).ready(function () {
|
|
|
508
518
|
*/
|
|
509
519
|
function M(A, B, R, L) {
|
|
510
520
|
|
|
511
|
-
var xA = A.x,
|
|
512
|
-
|
|
513
|
-
var xB = B.x,
|
|
514
|
-
yB = B.y;
|
|
521
|
+
var xA = A.x, yA = A.y;
|
|
522
|
+
var xB = B.x, yB = B.y;
|
|
515
523
|
|
|
516
524
|
var Ls = Math.pow(L, 2);
|
|
517
525
|
var Rs = Math.pow(R, 2);
|
|
518
526
|
var k = 2 * Rs - Ls;
|
|
519
527
|
|
|
520
528
|
var a = 4 * Math.pow(R, 2);
|
|
521
|
-
var b = -4 * k * yB;
|
|
529
|
+
var b = - 4 * k * yB;
|
|
522
530
|
var c = Math.pow(k, 2) - Math.pow(R, 2) * 4 * Math.pow(xB, 2);
|
|
523
531
|
|
|
524
532
|
var delta = Math.pow(b, 2) - 4 * a * c;
|
|
525
533
|
|
|
526
|
-
var x = 0,
|
|
527
|
-
y = 0;
|
|
534
|
+
var x = 0, y = 0;
|
|
528
535
|
var FIXED = 20;
|
|
529
536
|
|
|
530
537
|
if (xB != 0) {
|
|
@@ -532,21 +539,23 @@ $(document).ready(function () {
|
|
|
532
539
|
x = ((k - 2 * y * yB) / (2 * xB)).toFixed(FIXED);
|
|
533
540
|
|
|
534
541
|
// TODO: Is this the best method?
|
|
535
|
-
var yR = Math.round(y * 100)
|
|
536
|
-
var xR = Math.round(x * 100)
|
|
537
|
-
var xAR = Math.round(xA * 100)
|
|
538
|
-
var yAR = Math.round(yA * 100)
|
|
542
|
+
var yR = Math.round(y * 100)/100;
|
|
543
|
+
var xR = Math.round(x * 100)/100;
|
|
544
|
+
var xAR = Math.round(xA * 100)/100;
|
|
545
|
+
var yAR = Math.round(yA * 100)/100;
|
|
539
546
|
|
|
540
547
|
if (yR == yAR && xR == xAR) {
|
|
541
548
|
y = ((-b - Math.sqrt(delta)) / (2 * a)).toFixed(FIXED);
|
|
542
549
|
x = ((k - 2 * y * yB) / (2 * xB)).toFixed(FIXED);
|
|
543
550
|
}
|
|
544
|
-
}
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
545
553
|
// TODO: There can be other cases.
|
|
546
554
|
if (round(xB, 0) == 0 && round(yB, 0) == 200) {
|
|
547
555
|
x = 200;
|
|
548
556
|
y = 0;
|
|
549
|
-
}
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
550
559
|
x = -200;
|
|
551
560
|
y = 0;
|
|
552
561
|
}
|
|
@@ -586,8 +595,8 @@ $(document).ready(function () {
|
|
|
586
595
|
var yM = m * (200 + xM);
|
|
587
596
|
|
|
588
597
|
return {
|
|
589
|
-
"x":
|
|
590
|
-
"y":
|
|
598
|
+
"x":xM,
|
|
599
|
+
"y":yM
|
|
591
600
|
};
|
|
592
601
|
}
|
|
593
602
|
|
|
@@ -602,13 +611,13 @@ $(document).ready(function () {
|
|
|
602
611
|
// 1 PI ........... 180 deg
|
|
603
612
|
// x PI ........... angle deg
|
|
604
613
|
|
|
605
|
-
var angleRad = Math.PI * angle / 180;
|
|
614
|
+
var angleRad = (Math.PI * angle) / 180;
|
|
606
615
|
var tg = Math.tan(angleRad);
|
|
607
616
|
var yA = xA * tg;
|
|
608
617
|
|
|
609
618
|
return {
|
|
610
|
-
x: xA - 200
|
|
611
|
-
|
|
619
|
+
x: xA - 200
|
|
620
|
+
, y: yA
|
|
612
621
|
};
|
|
613
622
|
}
|
|
614
623
|
|
|
@@ -627,7 +636,7 @@ $(document).ready(function () {
|
|
|
627
636
|
if (n1 || n2) {
|
|
628
637
|
return {
|
|
629
638
|
"message": "There is a NaN.",
|
|
630
|
-
"code": 1
|
|
639
|
+
"code": 1,
|
|
631
640
|
};
|
|
632
641
|
}
|
|
633
642
|
|
|
@@ -637,17 +646,17 @@ $(document).ready(function () {
|
|
|
637
646
|
if (!(sum1 <= R && sum2 <= R)) {
|
|
638
647
|
return {
|
|
639
648
|
"message": "Something is wrong. Sum1 or sum2 is higher than R^2.",
|
|
640
|
-
"code": 2
|
|
649
|
+
"code": 2,
|
|
641
650
|
};
|
|
642
651
|
}
|
|
643
652
|
|
|
644
653
|
// Default, return true
|
|
645
654
|
return {
|
|
646
|
-
"message": "That's correct. Let's draw the line!"
|
|
655
|
+
"message": "That's correct. Let's draw the line!",
|
|
647
656
|
};
|
|
648
657
|
}
|
|
649
658
|
|
|
650
659
|
init();
|
|
651
660
|
$("html").hide().fadeIn(1000);
|
|
652
661
|
handlers();
|
|
653
|
-
});
|
|
662
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circular-mirror",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Simulates the reflections of a ray of light inside of a circular mirror.",
|
|
5
5
|
"main": "js/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"cli.js",
|
|
34
34
|
"index.js",
|
|
35
35
|
"index.d.ts",
|
|
36
|
-
"package-lock.json",
|
|
37
36
|
"bloggify.js",
|
|
38
37
|
"bloggify.json",
|
|
39
38
|
"bloggify/"
|