forked from DmitryBaranovskiy/raphael
-
Notifications
You must be signed in to change notification settings - Fork 1
/
raphael-src.html
5985 lines (5985 loc) · 741 KB
/
raphael-src.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!-- Generated with Dr.js -->
<html lang="en"><head><meta charset="utf-8"><title>raphael.js</title><link rel="stylesheet" href="dr.css"></head><body id="src-dr-js"><code id="L1"><span class="ln">1</span><span class="c">/*
</span></code><code id="L2"><span class="ln">2</span><span class="c"><span class="s"> * </span>Raphaël <span class="d">2.0</span><span class="d">.0</span><span class="s"> - </span>JavaScript Vector Library
</span></code><code id="L3"><span class="ln">3</span><span class="c"> *
</span></code><code id="L4"><span class="ln">4</span><span class="c"><span class="s"> * </span>Copyright (c) <span class="d">2011</span> Dmitry Baranovskiy (http:<span class="c">//raphaeljs.com)</span>
</span></code><code id="L5"><span class="ln">5</span><span class="c"><span class="s"> * </span>Copyright (c) <span class="d">2011</span> Sencha Labs (http:<span class="c">//sencha.com)</span>
</span></code><code id="L6"><span class="ln">6</span><span class="c"><span class="s"> * </span>Licensed under the MIT (http:<span class="c">//raphaeljs.com/license.html) license.</span>
</span></code><code id="L7"><span class="ln">7</span><span class="c"> */</span>
</code><code id="L8"><span class="ln">8</span>(<b>function</b> () {
</code><code id="L9"><span class="ln">9</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L10"><span class="ln">10</span><span class="c"> <span class="s"> * </span>Raphael
</span></code><code id="L11"><span class="ln">11</span><span class="c"> [ method ]
</span></code><code id="L12"><span class="ln">12</span><span class="c"> **
</span></code><code id="L13"><span class="ln">13</span><span class="c"> <span class="s"> * </span>Creates a canvas object on which to draw.
</span></code><code id="L14"><span class="ln">14</span><span class="c"> <span class="s"> * </span>You must <b>do</b> <b>this</b> first, as all future calls to drawing methods
</span></code><code id="L15"><span class="ln">15</span><span class="c"> <span class="s"> * </span>from <b>this</b> instance will be bound to <b>this</b> canvas.
</span></code><code id="L16"><span class="ln">16</span><span class="c"> > Parameters
</span></code><code id="L17"><span class="ln">17</span><span class="c"> **
</span></code><code id="L18"><span class="ln">18</span><span class="c"> <span class="s"> - </span>container (HTMLElement|string) DOM element or its ID which is going to be a parent <b>for</b> drawing surface
</span></code><code id="L19"><span class="ln">19</span><span class="c"> <span class="s"> - </span>width (number)
</span></code><code id="L20"><span class="ln">20</span><span class="c"> <span class="s"> - </span>height (number)
</span></code><code id="L21"><span class="ln">21</span><span class="c"> <span class="s"> * </span>or
</span></code><code id="L22"><span class="ln">22</span><span class="c"> <span class="s"> - </span>x (number)
</span></code><code id="L23"><span class="ln">23</span><span class="c"> <span class="s"> - </span>y (number)
</span></code><code id="L24"><span class="ln">24</span><span class="c"> <span class="s"> - </span>width (number)
</span></code><code id="L25"><span class="ln">25</span><span class="c"> <span class="s"> - </span>height (number)
</span></code><code id="L26"><span class="ln">26</span><span class="c"> <span class="s"> * </span>or
</span></code><code id="L27"><span class="ln">27</span><span class="c"> <span class="s"> - </span>all (array) (first <span class="d">3</span> or <span class="d">4</span> elements <b>in</b> the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions <b>in</b> format {type: type, <attributes>})
</span></code><code id="L28"><span class="ln">28</span><span class="c"> <span class="s"> * </span>or
</span></code><code id="L29"><span class="ln">29</span><span class="c"> <span class="s"> - </span>onReadyCallback (<b>function</b>) <b>function</b> that is going to be called on DOM ready event. You can also subscribe to <b>this</b> event via Eve’s “DOMLoad” event. In <b>this</b> <b>case</b> method returns `<b>undefined</b>`.
</span></code><code id="L30"><span class="ln">30</span><span class="c"> <span class="s"> = </span>(object) @Paper
</span></code><code id="L31"><span class="ln">31</span><span class="c"> > Usage
</span></code><code id="L32"><span class="ln">32</span><span class="c"> <span class="s"> | </span><span class="c">// Each of the following examples create a canvas</span>
</span></code><code id="L33"><span class="ln">33</span><span class="c"> <span class="s"> | </span><span class="c">// that is 320px wide by 200px high.</span>
</span></code><code id="L34"><span class="ln">34</span><span class="c"> <span class="s"> | </span><span class="c">// Canvas is created at the viewport’s <span class="d">10</span>,<span class="d">50</span> coordinate.</span>
</span></code><code id="L35"><span class="ln">35</span><span class="c"> <span class="s"> | </span><b>var</b> paper<span class="s"> = </span>Raphael(<span class="d">10</span>, <span class="d">50</span>, <span class="d">320</span>, <span class="d">200</span>);
</span></code><code id="L36"><span class="ln">36</span><span class="c"> <span class="s"> | </span><span class="c">// Canvas is created at the top left corner of the #notepad element</span>
</span></code><code id="L37"><span class="ln">37</span><span class="c"> <span class="s"> | </span><span class="c">// (or its top right corner <b>in</b> dir=<i>"rtl"</i> elements)</span>
</span></code><code id="L38"><span class="ln">38</span><span class="c"> <span class="s"> | </span><b>var</b> paper<span class="s"> = </span>Raphael(document.getElementById(<i>"notepad"</i>), <span class="d">320</span>, <span class="d">200</span>);
</span></code><code id="L39"><span class="ln">39</span><span class="c"> <span class="s"> | </span><span class="c">// Same as above</span>
</span></code><code id="L40"><span class="ln">40</span><span class="c"> <span class="s"> | </span><b>var</b> paper<span class="s"> = </span>Raphael(<i>"notepad"</i>, <span class="d">320</span>, <span class="d">200</span>);
</span></code><code id="L41"><span class="ln">41</span><span class="c"> <span class="s"> | </span><span class="c">// Image dump</span>
</span></code><code id="L42"><span class="ln">42</span><span class="c"> <span class="s"> | </span><b>var</b> set<span class="s"> = </span>Raphael([<i>"notepad"</i>, <span class="d">320</span>, <span class="d">200</span>, {
</span></code><code id="L43"><span class="ln">43</span><span class="c"> <span class="s"> | </span> type: <i>"rect"</i>,
</span></code><code id="L44"><span class="ln">44</span><span class="c"> <span class="s"> | </span> x: <span class="d">10</span>,
</span></code><code id="L45"><span class="ln">45</span><span class="c"> <span class="s"> | </span> y: <span class="d">10</span>,
</span></code><code id="L46"><span class="ln">46</span><span class="c"> <span class="s"> | </span> width: <span class="d">25</span>,
</span></code><code id="L47"><span class="ln">47</span><span class="c"> <span class="s"> | </span> height: <span class="d">25</span>,
</span></code><code id="L48"><span class="ln">48</span><span class="c"> <span class="s"> | </span> stroke: <i>"#f00"</i>
</span></code><code id="L49"><span class="ln">49</span><span class="c"> <span class="s"> | </span>}, {
</span></code><code id="L50"><span class="ln">50</span><span class="c"> <span class="s"> | </span> type: <i>"text"</i>,
</span></code><code id="L51"><span class="ln">51</span><span class="c"> <span class="s"> | </span> x: <span class="d">30</span>,
</span></code><code id="L52"><span class="ln">52</span><span class="c"> <span class="s"> | </span> y: <span class="d">40</span>,
</span></code><code id="L53"><span class="ln">53</span><span class="c"> <span class="s"> | </span> text: <i>"Dump"</i>
</span></code><code id="L54"><span class="ln">54</span><span class="c"> <span class="s"> | </span>}]);
</span></code><code id="L55"><span class="ln">55</span><span class="c"> \*/</span>
</code><code id="L56"><span class="ln">56</span> <b>function</b> R(first) {
</code><code id="L57"><span class="ln">57</span> <b>if</b> (R.is(first, <i>"<b>function</b>"</i>)) {
</code><code id="L58"><span class="ln">58</span> <b>return</b> eve.on(<i>"DOMload"</i>, first);
</code><code id="L59"><span class="ln">59</span> } <b>else</b> <b>if</b> (R.is(first, array)) {
</code><code id="L60"><span class="ln">60</span> <b>var</b> a<span class="s"> = </span>first,
</code><code id="L61"><span class="ln">61</span> cnv<span class="s"> = </span>create[apply](R, a.splice(<span class="d">0</span>, <span class="d">3</span><span class="s"> + </span>R.is(a[<span class="d">0</span>], nu))),
</code><code id="L62"><span class="ln">62</span> res<span class="s"> = </span>cnv.set(),
</code><code id="L63"><span class="ln">63</span> i<span class="s"> = </span><span class="d">0</span>,
</code><code id="L64"><span class="ln">64</span> ii<span class="s"> = </span>a.length,
</code><code id="L65"><span class="ln">65</span> j;
</code><code id="L66"><span class="ln">66</span> <b>for</b> (; i < ii; i++) {
</code><code id="L67"><span class="ln">67</span> j<span class="s"> = </span>a[i]<span class="s"> || </span>{};
</code><code id="L68"><span class="ln">68</span> elements[has](j.type)<span class="s"> && </span>res.push(cnv[j.type]().attr(j));
</code><code id="L69"><span class="ln">69</span> }
</code><code id="L70"><span class="ln">70</span> <b>return</b> res;
</code><code id="L71"><span class="ln">71</span> }
</code><code id="L72"><span class="ln">72</span> <b>return</b> create[apply](R, arguments);
</code><code id="L73"><span class="ln">73</span> }
</code><code id="L74"><span class="ln">74</span> R.version<span class="s"> = </span><i>"<span class="d">2.0</span><span class="d">.0</span>"</i>;
</code><code id="L75"><span class="ln">75</span> <b>var</b> separator<span class="s"> = </span>/[, ]+/,
</code><code id="L76"><span class="ln">76</span> elements<span class="s"> = </span>{circle: <span class="d">1</span>, rect: <span class="d">1</span>, path: <span class="d">1</span>, ellipse: <span class="d">1</span>, text: <span class="d">1</span>, image: <span class="d">1</span>},
</code><code id="L77"><span class="ln">77</span> formatrg<span class="s"> = </span>/\{(\d+)\}/g,
</code><code id="L78"><span class="ln">78</span> proto<span class="s"> = </span><i>"prototype"</i>,
</code><code id="L79"><span class="ln">79</span> has<span class="s"> = </span><i>"hasOwnProperty"</i>,
</code><code id="L80"><span class="ln">80</span> g<span class="s"> = </span>{
</code><code id="L81"><span class="ln">81</span> doc: document,
</code><code id="L82"><span class="ln">82</span> win: window
</code><code id="L83"><span class="ln">83</span> },
</code><code id="L84"><span class="ln">84</span> oldRaphael<span class="s"> = </span>{
</code><code id="L85"><span class="ln">85</span> was: Object.prototype[has].call(g.win, <i>"Raphael"</i>),
</code><code id="L86"><span class="ln">86</span> is: g.win.Raphael
</code><code id="L87"><span class="ln">87</span> },
</code><code id="L88"><span class="ln">88</span> Paper<span class="s"> = </span><b>function</b> () {},
</code><code id="L89"><span class="ln">89</span> paperproto,
</code><code id="L90"><span class="ln">90</span> appendChild<span class="s"> = </span><i>"appendChild"</i>,
</code><code id="L91"><span class="ln">91</span> apply<span class="s"> = </span><i>"apply"</i>,
</code><code id="L92"><span class="ln">92</span> concat<span class="s"> = </span><i>"concat"</i>,
</code><code id="L93"><span class="ln">93</span> supportsTouch<span class="s"> = </span><i>"createTouch"</i> <b>in</b> g.doc,
</code><code id="L94"><span class="ln">94</span> E<span class="s"> = </span><i>""</i>,
</code><code id="L95"><span class="ln">95</span> S<span class="s"> = </span><i>" "</i>,
</code><code id="L96"><span class="ln">96</span> Str<span class="s"> = </span>String,
</code><code id="L97"><span class="ln">97</span> split<span class="s"> = </span><i>"split"</i>,
</code><code id="L98"><span class="ln">98</span> events<span class="s"> = </span><i>"click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"</i>.split(S),
</code><code id="L99"><span class="ln">99</span> touchMap<span class="s"> = </span>{
</code><code id="L100"><span class="ln">100</span> mousedown: <i>"touchstart"</i>,
</code><code id="L101"><span class="ln">101</span> mousemove: <i>"touchmove"</i>,
</code><code id="L102"><span class="ln">102</span> mouseup: <i>"touchend"</i>
</code><code id="L103"><span class="ln">103</span> },
</code><code id="L104"><span class="ln">104</span> lowerCase<span class="s"> = </span>Str.prototype.toLowerCase,
</code><code id="L105"><span class="ln">105</span> math<span class="s"> = </span>Math,
</code><code id="L106"><span class="ln">106</span> mmax<span class="s"> = </span>math.max,
</code><code id="L107"><span class="ln">107</span> mmin<span class="s"> = </span>math.min,
</code><code id="L108"><span class="ln">108</span> abs<span class="s"> = </span>math.abs,
</code><code id="L109"><span class="ln">109</span> pow<span class="s"> = </span>math.pow,
</code><code id="L110"><span class="ln">110</span> PI<span class="s"> = </span>math.PI,
</code><code id="L111"><span class="ln">111</span> nu<span class="s"> = </span><i>"number"</i>,
</code><code id="L112"><span class="ln">112</span> string<span class="s"> = </span><i>"string"</i>,
</code><code id="L113"><span class="ln">113</span> array<span class="s"> = </span><i>"array"</i>,
</code><code id="L114"><span class="ln">114</span> toString<span class="s"> = </span><i>"toString"</i>,
</code><code id="L115"><span class="ln">115</span> fillString<span class="s"> = </span><i>"fill"</i>,
</code><code id="L116"><span class="ln">116</span> objectToString<span class="s"> = </span>Object.prototype.toString,
</code><code id="L117"><span class="ln">117</span> paper<span class="s"> = </span>{},
</code><code id="L118"><span class="ln">118</span> push<span class="s"> = </span><i>"push"</i>,
</code><code id="L119"><span class="ln">119</span> ISURL<span class="s"> = </span>/^url\([<i>'"]?([^\)]+?)['</i>"]?\)$/i,
</code><code id="L120"><span class="ln">120</span> colourRegExp<span class="s"> = </span>/^\s*((#[a-f\d]{<span class="d">6</span>})|(#[a-f\d]{<span class="d">3</span>})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
</code><code id="L121"><span class="ln">121</span> isnan<span class="s"> = </span>{<i>"NaN"</i>: <span class="d">1</span>, <i>"Infinity"</i>: <span class="d">1</span>, <i>"-Infinity"</i>: <span class="d">1</span>},
</code><code id="L122"><span class="ln">122</span> bezierrg<span class="s"> = </span>/^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
</code><code id="L123"><span class="ln">123</span> round<span class="s"> = </span>math.round,
</code><code id="L124"><span class="ln">124</span> setAttribute<span class="s"> = </span><i>"setAttribute"</i>,
</code><code id="L125"><span class="ln">125</span> toFloat<span class="s"> = </span>parseFloat,
</code><code id="L126"><span class="ln">126</span> toInt<span class="s"> = </span>parseInt,
</code><code id="L127"><span class="ln">127</span> ms<span class="s"> = </span><i>" progid:DXImageTransform.Microsoft"</i>,
</code><code id="L128"><span class="ln">128</span> upperCase<span class="s"> = </span>Str.prototype.toUpperCase,
</code><code id="L129"><span class="ln">129</span> availableAttrs<span class="s"> = </span>{<i>"arrow-end"</i>: <i>"none"</i>, <i>"arrow-start"</i>: <i>"none"</i>, blur: <span class="d">0</span>, <i>"clip-rect"</i>: <i>"<span class="d">0</span> <span class="d">0</span> <span class="d">1e9</span> <span class="d">1e9</span>"</i>, cursor: <i>"<b>default</b>"</i>, cx: <span class="d">0</span>, cy: <span class="d">0</span>, fill: <i>"#fff"</i>, <i>"fill-opacity"</i>: <span class="d">1</span>, font: <i>'10px "Arial"'</i>, <i>"font-family"</i>: <i>'"Arial"'</i>, <i>"font-size"</i>: <i>"<span class="d">10</span>"</i>, <i>"font-style"</i>: <i>"normal"</i>, <i>"font-weight"</i>: <span class="d">400</span>, gradient: <span class="d">0</span>, height: <span class="d">0</span>, href: <i>"http:<span class="c">//raphaeljs.com/"</i>, opacity: <span class="d">1</span>, path: <i>"M0,<span class="d">0</span>"</i>, r: <span class="d">0</span>, rx: <span class="d">0</span>, ry: <span class="d">0</span>, src: <i>""</i>, stroke: <i>"#<span class="d">000</span>"</i>, <i>"stroke-dasharray"</i>: <i>""</i>, <i>"stroke-linecap"</i>: <i>"butt"</i>, <i>"stroke-linejoin"</i>: <i>"butt"</i>, <i>"stroke-miterlimit"</i>: <span class="d">0</span>, <i>"stroke-opacity"</i>: <span class="d">1</span>, <i>"stroke-width"</i>: <span class="d">1</span>, target: <i>"_blank"</i>, <i>"text-anchor"</i>: <i>"middle"</i>, title: <i>"Raphael"</i>, transform: <i>""</i>, width: <span class="d">0</span>, x: <span class="d">0</span>, y: <span class="d">0</span>},</span>
</code><code id="L130"><span class="ln">130</span> availableAnimAttrs<span class="s"> = </span>{blur: nu, <i>"clip-rect"</i>: <i>"csv"</i>, cx: nu, cy: nu, fill: <i>"colour"</i>, <i>"fill-opacity"</i>: nu, <i>"font-size"</i>: nu, height: nu, opacity: nu, path: <i>"path"</i>, r: nu, rx: nu, ry: nu, stroke: <i>"colour"</i>, <i>"stroke-opacity"</i>: nu, <i>"stroke-width"</i>: nu, transform: <i>"transform"</i>, width: nu, x: nu, y: nu},
</code><code id="L131"><span class="ln">131</span> commaSpaces<span class="s"> = </span>/\s*,\s*/,
</code><code id="L132"><span class="ln">132</span> hsrg<span class="s"> = </span>{hs: <span class="d">1</span>, rg: <span class="d">1</span>},
</code><code id="L133"><span class="ln">133</span> p2s<span class="s"> = </span>/,?([achlmqrstvxz]),?/gi,
</code><code id="L134"><span class="ln">134</span> pathCommand<span class="s"> = </span>/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
</code><code id="L135"><span class="ln">135</span> tCommand<span class="s"> = </span>/([rstm])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
</code><code id="L136"><span class="ln">136</span> pathValues<span class="s"> = </span>/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,
</code><code id="L137"><span class="ln">137</span> radial_gradient<span class="s"> = </span>/^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
</code><code id="L138"><span class="ln">138</span> sortByKey<span class="s"> = </span><b>function</b> (a, b) {
</code><code id="L139"><span class="ln">139</span> <b>return</b> a.key<span class="s"> - </span>b.key;
</code><code id="L140"><span class="ln">140</span> },
</code><code id="L141"><span class="ln">141</span> sortByNumber<span class="s"> = </span><b>function</b> (a, b) {
</code><code id="L142"><span class="ln">142</span> <b>return</b> a<span class="s"> - </span>b;
</code><code id="L143"><span class="ln">143</span> },
</code><code id="L144"><span class="ln">144</span> fun<span class="s"> = </span><b>function</b> () {},
</code><code id="L145"><span class="ln">145</span> pipe<span class="s"> = </span><b>function</b> (x) {
</code><code id="L146"><span class="ln">146</span> <b>return</b> x;
</code><code id="L147"><span class="ln">147</span> },
</code><code id="L148"><span class="ln">148</span> rectPath<span class="s"> = </span><b>function</b> (x, y, w, h, r) {
</code><code id="L149"><span class="ln">149</span> <b>if</b> (r) {
</code><code id="L150"><span class="ln">150</span> <b>return</b> [[<i>"M"</i>, x<span class="s"> + </span>r, y], [<i>"l"</i>, w<span class="s"> - </span>r<span class="s"> * </span><span class="d">2</span>, <span class="d">0</span>], [<i>"a"</i>, r, r, <span class="d">0</span>, <span class="d">0</span>, <span class="d">1</span>, r, r], [<i>"l"</i>, <span class="d">0</span>, h<span class="s"> - </span>r<span class="s"> * </span><span class="d">2</span>], [<i>"a"</i>, r, r, <span class="d">0</span>, <span class="d">0</span>, <span class="d">1</span>, -r, r], [<i>"l"</i>, r<span class="s"> * </span><span class="d">2</span><span class="s"> - </span>w, <span class="d">0</span>], [<i>"a"</i>, r, r, <span class="d">0</span>, <span class="d">0</span>, <span class="d">1</span>, -r, -r], [<i>"l"</i>, <span class="d">0</span>, r<span class="s"> * </span><span class="d">2</span><span class="s"> - </span>h], [<i>"a"</i>, r, r, <span class="d">0</span>, <span class="d">0</span>, <span class="d">1</span>, r, -r], [<i>"z"</i>]];
</code><code id="L151"><span class="ln">151</span> }
</code><code id="L152"><span class="ln">152</span> <b>return</b> [[<i>"M"</i>, x, y], [<i>"l"</i>, w, <span class="d">0</span>], [<i>"l"</i>, <span class="d">0</span>, h], [<i>"l"</i>, -w, <span class="d">0</span>], [<i>"z"</i>]];
</code><code id="L153"><span class="ln">153</span> },
</code><code id="L154"><span class="ln">154</span> ellipsePath<span class="s"> = </span><b>function</b> (x, y, rx, ry) {
</code><code id="L155"><span class="ln">155</span> <b>if</b> (ry<span class="s"> == </span><b>null</b>) {
</code><code id="L156"><span class="ln">156</span> ry<span class="s"> = </span>rx;
</code><code id="L157"><span class="ln">157</span> }
</code><code id="L158"><span class="ln">158</span> <b>return</b> [[<i>"M"</i>, x, y], [<i>"m"</i>, <span class="d">0</span>, -ry], [<i>"a"</i>, rx, ry, <span class="d">0</span>, <span class="d">1</span>, <span class="d">1</span>, <span class="d">0</span>, <span class="d">2</span><span class="s"> * </span>ry], [<i>"a"</i>, rx, ry, <span class="d">0</span>, <span class="d">1</span>, <span class="d">1</span>, <span class="d">0</span>, -<span class="d">2</span><span class="s"> * </span>ry], [<i>"z"</i>]];
</code><code id="L159"><span class="ln">159</span> },
</code><code id="L160"><span class="ln">160</span> getPath<span class="s"> = </span>{
</code><code id="L161"><span class="ln">161</span> path: <b>function</b> (el) {
</code><code id="L162"><span class="ln">162</span> <b>return</b> el.attr(<i>"path"</i>);
</code><code id="L163"><span class="ln">163</span> },
</code><code id="L164"><span class="ln">164</span> circle: <b>function</b> (el) {
</code><code id="L165"><span class="ln">165</span> <b>var</b> a<span class="s"> = </span>el.attrs;
</code><code id="L166"><span class="ln">166</span> <b>return</b> ellipsePath(a.cx, a.cy, a.r);
</code><code id="L167"><span class="ln">167</span> },
</code><code id="L168"><span class="ln">168</span> ellipse: <b>function</b> (el) {
</code><code id="L169"><span class="ln">169</span> <b>var</b> a<span class="s"> = </span>el.attrs;
</code><code id="L170"><span class="ln">170</span> <b>return</b> ellipsePath(a.cx, a.cy, a.rx, a.ry);
</code><code id="L171"><span class="ln">171</span> },
</code><code id="L172"><span class="ln">172</span> rect: <b>function</b> (el) {
</code><code id="L173"><span class="ln">173</span> <b>var</b> a<span class="s"> = </span>el.attrs;
</code><code id="L174"><span class="ln">174</span> <b>return</b> rectPath(a.x, a.y, a.width, a.height, a.r);
</code><code id="L175"><span class="ln">175</span> },
</code><code id="L176"><span class="ln">176</span> image: <b>function</b> (el) {
</code><code id="L177"><span class="ln">177</span> <b>var</b> a<span class="s"> = </span>el.attrs;
</code><code id="L178"><span class="ln">178</span> <b>return</b> rectPath(a.x, a.y, a.width, a.height);
</code><code id="L179"><span class="ln">179</span> },
</code><code id="L180"><span class="ln">180</span> text: <b>function</b> (el) {
</code><code id="L181"><span class="ln">181</span> <b>var</b> bbox<span class="s"> = </span>el._getBBox();
</code><code id="L182"><span class="ln">182</span> <b>return</b> rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
</code><code id="L183"><span class="ln">183</span> }
</code><code id="L184"><span class="ln">184</span> },
</code><code id="L185"><span class="ln">185</span> mapPath<span class="s"> = </span><b>function</b> (path, matrix) {
</code><code id="L186"><span class="ln">186</span> <b>if</b> (!matrix) {
</code><code id="L187"><span class="ln">187</span> <b>return</b> path;
</code><code id="L188"><span class="ln">188</span> }
</code><code id="L189"><span class="ln">189</span> <b>var</b> x, y, i, j, pathi;
</code><code id="L190"><span class="ln">190</span> path<span class="s"> = </span>path2curve(path);
</code><code id="L191"><span class="ln">191</span> <b>for</b> (i<span class="s"> = </span><span class="d">0</span>, ii<span class="s"> = </span>path.length; i < ii; i++) {
</code><code id="L192"><span class="ln">192</span> pathi<span class="s"> = </span>path[i];
</code><code id="L193"><span class="ln">193</span> <b>for</b> (j<span class="s"> = </span><span class="d">1</span>, jj<span class="s"> = </span>pathi.length; j < jj; j += <span class="d">2</span>) {
</code><code id="L194"><span class="ln">194</span> x<span class="s"> = </span>matrix.x(pathi[j], pathi[j<span class="s"> + </span><span class="d">1</span>]);
</code><code id="L195"><span class="ln">195</span> y<span class="s"> = </span>matrix.y(pathi[j], pathi[j<span class="s"> + </span><span class="d">1</span>]);
</code><code id="L196"><span class="ln">196</span> pathi[j]<span class="s"> = </span>x;
</code><code id="L197"><span class="ln">197</span> pathi[j<span class="s"> + </span><span class="d">1</span>]<span class="s"> = </span>y;
</code><code id="L198"><span class="ln">198</span> }
</code><code id="L199"><span class="ln">199</span> }
</code><code id="L200"><span class="ln">200</span> <b>return</b> path;
</code><code id="L201"><span class="ln">201</span> };
</code><code id="L202"><span class="ln">202</span>
</code><code id="L203"><span class="ln">203</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L204"><span class="ln">204</span><span class="c"> <span class="s"> * </span>Raphael.type
</span></code><code id="L205"><span class="ln">205</span><span class="c"> [ property (string) ]
</span></code><code id="L206"><span class="ln">206</span><span class="c"> **
</span></code><code id="L207"><span class="ln">207</span><span class="c"> <span class="s"> * </span>Can be “SVG”, “VML” or empty, depending on browser support.
</span></code><code id="L208"><span class="ln">208</span><span class="c"> \*/</span>
</code><code id="L209"><span class="ln">209</span> R.type<span class="s"> = </span>(g.win.SVGAngle<span class="s"> || </span>g.doc.implementation.hasFeature(<i>"http:<span class="c">//www.w3.org/TR/SVG11/feature#BasicStructure"</i>, <i>"<span class="d">1.1</span>"</i>) ? <i>"SVG"</i> : <i>"VML"</i>);</span>
</code><code id="L210"><span class="ln">210</span> <b>if</b> (R.type<span class="s"> == </span><i>"VML"</i>) {
</code><code id="L211"><span class="ln">211</span> <b>var</b> d<span class="s"> = </span>g.doc.createElement(<i>"div"</i>),
</code><code id="L212"><span class="ln">212</span> b;
</code><code id="L213"><span class="ln">213</span> d.innerHTML<span class="s"> = </span><i>'<v:shape adj="<span class="d">1</span>"/>'</i>;
</code><code id="L214"><span class="ln">214</span> b<span class="s"> = </span>d.firstChild;
</code><code id="L215"><span class="ln">215</span> b.style.behavior<span class="s"> = </span><i>"url(#<b>default</b>#VML)"</i>;
</code><code id="L216"><span class="ln">216</span> <b>if</b> (!(b<span class="s"> && </span><b>typeof</b> b.adj<span class="s"> == </span><i>"object"</i>)) {
</code><code id="L217"><span class="ln">217</span> <b>return</b> R.type<span class="s"> = </span>E;
</code><code id="L218"><span class="ln">218</span> }
</code><code id="L219"><span class="ln">219</span> d<span class="s"> = </span><b>null</b>;
</code><code id="L220"><span class="ln">220</span> }
</code><code id="L221"><span class="ln">221</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L222"><span class="ln">222</span><span class="c"> <span class="s"> * </span>Raphael.svg
</span></code><code id="L223"><span class="ln">223</span><span class="c"> [ property (<b>boolean</b>) ]
</span></code><code id="L224"><span class="ln">224</span><span class="c"> **
</span></code><code id="L225"><span class="ln">225</span><span class="c"> <span class="s"> * </span>`<b>true</b>` <b>if</b> browser supports SVG.
</span></code><code id="L226"><span class="ln">226</span><span class="c"> \*/</span>
</code><code id="L227"><span class="ln">227</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L228"><span class="ln">228</span><span class="c"> <span class="s"> * </span>Raphael.vml
</span></code><code id="L229"><span class="ln">229</span><span class="c"> [ property (<b>boolean</b>) ]
</span></code><code id="L230"><span class="ln">230</span><span class="c"> **
</span></code><code id="L231"><span class="ln">231</span><span class="c"> <span class="s"> * </span>`<b>true</b>` <b>if</b> browser supports VML.
</span></code><code id="L232"><span class="ln">232</span><span class="c"> \*/</span>
</code><code id="L233"><span class="ln">233</span> R.svg<span class="s"> = </span>!(R.vml<span class="s"> = </span>R.type<span class="s"> == </span><i>"VML"</i>);
</code><code id="L234"><span class="ln">234</span> paperproto<span class="s"> = </span>Paper.prototype<span class="s"> = </span>R.prototype;
</code><code id="L235"><span class="ln">235</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L236"><span class="ln">236</span><span class="c"> <span class="s"> * </span>Paper.customAttributes
</span></code><code id="L237"><span class="ln">237</span><span class="c"> [ property (object) ]
</span></code><code id="L238"><span class="ln">238</span><span class="c"> **
</span></code><code id="L239"><span class="ln">239</span><span class="c"> <span class="s"> * </span>If you have a set of attributes that you would like to represent
</span></code><code id="L240"><span class="ln">240</span><span class="c"> <span class="s"> * </span>as a <b>function</b> of some number you can <b>do</b> it easily <b>with</b> custom attributes:
</span></code><code id="L241"><span class="ln">241</span><span class="c"> > Usage
</span></code><code id="L242"><span class="ln">242</span><span class="c"> <span class="s"> | </span>paper.customAttributes.hue<span class="s"> = </span><b>function</b> (num) {
</span></code><code id="L243"><span class="ln">243</span><span class="c"> <span class="s"> | </span> num<span class="s"> = </span>num<span class="s"> % </span><span class="d">1</span>;
</span></code><code id="L244"><span class="ln">244</span><span class="c"> <span class="s"> | </span> <b>return</b> {fill: <i>"hsb("</i><span class="s"> + </span>num<span class="s"> + </span><i>", <span class="d">.75</span>, <span class="d">1</span>)"</i>};
</span></code><code id="L245"><span class="ln">245</span><span class="c"> <span class="s"> | </span>};
</span></code><code id="L246"><span class="ln">246</span><span class="c"> <span class="s"> | </span><span class="c">// Custom attribute “hue” will change fill</span>
</span></code><code id="L247"><span class="ln">247</span><span class="c"> <span class="s"> | </span><span class="c">// to be given hue <b>with</b> fixed saturation and brightness.</span>
</span></code><code id="L248"><span class="ln">248</span><span class="c"> <span class="s"> | </span><span class="c">// Now you can use it like <b>this</b>:</span>
</span></code><code id="L249"><span class="ln">249</span><span class="c"> <span class="s"> | </span><b>var</b> c<span class="s"> = </span>paper.circle(<span class="d">10</span>, <span class="d">10</span>, <span class="d">10</span>).attr({hue: <span class="d">.45</span>});
</span></code><code id="L250"><span class="ln">250</span><span class="c"> <span class="s"> | </span><span class="c">// or even like <b>this</b>:</span>
</span></code><code id="L251"><span class="ln">251</span><span class="c"> <span class="s"> | </span>c.animate({hue: <span class="d">1</span>}, <span class="d">1e3</span>);
</span></code><code id="L252"><span class="ln">252</span><span class="c"> <span class="s"> | </span>
</span></code><code id="L253"><span class="ln">253</span><span class="c"> <span class="s"> | </span><span class="c">// You could also create custom attribute</span>
</span></code><code id="L254"><span class="ln">254</span><span class="c"> <span class="s"> | </span><span class="c">// <b>with</b> multiple parameters:</span>
</span></code><code id="L255"><span class="ln">255</span><span class="c"> <span class="s"> | </span>paper.customAttributes.hsb<span class="s"> = </span><b>function</b> (h, s, b) {
</span></code><code id="L256"><span class="ln">256</span><span class="c"> <span class="s"> | </span> <b>return</b> {fill: <i>"hsb("</i><span class="s"> + </span>[h, s, b].join(<i>","</i>)<span class="s"> + </span><i>")"</i>};
</span></code><code id="L257"><span class="ln">257</span><span class="c"> <span class="s"> | </span>};
</span></code><code id="L258"><span class="ln">258</span><span class="c"> <span class="s"> | </span>c.attr({hsb: <i>"<span class="d">.5</span> <span class="d">.8</span> <span class="d">1</span>"</i>});
</span></code><code id="L259"><span class="ln">259</span><span class="c"> <span class="s"> | </span>c.animate({hsb: <i>"<span class="d">1</span> <span class="d">0</span> <span class="d">.5</span>"</i>}, <span class="d">1e3</span>);
</span></code><code id="L260"><span class="ln">260</span><span class="c"> \*/</span>
</code><code id="L261"><span class="ln">261</span> paperproto.customAttributes<span class="s"> = </span>{};
</code><code id="L262"><span class="ln">262</span> R._id<span class="s"> = </span><span class="d">0</span>;
</code><code id="L263"><span class="ln">263</span> R._oid<span class="s"> = </span><span class="d">0</span>;
</code><code id="L264"><span class="ln">264</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L265"><span class="ln">265</span><span class="c"> <span class="s"> * </span>Raphael.fn
</span></code><code id="L266"><span class="ln">266</span><span class="c"> [ property (object) ]
</span></code><code id="L267"><span class="ln">267</span><span class="c"> **
</span></code><code id="L268"><span class="ln">268</span><span class="c"> <span class="s"> * </span>You can add your own method to the canvas. For example <b>if</b> you want to draw a pie chart,
</span></code><code id="L269"><span class="ln">269</span><span class="c"> <span class="s"> * </span>you can create your own pie chart <b>function</b> and ship it as a Raphaël plugin. To <b>do</b> <b>this</b>
</span></code><code id="L270"><span class="ln">270</span><span class="c"> <span class="s"> * </span>you need to extend the `Raphael.fn` object. Please note that you can create your own namespaces
</span></code><code id="L271"><span class="ln">271</span><span class="c"> <span class="s"> * </span>inside the `fn` object — methods will be run <b>in</b> the context of canvas anyway. You should alter
</span></code><code id="L272"><span class="ln">272</span><span class="c"> <span class="s"> * </span>the `fn` object before a Raphaël instance is created, otherwise it will take no effect.
</span></code><code id="L273"><span class="ln">273</span><span class="c"> > Usage
</span></code><code id="L274"><span class="ln">274</span><span class="c"> <span class="s"> | </span>Raphael.fn.arrow<span class="s"> = </span><b>function</b> (x1, y1, x2, y2, size) {
</span></code><code id="L275"><span class="ln">275</span><span class="c"> <span class="s"> | </span> <b>return</b> <b>this</b>.path( ... );
</span></code><code id="L276"><span class="ln">276</span><span class="c"> <span class="s"> | </span>};
</span></code><code id="L277"><span class="ln">277</span><span class="c"> <span class="s"> | </span><span class="c">// or create namespace</span>
</span></code><code id="L278"><span class="ln">278</span><span class="c"> <span class="s"> | </span>Raphael.fn.mystuff<span class="s"> = </span>{
</span></code><code id="L279"><span class="ln">279</span><span class="c"> <span class="s"> | </span> arrow: <b>function</b> () {…},
</span></code><code id="L280"><span class="ln">280</span><span class="c"> <span class="s"> | </span> star: <b>function</b> () {…},
</span></code><code id="L281"><span class="ln">281</span><span class="c"> <span class="s"> | </span> <span class="c">// etc…</span>
</span></code><code id="L282"><span class="ln">282</span><span class="c"> <span class="s"> | </span>};
</span></code><code id="L283"><span class="ln">283</span><span class="c"> <span class="s"> | </span><b>var</b> paper<span class="s"> = </span>Raphael(<span class="d">10</span>, <span class="d">10</span>, <span class="d">630</span>, <span class="d">480</span>);
</span></code><code id="L284"><span class="ln">284</span><span class="c"> <span class="s"> | </span><span class="c">// then use it</span>
</span></code><code id="L285"><span class="ln">285</span><span class="c"> <span class="s"> | </span>paper.arrow(<span class="d">10</span>, <span class="d">10</span>, <span class="d">30</span>, <span class="d">30</span>, <span class="d">5</span>).attr({fill: <i>"#f00"</i>});
</span></code><code id="L286"><span class="ln">286</span><span class="c"> <span class="s"> | </span>paper.mystuff.arrow();
</span></code><code id="L287"><span class="ln">287</span><span class="c"> <span class="s"> | </span>paper.mystuff.star();
</span></code><code id="L288"><span class="ln">288</span><span class="c"> \*/</span>
</code><code id="L289"><span class="ln">289</span> R.fn<span class="s"> = </span>{};
</code><code id="L290"><span class="ln">290</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L291"><span class="ln">291</span><span class="c"> <span class="s"> * </span>Raphael.is
</span></code><code id="L292"><span class="ln">292</span><span class="c"> [ method ]
</span></code><code id="L293"><span class="ln">293</span><span class="c"> **
</span></code><code id="L294"><span class="ln">294</span><span class="c"> <span class="s"> * </span>Handfull replacement <b>for</b> `<b>typeof</b>` operator.
</span></code><code id="L295"><span class="ln">295</span><span class="c"> > Parameters
</span></code><code id="L296"><span class="ln">296</span><span class="c"> <span class="s"> - </span>o (…) any object or primitive
</span></code><code id="L297"><span class="ln">297</span><span class="c"> <span class="s"> - </span>type (string) name of the type, i.e. “string”, “<b>function</b>”, “number”, etc.
</span></code><code id="L298"><span class="ln">298</span><span class="c"> <span class="s"> = </span>(<b>boolean</b>) is given value is of given type
</span></code><code id="L299"><span class="ln">299</span><span class="c"> \*/</span>
</code><code id="L300"><span class="ln">300</span> R.is<span class="s"> = </span><b>function</b> (o, type) {
</code><code id="L301"><span class="ln">301</span> type<span class="s"> = </span>lowerCase.call(type);
</code><code id="L302"><span class="ln">302</span> <b>if</b> (type<span class="s"> == </span><i>"finite"</i>) {
</code><code id="L303"><span class="ln">303</span> <b>return</b> !isnan[has](+o);
</code><code id="L304"><span class="ln">304</span> }
</code><code id="L305"><span class="ln">305</span> <b>return</b> (type<span class="s"> == </span><i>"<b>null</b>"</i><span class="s"> && </span>o<span class="s"> === </span><b>null</b>) ||
</code><code id="L306"><span class="ln">306</span> (type<span class="s"> == </span><b>typeof</b> o) ||
</code><code id="L307"><span class="ln">307</span> (type<span class="s"> == </span><i>"object"</i><span class="s"> && </span>o<span class="s"> === </span>Object(o)) ||
</code><code id="L308"><span class="ln">308</span> (type<span class="s"> == </span><i>"array"</i><span class="s"> && </span>Array.isArray<span class="s"> && </span>Array.isArray(o)) ||
</code><code id="L309"><span class="ln">309</span> objectToString.call(o).slice(<span class="d">8</span>, -<span class="d">1</span>).toLowerCase()<span class="s"> == </span>type;
</code><code id="L310"><span class="ln">310</span> };
</code><code id="L311"><span class="ln">311</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L312"><span class="ln">312</span><span class="c"> <span class="s"> * </span>Raphael.angle
</span></code><code id="L313"><span class="ln">313</span><span class="c"> [ method ]
</span></code><code id="L314"><span class="ln">314</span><span class="c"> **
</span></code><code id="L315"><span class="ln">315</span><span class="c"> <span class="s"> * </span>Returns angle between two or three points
</span></code><code id="L316"><span class="ln">316</span><span class="c"> > Parameters
</span></code><code id="L317"><span class="ln">317</span><span class="c"> <span class="s"> - </span>x1 (number) x coord of first point
</span></code><code id="L318"><span class="ln">318</span><span class="c"> <span class="s"> - </span>y1 (number) y coord of first point
</span></code><code id="L319"><span class="ln">319</span><span class="c"> <span class="s"> - </span>x2 (number) x coord of second point
</span></code><code id="L320"><span class="ln">320</span><span class="c"> <span class="s"> - </span>y2 (number) y coord of second point
</span></code><code id="L321"><span class="ln">321</span><span class="c"> <span class="s"> - </span>x3 (number) #optional x coord of third point
</span></code><code id="L322"><span class="ln">322</span><span class="c"> <span class="s"> - </span>y3 (number) #optional y coord of third point
</span></code><code id="L323"><span class="ln">323</span><span class="c"> <span class="s"> = </span>(number) angle <b>in</b> degrees.
</span></code><code id="L324"><span class="ln">324</span><span class="c"> \*/</span>
</code><code id="L325"><span class="ln">325</span> R.angle<span class="s"> = </span><b>function</b> (x1, y1, x2, y2, x3, y3) {
</code><code id="L326"><span class="ln">326</span> <b>if</b> (x3<span class="s"> == </span><b>null</b>) {
</code><code id="L327"><span class="ln">327</span> <b>var</b> x<span class="s"> = </span>x1<span class="s"> - </span>x2,
</code><code id="L328"><span class="ln">328</span> y<span class="s"> = </span>y1<span class="s"> - </span>y2;
</code><code id="L329"><span class="ln">329</span> <b>if</b> (!x<span class="s"> && </span>!y) {
</code><code id="L330"><span class="ln">330</span> <b>return</b> <span class="d">0</span>;
</code><code id="L331"><span class="ln">331</span> }
</code><code id="L332"><span class="ln">332</span> <b>return</b> (<span class="d">180</span><span class="s"> + </span>math.atan2(-y, -x)<span class="s"> * </span><span class="d">180</span><span class="s"> / </span>PI<span class="s"> + </span><span class="d">360</span>)<span class="s"> % </span><span class="d">360</span>;
</code><code id="L333"><span class="ln">333</span> } <b>else</b> {
</code><code id="L334"><span class="ln">334</span> <b>return</b> R.angle(x1, y1, x3, y3)<span class="s"> - </span>R.angle(x2, y2, x3, y3);
</code><code id="L335"><span class="ln">335</span> }
</code><code id="L336"><span class="ln">336</span> };
</code><code id="L337"><span class="ln">337</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L338"><span class="ln">338</span><span class="c"> <span class="s"> * </span>Raphael.rad
</span></code><code id="L339"><span class="ln">339</span><span class="c"> [ method ]
</span></code><code id="L340"><span class="ln">340</span><span class="c"> **
</span></code><code id="L341"><span class="ln">341</span><span class="c"> <span class="s"> * </span>Transform angle to radians
</span></code><code id="L342"><span class="ln">342</span><span class="c"> > Parameters
</span></code><code id="L343"><span class="ln">343</span><span class="c"> <span class="s"> - </span>deg (number) angle <b>in</b> degrees
</span></code><code id="L344"><span class="ln">344</span><span class="c"> <span class="s"> = </span>(number) angle <b>in</b> radians.
</span></code><code id="L345"><span class="ln">345</span><span class="c"> \*/</span>
</code><code id="L346"><span class="ln">346</span> R.rad<span class="s"> = </span><b>function</b> (deg) {
</code><code id="L347"><span class="ln">347</span> <b>return</b> deg<span class="s"> % </span><span class="d">360</span><span class="s"> * </span>PI<span class="s"> / </span><span class="d">180</span>;
</code><code id="L348"><span class="ln">348</span> };
</code><code id="L349"><span class="ln">349</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L350"><span class="ln">350</span><span class="c"> <span class="s"> * </span>Raphael.deg
</span></code><code id="L351"><span class="ln">351</span><span class="c"> [ method ]
</span></code><code id="L352"><span class="ln">352</span><span class="c"> **
</span></code><code id="L353"><span class="ln">353</span><span class="c"> <span class="s"> * </span>Transform angle to degrees
</span></code><code id="L354"><span class="ln">354</span><span class="c"> > Parameters
</span></code><code id="L355"><span class="ln">355</span><span class="c"> <span class="s"> - </span>deg (number) angle <b>in</b> radians
</span></code><code id="L356"><span class="ln">356</span><span class="c"> <span class="s"> = </span>(number) angle <b>in</b> degrees.
</span></code><code id="L357"><span class="ln">357</span><span class="c"> \*/</span>
</code><code id="L358"><span class="ln">358</span> R.deg<span class="s"> = </span><b>function</b> (rad) {
</code><code id="L359"><span class="ln">359</span> <b>return</b> rad<span class="s"> * </span><span class="d">180</span><span class="s"> / </span>PI<span class="s"> % </span><span class="d">360</span>;
</code><code id="L360"><span class="ln">360</span> };
</code><code id="L361"><span class="ln">361</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L362"><span class="ln">362</span><span class="c"> <span class="s"> * </span>Raphael.snapTo
</span></code><code id="L363"><span class="ln">363</span><span class="c"> [ method ]
</span></code><code id="L364"><span class="ln">364</span><span class="c"> **
</span></code><code id="L365"><span class="ln">365</span><span class="c"> <span class="s"> * </span>Snaps given value to given grid.
</span></code><code id="L366"><span class="ln">366</span><span class="c"> > Parameters
</span></code><code id="L367"><span class="ln">367</span><span class="c"> <span class="s"> - </span>values (array|number) given array of values or step of the grid
</span></code><code id="L368"><span class="ln">368</span><span class="c"> <span class="s"> - </span>value (number) value to adjust
</span></code><code id="L369"><span class="ln">369</span><span class="c"> <span class="s"> - </span>tolerance (number) #optional tolerance <b>for</b> snapping. Default is `<span class="d">10</span>`.
</span></code><code id="L370"><span class="ln">370</span><span class="c"> <span class="s"> = </span>(number) adjusted value.
</span></code><code id="L371"><span class="ln">371</span><span class="c"> \*/</span>
</code><code id="L372"><span class="ln">372</span> R.snapTo<span class="s"> = </span><b>function</b> (values, value, tolerance) {
</code><code id="L373"><span class="ln">373</span> tolerance<span class="s"> = </span>R.is(tolerance, <i>"finite"</i>) ? tolerance : <span class="d">10</span>;
</code><code id="L374"><span class="ln">374</span> <b>if</b> (R.is(values, array)) {
</code><code id="L375"><span class="ln">375</span> <b>var</b> i<span class="s"> = </span>values.length;
</code><code id="L376"><span class="ln">376</span> <b>while</b> (i--) <b>if</b> (abs(values[i]<span class="s"> - </span>value) <= tolerance) {
</code><code id="L377"><span class="ln">377</span> <b>return</b> values[i];
</code><code id="L378"><span class="ln">378</span> }
</code><code id="L379"><span class="ln">379</span> } <b>else</b> {
</code><code id="L380"><span class="ln">380</span> values<span class="s"> = </span>+values;
</code><code id="L381"><span class="ln">381</span> <b>var</b> rem<span class="s"> = </span>value<span class="s"> % </span>values;
</code><code id="L382"><span class="ln">382</span> <b>if</b> (rem < tolerance) {
</code><code id="L383"><span class="ln">383</span> <b>return</b> value<span class="s"> - </span>rem;
</code><code id="L384"><span class="ln">384</span> }
</code><code id="L385"><span class="ln">385</span> <b>if</b> (rem > values<span class="s"> - </span>tolerance) {
</code><code id="L386"><span class="ln">386</span> <b>return</b> value<span class="s"> - </span>rem<span class="s"> + </span>values;
</code><code id="L387"><span class="ln">387</span> }
</code><code id="L388"><span class="ln">388</span> }
</code><code id="L389"><span class="ln">389</span> <b>return</b> value;
</code><code id="L390"><span class="ln">390</span> };
</code><code id="L391"><span class="ln">391</span>
</code><code id="L392"><span class="ln">392</span> <b>var</b> createUUID<span class="s"> = </span>(<b>function</b> (uuidRegEx, uuidReplacer) {
</code><code id="L393"><span class="ln">393</span> <b>return</b> <b>function</b> () {
</code><code id="L394"><span class="ln">394</span> <b>return</b> <i>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"</i>.replace(uuidRegEx, uuidReplacer).toUpperCase();
</code><code id="L395"><span class="ln">395</span> };
</code><code id="L396"><span class="ln">396</span> })(/[xy]/g, <b>function</b> (c) {
</code><code id="L397"><span class="ln">397</span> <b>var</b> r<span class="s"> = </span>math.random()<span class="s"> * </span><span class="d">16</span><span class="s"> | </span><span class="d">0</span>,
</code><code id="L398"><span class="ln">398</span> v<span class="s"> = </span>c<span class="s"> == </span><i>"x"</i> ? r : (r<span class="s"> & </span><span class="d">3</span><span class="s"> | </span><span class="d">8</span>);
</code><code id="L399"><span class="ln">399</span> <b>return</b> v.toString(<span class="d">16</span>);
</code><code id="L400"><span class="ln">400</span> });
</code><code id="L401"><span class="ln">401</span>
</code><code id="L402"><span class="ln">402</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L403"><span class="ln">403</span><span class="c"> <span class="s"> * </span>Raphael.setWindow
</span></code><code id="L404"><span class="ln">404</span><span class="c"> [ method ]
</span></code><code id="L405"><span class="ln">405</span><span class="c"> **
</span></code><code id="L406"><span class="ln">406</span><span class="c"> <span class="s"> * </span>Used when you need to draw <b>in</b> `<iframe>`. Switched window to the iframe one.
</span></code><code id="L407"><span class="ln">407</span><span class="c"> > Parameters
</span></code><code id="L408"><span class="ln">408</span><span class="c"> <span class="s"> - </span>newwin (window) <b>new</b> window object
</span></code><code id="L409"><span class="ln">409</span><span class="c"> \*/</span>
</code><code id="L410"><span class="ln">410</span> R.setWindow<span class="s"> = </span><b>function</b> (newwin) {
</code><code id="L411"><span class="ln">411</span> eve(<i>"setWindow"</i>, R, g.win, newwin);
</code><code id="L412"><span class="ln">412</span> g.win<span class="s"> = </span>newwin;
</code><code id="L413"><span class="ln">413</span> g.doc<span class="s"> = </span>g.win.document;
</code><code id="L414"><span class="ln">414</span> <b>if</b> (initWin) {
</code><code id="L415"><span class="ln">415</span> initWin(g.win);
</code><code id="L416"><span class="ln">416</span> }
</code><code id="L417"><span class="ln">417</span> };
</code><code id="L418"><span class="ln">418</span> <span class="c">// colour utilities</span>
</code><code id="L419"><span class="ln">419</span> <b>var</b> toHex<span class="s"> = </span><b>function</b> (color) {
</code><code id="L420"><span class="ln">420</span> <b>if</b> (R.vml) {
</code><code id="L421"><span class="ln">421</span> <span class="c">// http://dean.edwards.name/weblog/<span class="d">2009</span>/<span class="d">10</span>/convert-any-colour-value-to-hex-<b>in</b>-msie/</span>
</code><code id="L422"><span class="ln">422</span> <b>var</b> trim<span class="s"> = </span>/^\s+|\s+$/g;
</code><code id="L423"><span class="ln">423</span> <b>var</b> bod;
</code><code id="L424"><span class="ln">424</span> <b>try</b> {
</code><code id="L425"><span class="ln">425</span> <b>var</b> docum<span class="s"> = </span><b>new</b> ActiveXObject(<i>"htmlfile"</i>);
</code><code id="L426"><span class="ln">426</span> docum.write(<i>"<body>"</i>);
</code><code id="L427"><span class="ln">427</span> docum.close();
</code><code id="L428"><span class="ln">428</span> bod<span class="s"> = </span>docum.body;
</code><code id="L429"><span class="ln">429</span> } <b>catch</b>(e) {
</code><code id="L430"><span class="ln">430</span> bod<span class="s"> = </span>createPopup().document.body;
</code><code id="L431"><span class="ln">431</span> }
</code><code id="L432"><span class="ln">432</span> <b>var</b> range<span class="s"> = </span>bod.createTextRange();
</code><code id="L433"><span class="ln">433</span> toHex<span class="s"> = </span>cacher(<b>function</b> (color) {
</code><code id="L434"><span class="ln">434</span> <b>try</b> {
</code><code id="L435"><span class="ln">435</span> bod.style.color<span class="s"> = </span>Str(color).replace(trim, E);
</code><code id="L436"><span class="ln">436</span> <b>var</b> value<span class="s"> = </span>range.queryCommandValue(<i>"ForeColor"</i>);
</code><code id="L437"><span class="ln">437</span> value<span class="s"> = </span>((value<span class="s"> & </span><span class="d">255</span>) << <span class="d">16</span>)<span class="s"> | </span>(value<span class="s"> & </span><span class="d">65280</span>)<span class="s"> | </span>((value<span class="s"> & </span><span class="d">16711680</span>) >>> <span class="d">16</span>);
</code><code id="L438"><span class="ln">438</span> <b>return</b> <i>"#"</i><span class="s"> + </span>(<i>"<span class="d">000000</span>"</i><span class="s"> + </span>value.toString(<span class="d">16</span>)).slice(-<span class="d">6</span>);
</code><code id="L439"><span class="ln">439</span> } <b>catch</b>(e) {
</code><code id="L440"><span class="ln">440</span> <b>return</b> <i>"none"</i>;
</code><code id="L441"><span class="ln">441</span> }
</code><code id="L442"><span class="ln">442</span> });
</code><code id="L443"><span class="ln">443</span> } <b>else</b> {
</code><code id="L444"><span class="ln">444</span> <b>var</b> i<span class="s"> = </span>g.doc.createElement(<i>"i"</i>);
</code><code id="L445"><span class="ln">445</span> i.title<span class="s"> = </span><i>"Rapha\xebl Colour Picker"</i>;
</code><code id="L446"><span class="ln">446</span> i.style.display<span class="s"> = </span><i>"none"</i>;
</code><code id="L447"><span class="ln">447</span> g.doc.body.appendChild(i);
</code><code id="L448"><span class="ln">448</span> toHex<span class="s"> = </span>cacher(<b>function</b> (color) {
</code><code id="L449"><span class="ln">449</span> i.style.color<span class="s"> = </span>color;
</code><code id="L450"><span class="ln">450</span> <b>return</b> g.doc.defaultView.getComputedStyle(i, E).getPropertyValue(<i>"color"</i>);
</code><code id="L451"><span class="ln">451</span> });
</code><code id="L452"><span class="ln">452</span> }
</code><code id="L453"><span class="ln">453</span> <b>return</b> toHex(color);
</code><code id="L454"><span class="ln">454</span> },
</code><code id="L455"><span class="ln">455</span> hsbtoString<span class="s"> = </span><b>function</b> () {
</code><code id="L456"><span class="ln">456</span> <b>return</b> <i>"hsb("</i><span class="s"> + </span>[<b>this</b>.h, <b>this</b>.s, <b>this</b>.b]<span class="s"> + </span><i>")"</i>;
</code><code id="L457"><span class="ln">457</span> },
</code><code id="L458"><span class="ln">458</span> hsltoString<span class="s"> = </span><b>function</b> () {
</code><code id="L459"><span class="ln">459</span> <b>return</b> <i>"hsl("</i><span class="s"> + </span>[<b>this</b>.h, <b>this</b>.s, <b>this</b>.l]<span class="s"> + </span><i>")"</i>;
</code><code id="L460"><span class="ln">460</span> },
</code><code id="L461"><span class="ln">461</span> rgbtoString<span class="s"> = </span><b>function</b> () {
</code><code id="L462"><span class="ln">462</span> <b>return</b> <b>this</b>.hex;
</code><code id="L463"><span class="ln">463</span> },
</code><code id="L464"><span class="ln">464</span> prepareRGB<span class="s"> = </span><b>function</b> (r, g, b) {
</code><code id="L465"><span class="ln">465</span> <b>if</b> (g<span class="s"> == </span><b>null</b><span class="s"> && </span>R.is(r, <i>"object"</i>)<span class="s"> && </span><i>"r"</i> <b>in</b> r<span class="s"> && </span><i>"g"</i> <b>in</b> r<span class="s"> && </span><i>"b"</i> <b>in</b> r) {
</code><code id="L466"><span class="ln">466</span> b<span class="s"> = </span>r.b;
</code><code id="L467"><span class="ln">467</span> g<span class="s"> = </span>r.g;
</code><code id="L468"><span class="ln">468</span> r<span class="s"> = </span>r.r;
</code><code id="L469"><span class="ln">469</span> }
</code><code id="L470"><span class="ln">470</span> <b>if</b> (g<span class="s"> == </span><b>null</b><span class="s"> && </span>R.is(r, string)) {
</code><code id="L471"><span class="ln">471</span> <b>var</b> clr<span class="s"> = </span>R.getRGB(r);
</code><code id="L472"><span class="ln">472</span> r<span class="s"> = </span>clr.r;
</code><code id="L473"><span class="ln">473</span> g<span class="s"> = </span>clr.g;
</code><code id="L474"><span class="ln">474</span> b<span class="s"> = </span>clr.b;
</code><code id="L475"><span class="ln">475</span> }
</code><code id="L476"><span class="ln">476</span> <b>if</b> (r > <span class="d">1</span><span class="s"> || </span>g > <span class="d">1</span><span class="s"> || </span>b > <span class="d">1</span>) {
</code><code id="L477"><span class="ln">477</span> r /= <span class="d">255</span>;
</code><code id="L478"><span class="ln">478</span> g /= <span class="d">255</span>;
</code><code id="L479"><span class="ln">479</span> b /= <span class="d">255</span>;
</code><code id="L480"><span class="ln">480</span> }
</code><code id="L481"><span class="ln">481</span>
</code><code id="L482"><span class="ln">482</span> <b>return</b> [r, g, b];
</code><code id="L483"><span class="ln">483</span> },
</code><code id="L484"><span class="ln">484</span> packageRGB<span class="s"> = </span><b>function</b> (r, g, b, o) {
</code><code id="L485"><span class="ln">485</span> r *= <span class="d">255</span>;
</code><code id="L486"><span class="ln">486</span> g *= <span class="d">255</span>;
</code><code id="L487"><span class="ln">487</span> b *= <span class="d">255</span>;
</code><code id="L488"><span class="ln">488</span> <b>var</b> rgb<span class="s"> = </span>{
</code><code id="L489"><span class="ln">489</span> r: r,
</code><code id="L490"><span class="ln">490</span> g: g,
</code><code id="L491"><span class="ln">491</span> b: b,
</code><code id="L492"><span class="ln">492</span> hex: R.rgb(r, g, b),
</code><code id="L493"><span class="ln">493</span> toString: rgbtoString
</code><code id="L494"><span class="ln">494</span> };
</code><code id="L495"><span class="ln">495</span> R.is(o, <i>"finite"</i>)<span class="s"> && </span>(rgb.opacity<span class="s"> = </span>o);
</code><code id="L496"><span class="ln">496</span> <b>return</b> rgb;
</code><code id="L497"><span class="ln">497</span> };
</code><code id="L498"><span class="ln">498</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L499"><span class="ln">499</span><span class="c"> <span class="s"> * </span>Raphael.hsb2rgb
</span></code><code id="L500"><span class="ln">500</span><span class="c"> [ method ]
</span></code><code id="L501"><span class="ln">501</span><span class="c"> **
</span></code><code id="L502"><span class="ln">502</span><span class="c"> <span class="s"> * </span>Converts HSB values to RGB object.
</span></code><code id="L503"><span class="ln">503</span><span class="c"> > Parameters
</span></code><code id="L504"><span class="ln">504</span><span class="c"> <span class="s"> - </span>h (number) hue
</span></code><code id="L505"><span class="ln">505</span><span class="c"> <span class="s"> - </span>s (number) saturation
</span></code><code id="L506"><span class="ln">506</span><span class="c"> <span class="s"> - </span>v (number) value or brightness
</span></code><code id="L507"><span class="ln">507</span><span class="c"> <span class="s"> = </span>(object) RGB object <b>in</b> format:
</span></code><code id="L508"><span class="ln">508</span><span class="c"> o {
</span></code><code id="L509"><span class="ln">509</span><span class="c"> o r (number) red,
</span></code><code id="L510"><span class="ln">510</span><span class="c"> o g (number) green,
</span></code><code id="L511"><span class="ln">511</span><span class="c"> o b (number) blue,
</span></code><code id="L512"><span class="ln">512</span><span class="c"> o hex (string) color <b>in</b> HTML/CSS format: #••••••
</span></code><code id="L513"><span class="ln">513</span><span class="c"> o }
</span></code><code id="L514"><span class="ln">514</span><span class="c"> \*/</span>
</code><code id="L515"><span class="ln">515</span> R.hsb2rgb<span class="s"> = </span><b>function</b> (h, s, v, o) {
</code><code id="L516"><span class="ln">516</span> <b>if</b> (<b>this</b>.is(h, <i>"object"</i>)<span class="s"> && </span><i>"h"</i> <b>in</b> h<span class="s"> && </span><i>"s"</i> <b>in</b> h<span class="s"> && </span><i>"b"</i> <b>in</b> h) {
</code><code id="L517"><span class="ln">517</span> v<span class="s"> = </span>h.b;
</code><code id="L518"><span class="ln">518</span> s<span class="s"> = </span>h.s;
</code><code id="L519"><span class="ln">519</span> h<span class="s"> = </span>h.h;
</code><code id="L520"><span class="ln">520</span> o<span class="s"> = </span>h.o;
</code><code id="L521"><span class="ln">521</span> }
</code><code id="L522"><span class="ln">522</span> h *= <span class="d">360</span>;
</code><code id="L523"><span class="ln">523</span> <b>var</b> R, G, B, X, C;
</code><code id="L524"><span class="ln">524</span> h<span class="s"> = </span>(h<span class="s"> % </span><span class="d">360</span>)<span class="s"> / </span><span class="d">60</span>;
</code><code id="L525"><span class="ln">525</span> C<span class="s"> = </span>v<span class="s"> * </span>s;
</code><code id="L526"><span class="ln">526</span> X<span class="s"> = </span>C<span class="s"> * </span>(<span class="d">1</span><span class="s"> - </span>abs(h<span class="s"> % </span><span class="d">2</span><span class="s"> - </span><span class="d">1</span>));
</code><code id="L527"><span class="ln">527</span> R<span class="s"> = </span>G<span class="s"> = </span>B<span class="s"> = </span>v<span class="s"> - </span>C;
</code><code id="L528"><span class="ln">528</span>
</code><code id="L529"><span class="ln">529</span> h<span class="s"> = </span>~~h;
</code><code id="L530"><span class="ln">530</span> R += [C, X, <span class="d">0</span>, <span class="d">0</span>, X, C][h];
</code><code id="L531"><span class="ln">531</span> G += [X, C, C, X, <span class="d">0</span>, <span class="d">0</span>][h];
</code><code id="L532"><span class="ln">532</span> B += [<span class="d">0</span>, <span class="d">0</span>, X, C, C, X][h];
</code><code id="L533"><span class="ln">533</span> <b>return</b> packageRGB(R, G, B, o);
</code><code id="L534"><span class="ln">534</span> };
</code><code id="L535"><span class="ln">535</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L536"><span class="ln">536</span><span class="c"> <span class="s"> * </span>Raphael.hsl2rgb
</span></code><code id="L537"><span class="ln">537</span><span class="c"> [ method ]
</span></code><code id="L538"><span class="ln">538</span><span class="c"> **
</span></code><code id="L539"><span class="ln">539</span><span class="c"> <span class="s"> * </span>Converts HSL values to RGB object.
</span></code><code id="L540"><span class="ln">540</span><span class="c"> > Parameters
</span></code><code id="L541"><span class="ln">541</span><span class="c"> <span class="s"> - </span>h (number) hue
</span></code><code id="L542"><span class="ln">542</span><span class="c"> <span class="s"> - </span>s (number) saturation
</span></code><code id="L543"><span class="ln">543</span><span class="c"> <span class="s"> - </span>l (number) luminosity
</span></code><code id="L544"><span class="ln">544</span><span class="c"> <span class="s"> = </span>(object) RGB object <b>in</b> format:
</span></code><code id="L545"><span class="ln">545</span><span class="c"> o {
</span></code><code id="L546"><span class="ln">546</span><span class="c"> o r (number) red,
</span></code><code id="L547"><span class="ln">547</span><span class="c"> o g (number) green,
</span></code><code id="L548"><span class="ln">548</span><span class="c"> o b (number) blue,
</span></code><code id="L549"><span class="ln">549</span><span class="c"> o hex (string) color <b>in</b> HTML/CSS format: #••••••
</span></code><code id="L550"><span class="ln">550</span><span class="c"> o }
</span></code><code id="L551"><span class="ln">551</span><span class="c"> \*/</span>
</code><code id="L552"><span class="ln">552</span> R.hsl2rgb<span class="s"> = </span><b>function</b> (h, s, l, o) {
</code><code id="L553"><span class="ln">553</span> <b>if</b> (<b>this</b>.is(h, <i>"object"</i>)<span class="s"> && </span><i>"h"</i> <b>in</b> h<span class="s"> && </span><i>"s"</i> <b>in</b> h<span class="s"> && </span><i>"l"</i> <b>in</b> h) {
</code><code id="L554"><span class="ln">554</span> l<span class="s"> = </span>h.l;
</code><code id="L555"><span class="ln">555</span> s<span class="s"> = </span>h.s;
</code><code id="L556"><span class="ln">556</span> h<span class="s"> = </span>h.h;
</code><code id="L557"><span class="ln">557</span> }
</code><code id="L558"><span class="ln">558</span> <b>if</b> (h > <span class="d">1</span><span class="s"> || </span>s > <span class="d">1</span><span class="s"> || </span>l > <span class="d">1</span>) {
</code><code id="L559"><span class="ln">559</span> h /= <span class="d">360</span>;
</code><code id="L560"><span class="ln">560</span> s /= <span class="d">100</span>;
</code><code id="L561"><span class="ln">561</span> l /= <span class="d">100</span>;
</code><code id="L562"><span class="ln">562</span> }
</code><code id="L563"><span class="ln">563</span> h *= <span class="d">360</span>;
</code><code id="L564"><span class="ln">564</span> <b>var</b> R, G, B, X, C;
</code><code id="L565"><span class="ln">565</span> h<span class="s"> = </span>(h<span class="s"> % </span><span class="d">360</span>)<span class="s"> / </span><span class="d">60</span>;
</code><code id="L566"><span class="ln">566</span> C<span class="s"> = </span><span class="d">2</span><span class="s"> * </span>s<span class="s"> * </span>(l < <span class="d">.5</span> ? l : <span class="d">1</span><span class="s"> - </span>l);
</code><code id="L567"><span class="ln">567</span> X<span class="s"> = </span>C<span class="s"> * </span>(<span class="d">1</span><span class="s"> - </span>abs(h<span class="s"> % </span><span class="d">2</span><span class="s"> - </span><span class="d">1</span>));
</code><code id="L568"><span class="ln">568</span> R<span class="s"> = </span>G<span class="s"> = </span>B<span class="s"> = </span>l<span class="s"> - </span>C<span class="s"> / </span><span class="d">2</span>;
</code><code id="L569"><span class="ln">569</span>
</code><code id="L570"><span class="ln">570</span> h<span class="s"> = </span>~~h;
</code><code id="L571"><span class="ln">571</span> R += [C, X, <span class="d">0</span>, <span class="d">0</span>, X, C][h];
</code><code id="L572"><span class="ln">572</span> G += [X, C, C, X, <span class="d">0</span>, <span class="d">0</span>][h];
</code><code id="L573"><span class="ln">573</span> B += [<span class="d">0</span>, <span class="d">0</span>, X, C, C, X][h];
</code><code id="L574"><span class="ln">574</span> <b>return</b> packageRGB(R, G, B, o);
</code><code id="L575"><span class="ln">575</span> };
</code><code id="L576"><span class="ln">576</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L577"><span class="ln">577</span><span class="c"> <span class="s"> * </span>Raphael.rgb2hsb
</span></code><code id="L578"><span class="ln">578</span><span class="c"> [ method ]
</span></code><code id="L579"><span class="ln">579</span><span class="c"> **
</span></code><code id="L580"><span class="ln">580</span><span class="c"> <span class="s"> * </span>Converts RGB values to HSB object.
</span></code><code id="L581"><span class="ln">581</span><span class="c"> > Parameters
</span></code><code id="L582"><span class="ln">582</span><span class="c"> <span class="s"> - </span>r (number) red
</span></code><code id="L583"><span class="ln">583</span><span class="c"> <span class="s"> - </span>g (number) green
</span></code><code id="L584"><span class="ln">584</span><span class="c"> <span class="s"> - </span>b (number) blue
</span></code><code id="L585"><span class="ln">585</span><span class="c"> <span class="s"> = </span>(object) HSB object <b>in</b> format:
</span></code><code id="L586"><span class="ln">586</span><span class="c"> o {
</span></code><code id="L587"><span class="ln">587</span><span class="c"> o h (number) hue
</span></code><code id="L588"><span class="ln">588</span><span class="c"> o s (number) saturation
</span></code><code id="L589"><span class="ln">589</span><span class="c"> o b (number) brightness
</span></code><code id="L590"><span class="ln">590</span><span class="c"> o }
</span></code><code id="L591"><span class="ln">591</span><span class="c"> \*/</span>
</code><code id="L592"><span class="ln">592</span> R.rgb2hsb<span class="s"> = </span><b>function</b> (r, g, b) {
</code><code id="L593"><span class="ln">593</span> b<span class="s"> = </span>prepareRGB(r, g, b);
</code><code id="L594"><span class="ln">594</span> r<span class="s"> = </span>b[<span class="d">0</span>];
</code><code id="L595"><span class="ln">595</span> g<span class="s"> = </span>b[<span class="d">1</span>];
</code><code id="L596"><span class="ln">596</span> b<span class="s"> = </span>b[<span class="d">2</span>];
</code><code id="L597"><span class="ln">597</span>
</code><code id="L598"><span class="ln">598</span> <b>var</b> H, S, V, C;
</code><code id="L599"><span class="ln">599</span> V<span class="s"> = </span>mmax(r, g, b);
</code><code id="L600"><span class="ln">600</span> C<span class="s"> = </span>V<span class="s"> - </span>mmin(r, g, b);
</code><code id="L601"><span class="ln">601</span> H<span class="s"> = </span>(C<span class="s"> == </span><span class="d">0</span> ? <b>null</b> :
</code><code id="L602"><span class="ln">602</span> V<span class="s"> == </span>r ? (g<span class="s"> - </span>b)<span class="s"> / </span>C :
</code><code id="L603"><span class="ln">603</span> V<span class="s"> == </span>g ? (b<span class="s"> - </span>r)<span class="s"> / </span>C<span class="s"> + </span><span class="d">2</span> :
</code><code id="L604"><span class="ln">604</span> (r<span class="s"> - </span>g)<span class="s"> / </span>C<span class="s"> + </span><span class="d">4</span>);
</code><code id="L605"><span class="ln">605</span> H<span class="s"> = </span>(H<span class="s"> % </span><span class="d">6</span>)<span class="s"> * </span><span class="d">60</span>;
</code><code id="L606"><span class="ln">606</span> S<span class="s"> = </span>C<span class="s"> == </span><span class="d">0</span> ? <span class="d">0</span> : C<span class="s"> / </span>V;
</code><code id="L607"><span class="ln">607</span> <b>return</b> {h: H, s: S, b: V, toString: hsbtoString};
</code><code id="L608"><span class="ln">608</span> };
</code><code id="L609"><span class="ln">609</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L610"><span class="ln">610</span><span class="c"> <span class="s"> * </span>Raphael.rgb2hsl
</span></code><code id="L611"><span class="ln">611</span><span class="c"> [ method ]
</span></code><code id="L612"><span class="ln">612</span><span class="c"> **
</span></code><code id="L613"><span class="ln">613</span><span class="c"> <span class="s"> * </span>Converts RGB values to HSL object.
</span></code><code id="L614"><span class="ln">614</span><span class="c"> > Parameters
</span></code><code id="L615"><span class="ln">615</span><span class="c"> <span class="s"> - </span>r (number) red
</span></code><code id="L616"><span class="ln">616</span><span class="c"> <span class="s"> - </span>g (number) green
</span></code><code id="L617"><span class="ln">617</span><span class="c"> <span class="s"> - </span>b (number) blue
</span></code><code id="L618"><span class="ln">618</span><span class="c"> <span class="s"> = </span>(object) HSL object <b>in</b> format:
</span></code><code id="L619"><span class="ln">619</span><span class="c"> o {
</span></code><code id="L620"><span class="ln">620</span><span class="c"> o h (number) hue
</span></code><code id="L621"><span class="ln">621</span><span class="c"> o s (number) saturation
</span></code><code id="L622"><span class="ln">622</span><span class="c"> o l (number) luminosity
</span></code><code id="L623"><span class="ln">623</span><span class="c"> o }
</span></code><code id="L624"><span class="ln">624</span><span class="c"> \*/</span>
</code><code id="L625"><span class="ln">625</span> R.rgb2hsl<span class="s"> = </span><b>function</b> (r, g, b) {
</code><code id="L626"><span class="ln">626</span> b<span class="s"> = </span>prepareRGB(r, g, b);
</code><code id="L627"><span class="ln">627</span> r<span class="s"> = </span>b[<span class="d">0</span>];
</code><code id="L628"><span class="ln">628</span> g<span class="s"> = </span>b[<span class="d">1</span>];
</code><code id="L629"><span class="ln">629</span> b<span class="s"> = </span>b[<span class="d">2</span>];
</code><code id="L630"><span class="ln">630</span>
</code><code id="L631"><span class="ln">631</span> <b>var</b> H, S, L, M, m, C;
</code><code id="L632"><span class="ln">632</span> M<span class="s"> = </span>mmax(r, g, b);
</code><code id="L633"><span class="ln">633</span> m<span class="s"> = </span>mmin(r, g, b);
</code><code id="L634"><span class="ln">634</span> C<span class="s"> = </span>M<span class="s"> - </span>m;
</code><code id="L635"><span class="ln">635</span> H<span class="s"> = </span>(C<span class="s"> == </span><span class="d">0</span> ? <b>null</b> :
</code><code id="L636"><span class="ln">636</span> M<span class="s"> == </span>r ? (g<span class="s"> - </span>b)<span class="s"> / </span>C :
</code><code id="L637"><span class="ln">637</span> M<span class="s"> == </span>g ? (b<span class="s"> - </span>r)<span class="s"> / </span>C<span class="s"> + </span><span class="d">2</span> :
</code><code id="L638"><span class="ln">638</span> (r<span class="s"> - </span>g)<span class="s"> / </span>C<span class="s"> + </span><span class="d">4</span>);
</code><code id="L639"><span class="ln">639</span> H<span class="s"> = </span>(H<span class="s"> % </span><span class="d">6</span>)<span class="s"> * </span><span class="d">60</span>;
</code><code id="L640"><span class="ln">640</span> L<span class="s"> = </span>(M<span class="s"> + </span>m)<span class="s"> / </span><span class="d">2</span>;
</code><code id="L641"><span class="ln">641</span> S<span class="s"> = </span>(C<span class="s"> == </span><span class="d">0</span> ? <span class="d">0</span> :
</code><code id="L642"><span class="ln">642</span> L < <span class="d">.5</span> ? C<span class="s"> / </span>(<span class="d">2</span><span class="s"> * </span>L) :
</code><code id="L643"><span class="ln">643</span> C<span class="s"> / </span>(<span class="d">2</span><span class="s"> - </span><span class="d">2</span><span class="s"> * </span>L));
</code><code id="L644"><span class="ln">644</span> <b>return</b> {h: H, s: S, l: L, toString: hsltoString};
</code><code id="L645"><span class="ln">645</span> };
</code><code id="L646"><span class="ln">646</span> R._path2string<span class="s"> = </span><b>function</b> () {
</code><code id="L647"><span class="ln">647</span> <b>return</b> <b>this</b>.join(<i>","</i>).replace(p2s, <i>"$<span class="d">1</span>"</i>);
</code><code id="L648"><span class="ln">648</span> };
</code><code id="L649"><span class="ln">649</span> <b>function</b> cacher(f, scope, postprocessor) {
</code><code id="L650"><span class="ln">650</span> <b>function</b> newf() {
</code><code id="L651"><span class="ln">651</span> <b>var</b> arg<span class="s"> = </span>Array.prototype.slice.call(arguments, <span class="d">0</span>),
</code><code id="L652"><span class="ln">652</span> args<span class="s"> = </span>arg.join(<i>"\u2400"</i>),
</code><code id="L653"><span class="ln">653</span> cache<span class="s"> = </span>newf.cache<span class="s"> = </span>newf.cache<span class="s"> || </span>{},
</code><code id="L654"><span class="ln">654</span> count<span class="s"> = </span>newf.count<span class="s"> = </span>newf.count<span class="s"> || </span>[];
</code><code id="L655"><span class="ln">655</span> <b>if</b> (cache[has](args)) {
</code><code id="L656"><span class="ln">656</span> <b>return</b> postprocessor ? postprocessor(cache[args]) : cache[args];
</code><code id="L657"><span class="ln">657</span> }
</code><code id="L658"><span class="ln">658</span> count.length >= <span class="d">1e3</span><span class="s"> && </span><b>delete</b> cache[count.shift()];
</code><code id="L659"><span class="ln">659</span> count.push(args);
</code><code id="L660"><span class="ln">660</span> cache[args]<span class="s"> = </span>f[apply](scope, arg);
</code><code id="L661"><span class="ln">661</span> <b>return</b> postprocessor ? postprocessor(cache[args]) : cache[args];
</code><code id="L662"><span class="ln">662</span> }
</code><code id="L663"><span class="ln">663</span> <b>return</b> newf;
</code><code id="L664"><span class="ln">664</span> }
</code><code id="L665"><span class="ln">665</span>
</code><code id="L666"><span class="ln">666</span> <b>function</b> preload(src, f) {
</code><code id="L667"><span class="ln">667</span> <b>var</b> img<span class="s"> = </span>g.doc.createElement(<i>"img"</i>);
</code><code id="L668"><span class="ln">668</span> img.style.cssText<span class="s"> = </span><i>"position:absolute;left:-9999em;top-9999em"</i>;
</code><code id="L669"><span class="ln">669</span> img.onload<span class="s"> = </span><b>function</b> () {
</code><code id="L670"><span class="ln">670</span> f.call(<b>this</b>);
</code><code id="L671"><span class="ln">671</span> <b>this</b>.onload<span class="s"> = </span><b>null</b>;
</code><code id="L672"><span class="ln">672</span> g.doc.body.removeChild(<b>this</b>);
</code><code id="L673"><span class="ln">673</span> };
</code><code id="L674"><span class="ln">674</span> img.onerror<span class="s"> = </span><b>function</b> () {
</code><code id="L675"><span class="ln">675</span> g.doc.body.removeChild(<b>this</b>);
</code><code id="L676"><span class="ln">676</span> };
</code><code id="L677"><span class="ln">677</span> g.doc.body.appendChild(img);
</code><code id="L678"><span class="ln">678</span> img.src<span class="s"> = </span>src;
</code><code id="L679"><span class="ln">679</span> }
</code><code id="L680"><span class="ln">680</span>
</code><code id="L681"><span class="ln">681</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L682"><span class="ln">682</span><span class="c"> <span class="s"> * </span>Raphael.getRGB
</span></code><code id="L683"><span class="ln">683</span><span class="c"> [ method ]
</span></code><code id="L684"><span class="ln">684</span><span class="c"> **
</span></code><code id="L685"><span class="ln">685</span><span class="c"> <span class="s"> * </span>Parses colour string as RGB object
</span></code><code id="L686"><span class="ln">686</span><span class="c"> > Parameters
</span></code><code id="L687"><span class="ln">687</span><span class="c"> <span class="s"> - </span>colour (string) colour string <b>in</b> one of formats:
</span></code><code id="L688"><span class="ln">688</span><span class="c"> # <ul>
</span></code><code id="L689"><span class="ln">689</span><span class="c"> # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
</span></code><code id="L690"><span class="ln">690</span><span class="c"> # <li>#••• — shortened HTML colour: (“<code>#<span class="d">000</span></code>”, “<code>#fc0</code>”, etc)</li>
</span></code><code id="L691"><span class="ln">691</span><span class="c"> # <li>#•••••• — full length HTML colour: (“<code>#<span class="d">000000</span></code>”, “<code>#bd2300</code>”)</li>
</span></code><code id="L692"><span class="ln">692</span><span class="c"> # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(<span class="d">200</span>, <span class="d">100</span>, <span class="d">0</span>)</code>”)</li>
</span></code><code id="L693"><span class="ln">693</span><span class="c"> # <li>rgb(•••%, •••%, •••%) — same as above, but <b>in</b> %: (“<code>rgb(<span class="d">100</span>%, <span class="d">175</span>%, <span class="d">0</span>%)</code>”)</li>
</span></code><code id="L694"><span class="ln">694</span><span class="c"> # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(<span class="d">0.5</span>, <span class="d">0.25</span>, <span class="d">1</span>)</code>”)</li>
</span></code><code id="L695"><span class="ln">695</span><span class="c"> # <li>hsb(•••%, •••%, •••%) — same as above, but <b>in</b> %</li>
</span></code><code id="L696"><span class="ln">696</span><span class="c"> # <li>hsl(•••, •••, •••) — same as hsb</li>
</span></code><code id="L697"><span class="ln">697</span><span class="c"> # <li>hsl(•••%, •••%, •••%) — same as hsb</li>
</span></code><code id="L698"><span class="ln">698</span><span class="c"> # </ul>
</span></code><code id="L699"><span class="ln">699</span><span class="c"> <span class="s"> = </span>(object) RGB object <b>in</b> format:
</span></code><code id="L700"><span class="ln">700</span><span class="c"> o {
</span></code><code id="L701"><span class="ln">701</span><span class="c"> o r (number) red,
</span></code><code id="L702"><span class="ln">702</span><span class="c"> o g (number) green,
</span></code><code id="L703"><span class="ln">703</span><span class="c"> o b (number) blue
</span></code><code id="L704"><span class="ln">704</span><span class="c"> o hex (string) color <b>in</b> HTML/CSS format: #••••••,
</span></code><code id="L705"><span class="ln">705</span><span class="c"> o error (<b>boolean</b>) <b>true</b> <b>if</b> string can’t be parsed
</span></code><code id="L706"><span class="ln">706</span><span class="c"> o }
</span></code><code id="L707"><span class="ln">707</span><span class="c"> \*/</span>
</code><code id="L708"><span class="ln">708</span> R.getRGB<span class="s"> = </span>cacher(<b>function</b> (colour) {
</code><code id="L709"><span class="ln">709</span> <b>if</b> (!colour<span class="s"> || </span>!!((colour<span class="s"> = </span>Str(colour)).indexOf(<i>"-"</i>)<span class="s"> + </span><span class="d">1</span>)) {
</code><code id="L710"><span class="ln">710</span> <b>return</b> {r: -<span class="d">1</span>, g: -<span class="d">1</span>, b: -<span class="d">1</span>, hex: <i>"none"</i>, error: <span class="d">1</span>};
</code><code id="L711"><span class="ln">711</span> }
</code><code id="L712"><span class="ln">712</span> <b>if</b> (colour<span class="s"> == </span><i>"none"</i>) {
</code><code id="L713"><span class="ln">713</span> <b>return</b> {r: -<span class="d">1</span>, g: -<span class="d">1</span>, b: -<span class="d">1</span>, hex: <i>"none"</i>};
</code><code id="L714"><span class="ln">714</span> }
</code><code id="L715"><span class="ln">715</span> !(hsrg[has](colour.toLowerCase().substring(<span class="d">0</span>, <span class="d">2</span>))<span class="s"> || </span>colour.charAt()<span class="s"> == </span><i>"#"</i>)<span class="s"> && </span>(colour<span class="s"> = </span>toHex(colour));
</code><code id="L716"><span class="ln">716</span> <b>var</b> res,
</code><code id="L717"><span class="ln">717</span> red,
</code><code id="L718"><span class="ln">718</span> green,
</code><code id="L719"><span class="ln">719</span> blue,
</code><code id="L720"><span class="ln">720</span> opacity,
</code><code id="L721"><span class="ln">721</span> t,
</code><code id="L722"><span class="ln">722</span> values,
</code><code id="L723"><span class="ln">723</span> rgb<span class="s"> = </span>colour.match(colourRegExp);
</code><code id="L724"><span class="ln">724</span> <b>if</b> (rgb) {
</code><code id="L725"><span class="ln">725</span> <b>if</b> (rgb[<span class="d">2</span>]) {
</code><code id="L726"><span class="ln">726</span> blue<span class="s"> = </span>toInt(rgb[<span class="d">2</span>].substring(<span class="d">5</span>), <span class="d">16</span>);
</code><code id="L727"><span class="ln">727</span> green<span class="s"> = </span>toInt(rgb[<span class="d">2</span>].substring(<span class="d">3</span>, <span class="d">5</span>), <span class="d">16</span>);
</code><code id="L728"><span class="ln">728</span> red<span class="s"> = </span>toInt(rgb[<span class="d">2</span>].substring(<span class="d">1</span>, <span class="d">3</span>), <span class="d">16</span>);
</code><code id="L729"><span class="ln">729</span> }
</code><code id="L730"><span class="ln">730</span> <b>if</b> (rgb[<span class="d">3</span>]) {
</code><code id="L731"><span class="ln">731</span> blue<span class="s"> = </span>toInt((t<span class="s"> = </span>rgb[<span class="d">3</span>].charAt(<span class="d">3</span>))<span class="s"> + </span>t, <span class="d">16</span>);
</code><code id="L732"><span class="ln">732</span> green<span class="s"> = </span>toInt((t<span class="s"> = </span>rgb[<span class="d">3</span>].charAt(<span class="d">2</span>))<span class="s"> + </span>t, <span class="d">16</span>);
</code><code id="L733"><span class="ln">733</span> red<span class="s"> = </span>toInt((t<span class="s"> = </span>rgb[<span class="d">3</span>].charAt(<span class="d">1</span>))<span class="s"> + </span>t, <span class="d">16</span>);
</code><code id="L734"><span class="ln">734</span> }
</code><code id="L735"><span class="ln">735</span> <b>if</b> (rgb[<span class="d">4</span>]) {
</code><code id="L736"><span class="ln">736</span> values<span class="s"> = </span>rgb[<span class="d">4</span>].split(commaSpaces);
</code><code id="L737"><span class="ln">737</span> red<span class="s"> = </span>toFloat(values[<span class="d">0</span>]);
</code><code id="L738"><span class="ln">738</span> values[<span class="d">0</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(red *= <span class="d">2.55</span>);
</code><code id="L739"><span class="ln">739</span> green<span class="s"> = </span>toFloat(values[<span class="d">1</span>]);
</code><code id="L740"><span class="ln">740</span> values[<span class="d">1</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(green *= <span class="d">2.55</span>);
</code><code id="L741"><span class="ln">741</span> blue<span class="s"> = </span>toFloat(values[<span class="d">2</span>]);
</code><code id="L742"><span class="ln">742</span> values[<span class="d">2</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(blue *= <span class="d">2.55</span>);
</code><code id="L743"><span class="ln">743</span> rgb[<span class="d">1</span>].toLowerCase().slice(<span class="d">0</span>, <span class="d">4</span>)<span class="s"> == </span><i>"rgba"</i><span class="s"> && </span>(opacity<span class="s"> = </span>toFloat(values[<span class="d">3</span>]));
</code><code id="L744"><span class="ln">744</span> values[<span class="d">3</span>]<span class="s"> && </span>values[<span class="d">3</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(opacity /= <span class="d">100</span>);
</code><code id="L745"><span class="ln">745</span> }
</code><code id="L746"><span class="ln">746</span> <b>if</b> (rgb[<span class="d">5</span>]) {
</code><code id="L747"><span class="ln">747</span> values<span class="s"> = </span>rgb[<span class="d">5</span>].split(commaSpaces);
</code><code id="L748"><span class="ln">748</span> red<span class="s"> = </span>toFloat(values[<span class="d">0</span>]);
</code><code id="L749"><span class="ln">749</span> values[<span class="d">0</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(red *= <span class="d">2.55</span>);
</code><code id="L750"><span class="ln">750</span> green<span class="s"> = </span>toFloat(values[<span class="d">1</span>]);
</code><code id="L751"><span class="ln">751</span> values[<span class="d">1</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(green *= <span class="d">2.55</span>);
</code><code id="L752"><span class="ln">752</span> blue<span class="s"> = </span>toFloat(values[<span class="d">2</span>]);
</code><code id="L753"><span class="ln">753</span> values[<span class="d">2</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(blue *= <span class="d">2.55</span>);
</code><code id="L754"><span class="ln">754</span> (values[<span class="d">0</span>].slice(-<span class="d">3</span>)<span class="s"> == </span><i>"deg"</i><span class="s"> || </span>values[<span class="d">0</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"\xb0"</i>)<span class="s"> && </span>(red /= <span class="d">360</span>);
</code><code id="L755"><span class="ln">755</span> rgb[<span class="d">1</span>].toLowerCase().slice(<span class="d">0</span>, <span class="d">4</span>)<span class="s"> == </span><i>"hsba"</i><span class="s"> && </span>(opacity<span class="s"> = </span>toFloat(values[<span class="d">3</span>]));
</code><code id="L756"><span class="ln">756</span> values[<span class="d">3</span>]<span class="s"> && </span>values[<span class="d">3</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(opacity /= <span class="d">100</span>);
</code><code id="L757"><span class="ln">757</span> <b>return</b> R.hsb2rgb(red, green, blue, opacity);
</code><code id="L758"><span class="ln">758</span> }
</code><code id="L759"><span class="ln">759</span> <b>if</b> (rgb[<span class="d">6</span>]) {
</code><code id="L760"><span class="ln">760</span> values<span class="s"> = </span>rgb[<span class="d">6</span>].split(commaSpaces);
</code><code id="L761"><span class="ln">761</span> red<span class="s"> = </span>toFloat(values[<span class="d">0</span>]);
</code><code id="L762"><span class="ln">762</span> values[<span class="d">0</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(red *= <span class="d">2.55</span>);
</code><code id="L763"><span class="ln">763</span> green<span class="s"> = </span>toFloat(values[<span class="d">1</span>]);
</code><code id="L764"><span class="ln">764</span> values[<span class="d">1</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(green *= <span class="d">2.55</span>);
</code><code id="L765"><span class="ln">765</span> blue<span class="s"> = </span>toFloat(values[<span class="d">2</span>]);
</code><code id="L766"><span class="ln">766</span> values[<span class="d">2</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(blue *= <span class="d">2.55</span>);
</code><code id="L767"><span class="ln">767</span> (values[<span class="d">0</span>].slice(-<span class="d">3</span>)<span class="s"> == </span><i>"deg"</i><span class="s"> || </span>values[<span class="d">0</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"\xb0"</i>)<span class="s"> && </span>(red /= <span class="d">360</span>);
</code><code id="L768"><span class="ln">768</span> rgb[<span class="d">1</span>].toLowerCase().slice(<span class="d">0</span>, <span class="d">4</span>)<span class="s"> == </span><i>"hsla"</i><span class="s"> && </span>(opacity<span class="s"> = </span>toFloat(values[<span class="d">3</span>]));
</code><code id="L769"><span class="ln">769</span> values[<span class="d">3</span>]<span class="s"> && </span>values[<span class="d">3</span>].slice(-<span class="d">1</span>)<span class="s"> == </span><i>"%"</i><span class="s"> && </span>(opacity /= <span class="d">100</span>);
</code><code id="L770"><span class="ln">770</span> <b>return</b> R.hsl2rgb(red, green, blue, opacity);
</code><code id="L771"><span class="ln">771</span> }
</code><code id="L772"><span class="ln">772</span> rgb<span class="s"> = </span>{r: red, g: green, b: blue};
</code><code id="L773"><span class="ln">773</span> rgb.hex<span class="s"> = </span><i>"#"</i><span class="s"> + </span>(<span class="d">16777216</span><span class="s"> | </span>blue<span class="s"> | </span>(green << <span class="d">8</span>)<span class="s"> | </span>(red << <span class="d">16</span>)).toString(<span class="d">16</span>).slice(<span class="d">1</span>);
</code><code id="L774"><span class="ln">774</span> R.is(opacity, <i>"finite"</i>)<span class="s"> && </span>(rgb.opacity<span class="s"> = </span>opacity);
</code><code id="L775"><span class="ln">775</span> <b>return</b> rgb;
</code><code id="L776"><span class="ln">776</span> }
</code><code id="L777"><span class="ln">777</span> <b>return</b> {r: -<span class="d">1</span>, g: -<span class="d">1</span>, b: -<span class="d">1</span>, hex: <i>"none"</i>, error: <span class="d">1</span>};
</code><code id="L778"><span class="ln">778</span> }, R);
</code><code id="L779"><span class="ln">779</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L780"><span class="ln">780</span><span class="c"> <span class="s"> * </span>Raphael.hsb
</span></code><code id="L781"><span class="ln">781</span><span class="c"> [ method ]
</span></code><code id="L782"><span class="ln">782</span><span class="c"> **
</span></code><code id="L783"><span class="ln">783</span><span class="c"> <span class="s"> * </span>Converts HSB values to hex representation of the colour.
</span></code><code id="L784"><span class="ln">784</span><span class="c"> > Parameters
</span></code><code id="L785"><span class="ln">785</span><span class="c"> <span class="s"> - </span>h (number) hue
</span></code><code id="L786"><span class="ln">786</span><span class="c"> <span class="s"> - </span>s (number) saturation
</span></code><code id="L787"><span class="ln">787</span><span class="c"> <span class="s"> - </span>b (number) value or brightness
</span></code><code id="L788"><span class="ln">788</span><span class="c"> <span class="s"> = </span>(string) hex representation of the colour.
</span></code><code id="L789"><span class="ln">789</span><span class="c"> \*/</span>
</code><code id="L790"><span class="ln">790</span> R.hsb<span class="s"> = </span>cacher(<b>function</b> (h, s, b) {
</code><code id="L791"><span class="ln">791</span> <b>return</b> R.hsb2rgb(h, s, b).hex;
</code><code id="L792"><span class="ln">792</span> });
</code><code id="L793"><span class="ln">793</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L794"><span class="ln">794</span><span class="c"> <span class="s"> * </span>Raphael.hsl
</span></code><code id="L795"><span class="ln">795</span><span class="c"> [ method ]
</span></code><code id="L796"><span class="ln">796</span><span class="c"> **
</span></code><code id="L797"><span class="ln">797</span><span class="c"> <span class="s"> * </span>Converts HSL values to hex representation of the colour.
</span></code><code id="L798"><span class="ln">798</span><span class="c"> > Parameters
</span></code><code id="L799"><span class="ln">799</span><span class="c"> <span class="s"> - </span>h (number) hue
</span></code><code id="L800"><span class="ln">800</span><span class="c"> <span class="s"> - </span>s (number) saturation
</span></code><code id="L801"><span class="ln">801</span><span class="c"> <span class="s"> - </span>l (number) luminosity
</span></code><code id="L802"><span class="ln">802</span><span class="c"> <span class="s"> = </span>(string) hex representation of the colour.
</span></code><code id="L803"><span class="ln">803</span><span class="c"> \*/</span>
</code><code id="L804"><span class="ln">804</span> R.hsl<span class="s"> = </span>cacher(<b>function</b> (h, s, l) {
</code><code id="L805"><span class="ln">805</span> <b>return</b> R.hsl2rgb(h, s, l).hex;
</code><code id="L806"><span class="ln">806</span> });
</code><code id="L807"><span class="ln">807</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L808"><span class="ln">808</span><span class="c"> <span class="s"> * </span>Raphael.rgb
</span></code><code id="L809"><span class="ln">809</span><span class="c"> [ method ]
</span></code><code id="L810"><span class="ln">810</span><span class="c"> **
</span></code><code id="L811"><span class="ln">811</span><span class="c"> <span class="s"> * </span>Converts RGB values to hex representation of the colour.
</span></code><code id="L812"><span class="ln">812</span><span class="c"> > Parameters
</span></code><code id="L813"><span class="ln">813</span><span class="c"> <span class="s"> - </span>r (number) red
</span></code><code id="L814"><span class="ln">814</span><span class="c"> <span class="s"> - </span>g (number) green
</span></code><code id="L815"><span class="ln">815</span><span class="c"> <span class="s"> - </span>b (number) blue
</span></code><code id="L816"><span class="ln">816</span><span class="c"> <span class="s"> = </span>(string) hex representation of the colour.
</span></code><code id="L817"><span class="ln">817</span><span class="c"> \*/</span>
</code><code id="L818"><span class="ln">818</span> R.rgb<span class="s"> = </span>cacher(<b>function</b> (r, g, b) {
</code><code id="L819"><span class="ln">819</span> <b>return</b> <i>"#"</i><span class="s"> + </span>(<span class="d">16777216</span><span class="s"> | </span>b<span class="s"> | </span>(g << <span class="d">8</span>)<span class="s"> | </span>(r << <span class="d">16</span>)).toString(<span class="d">16</span>).slice(<span class="d">1</span>);
</code><code id="L820"><span class="ln">820</span> });
</code><code id="L821"><span class="ln">821</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L822"><span class="ln">822</span><span class="c"> <span class="s"> * </span>Raphael.getColor
</span></code><code id="L823"><span class="ln">823</span><span class="c"> [ method ]
</span></code><code id="L824"><span class="ln">824</span><span class="c"> **
</span></code><code id="L825"><span class="ln">825</span><span class="c"> <span class="s"> * </span>On each call returns next colour <b>in</b> the spectrum. To reset it back to red call @Raphael.getColor.reset
</span></code><code id="L826"><span class="ln">826</span><span class="c"> > Parameters
</span></code><code id="L827"><span class="ln">827</span><span class="c"> <span class="s"> - </span>value (number) #optional brightness, <b>default</b> is `<span class="d">0.75</span>`
</span></code><code id="L828"><span class="ln">828</span><span class="c"> <span class="s"> = </span>(string) hex representation of the colour.
</span></code><code id="L829"><span class="ln">829</span><span class="c"> \*/</span>
</code><code id="L830"><span class="ln">830</span> R.getColor<span class="s"> = </span><b>function</b> (value) {
</code><code id="L831"><span class="ln">831</span> <b>var</b> start<span class="s"> = </span><b>this</b>.getColor.start<span class="s"> = </span><b>this</b>.getColor.start<span class="s"> || </span>{h: <span class="d">0</span>, s: <span class="d">1</span>, b: value<span class="s"> || </span><span class="d">.75</span>},
</code><code id="L832"><span class="ln">832</span> rgb<span class="s"> = </span><b>this</b>.hsb2rgb(start.h, start.s, start.b);
</code><code id="L833"><span class="ln">833</span> start.h += <span class="d">.075</span>;
</code><code id="L834"><span class="ln">834</span> <b>if</b> (start.h > <span class="d">1</span>) {
</code><code id="L835"><span class="ln">835</span> start.h<span class="s"> = </span><span class="d">0</span>;
</code><code id="L836"><span class="ln">836</span> start.s -= <span class="d">.2</span>;
</code><code id="L837"><span class="ln">837</span> start.s <= <span class="d">0</span><span class="s"> && </span>(<b>this</b>.getColor.start<span class="s"> = </span>{h: <span class="d">0</span>, s: <span class="d">1</span>, b: start.b});
</code><code id="L838"><span class="ln">838</span> }
</code><code id="L839"><span class="ln">839</span> <b>return</b> rgb.hex;
</code><code id="L840"><span class="ln">840</span> };
</code><code id="L841"><span class="ln">841</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L842"><span class="ln">842</span><span class="c"> <span class="s"> * </span>Raphael.getColor.reset
</span></code><code id="L843"><span class="ln">843</span><span class="c"> [ method ]
</span></code><code id="L844"><span class="ln">844</span><span class="c"> **
</span></code><code id="L845"><span class="ln">845</span><span class="c"> <span class="s"> * </span>Resets spectrum position <b>for</b> @Raphael.getColor back to red.
</span></code><code id="L846"><span class="ln">846</span><span class="c"> \*/</span>
</code><code id="L847"><span class="ln">847</span> R.getColor.reset<span class="s"> = </span><b>function</b> () {
</code><code id="L848"><span class="ln">848</span> <b>delete</b> <b>this</b>.start;
</code><code id="L849"><span class="ln">849</span> };
</code><code id="L850"><span class="ln">850</span>
</code><code id="L851"><span class="ln">851</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L852"><span class="ln">852</span><span class="c"> <span class="s"> * </span>Raphael.parsePathString
</span></code><code id="L853"><span class="ln">853</span><span class="c"> [ method ]
</span></code><code id="L854"><span class="ln">854</span><span class="c"> **
</span></code><code id="L855"><span class="ln">855</span><span class="c"> <span class="s"> * </span>Utility method
</span></code><code id="L856"><span class="ln">856</span><span class="c"> **
</span></code><code id="L857"><span class="ln">857</span><span class="c"> <span class="s"> * </span>Parses given path string into an array of arrays of path segments.
</span></code><code id="L858"><span class="ln">858</span><span class="c"> > Parameters
</span></code><code id="L859"><span class="ln">859</span><span class="c"> <span class="s"> - </span>pathString (string|array) path string or array of segments (<b>in</b> the last <b>case</b> it will be returned straight away)
</span></code><code id="L860"><span class="ln">860</span><span class="c"> <span class="s"> = </span>(array) array of segments.
</span></code><code id="L861"><span class="ln">861</span><span class="c"> \*/</span>
</code><code id="L862"><span class="ln">862</span> R.parsePathString<span class="s"> = </span>cacher(<b>function</b> (pathString) {
</code><code id="L863"><span class="ln">863</span> <b>if</b> (!pathString) {
</code><code id="L864"><span class="ln">864</span> <b>return</b> <b>null</b>;
</code><code id="L865"><span class="ln">865</span> }
</code><code id="L866"><span class="ln">866</span> <b>var</b> paramCounts<span class="s"> = </span>{a: <span class="d">7</span>, c: <span class="d">6</span>, h: <span class="d">1</span>, l: <span class="d">2</span>, m: <span class="d">2</span>, q: <span class="d">4</span>, s: <span class="d">4</span>, t: <span class="d">2</span>, v: <span class="d">1</span>, z: <span class="d">0</span>},
</code><code id="L867"><span class="ln">867</span> data<span class="s"> = </span>[];
</code><code id="L868"><span class="ln">868</span> <b>if</b> (R.is(pathString, array)<span class="s"> && </span>R.is(pathString[<span class="d">0</span>], array)) { <span class="c">// rough assumption</span>
</code><code id="L869"><span class="ln">869</span> data<span class="s"> = </span>pathClone(pathString);
</code><code id="L870"><span class="ln">870</span> }
</code><code id="L871"><span class="ln">871</span> <b>if</b> (!data.length) {
</code><code id="L872"><span class="ln">872</span> Str(pathString).replace(pathCommand, <b>function</b> (a, b, c) {
</code><code id="L873"><span class="ln">873</span> <b>var</b> params<span class="s"> = </span>[],
</code><code id="L874"><span class="ln">874</span> name<span class="s"> = </span>lowerCase.call(b);
</code><code id="L875"><span class="ln">875</span> c.replace(pathValues, <b>function</b> (a, b) {
</code><code id="L876"><span class="ln">876</span> b<span class="s"> && </span>params.push(+b);
</code><code id="L877"><span class="ln">877</span> });
</code><code id="L878"><span class="ln">878</span> <b>if</b> (name<span class="s"> == </span><i>"m"</i><span class="s"> && </span>params.length > <span class="d">2</span>) {
</code><code id="L879"><span class="ln">879</span> data.push([b][concat](params.splice(<span class="d">0</span>, <span class="d">2</span>)));
</code><code id="L880"><span class="ln">880</span> name<span class="s"> = </span><i>"l"</i>;
</code><code id="L881"><span class="ln">881</span> b<span class="s"> = </span>b<span class="s"> == </span><i>"m"</i> ? <i>"l"</i> : <i>"L"</i>;
</code><code id="L882"><span class="ln">882</span> }
</code><code id="L883"><span class="ln">883</span> <b>while</b> (params.length >= paramCounts[name]) {
</code><code id="L884"><span class="ln">884</span> data.push([b][concat](params.splice(<span class="d">0</span>, paramCounts[name])));
</code><code id="L885"><span class="ln">885</span> <b>if</b> (!paramCounts[name]) {
</code><code id="L886"><span class="ln">886</span> <b>break</b>;
</code><code id="L887"><span class="ln">887</span> }
</code><code id="L888"><span class="ln">888</span> }
</code><code id="L889"><span class="ln">889</span> });
</code><code id="L890"><span class="ln">890</span> }
</code><code id="L891"><span class="ln">891</span> data.toString<span class="s"> = </span>R._path2string;
</code><code id="L892"><span class="ln">892</span> <b>return</b> data;
</code><code id="L893"><span class="ln">893</span> });
</code><code id="L894"><span class="ln">894</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L895"><span class="ln">895</span><span class="c"> <span class="s"> * </span>Raphael.parseTransformString
</span></code><code id="L896"><span class="ln">896</span><span class="c"> [ method ]
</span></code><code id="L897"><span class="ln">897</span><span class="c"> **
</span></code><code id="L898"><span class="ln">898</span><span class="c"> <span class="s"> * </span>Utility method
</span></code><code id="L899"><span class="ln">899</span><span class="c"> **
</span></code><code id="L900"><span class="ln">900</span><span class="c"> <span class="s"> * </span>Parses given path string into an array of transformations.
</span></code><code id="L901"><span class="ln">901</span><span class="c"> > Parameters
</span></code><code id="L902"><span class="ln">902</span><span class="c"> <span class="s"> - </span>TString (string|array) transform string or array of transformations (<b>in</b> the last <b>case</b> it will be returned straight away)
</span></code><code id="L903"><span class="ln">903</span><span class="c"> <span class="s"> = </span>(array) array of transformations.
</span></code><code id="L904"><span class="ln">904</span><span class="c"> \*/</span>
</code><code id="L905"><span class="ln">905</span> R.parseTransformString<span class="s"> = </span>cacher(<b>function</b> (TString) {
</code><code id="L906"><span class="ln">906</span> <b>if</b> (!TString) {
</code><code id="L907"><span class="ln">907</span> <b>return</b> <b>null</b>;
</code><code id="L908"><span class="ln">908</span> }
</code><code id="L909"><span class="ln">909</span> <b>var</b> paramCounts<span class="s"> = </span>{r: <span class="d">3</span>, s: <span class="d">4</span>, t: <span class="d">2</span>, m: <span class="d">6</span>},
</code><code id="L910"><span class="ln">910</span> data<span class="s"> = </span>[];
</code><code id="L911"><span class="ln">911</span> <b>if</b> (R.is(TString, array)<span class="s"> && </span>R.is(TString[<span class="d">0</span>], array)) { <span class="c">// rough assumption</span>
</code><code id="L912"><span class="ln">912</span> data<span class="s"> = </span>pathClone(TString);
</code><code id="L913"><span class="ln">913</span> }
</code><code id="L914"><span class="ln">914</span> <b>if</b> (!data.length) {
</code><code id="L915"><span class="ln">915</span> Str(TString).replace(tCommand, <b>function</b> (a, b, c) {
</code><code id="L916"><span class="ln">916</span> <b>var</b> params<span class="s"> = </span>[],
</code><code id="L917"><span class="ln">917</span> name<span class="s"> = </span>lowerCase.call(b);
</code><code id="L918"><span class="ln">918</span> c.replace(pathValues, <b>function</b> (a, b) {
</code><code id="L919"><span class="ln">919</span> b<span class="s"> && </span>params.push(+b);
</code><code id="L920"><span class="ln">920</span> });
</code><code id="L921"><span class="ln">921</span> data.push([name][concat](params));
</code><code id="L922"><span class="ln">922</span> });
</code><code id="L923"><span class="ln">923</span> }
</code><code id="L924"><span class="ln">924</span> data.toString<span class="s"> = </span>R._path2string;
</code><code id="L925"><span class="ln">925</span> <b>return</b> data;
</code><code id="L926"><span class="ln">926</span> });
</code><code id="L927"><span class="ln">927</span><span class="c"> <span class="c">/*\</span>
</span></code><code id="L928"><span class="ln">928</span><span class="c"> <span class="s"> * </span>Raphael.findDotsAtSegment
</span></code><code id="L929"><span class="ln">929</span><span class="c"> [ method ]
</span></code><code id="L930"><span class="ln">930</span><span class="c"> **
</span></code><code id="L931"><span class="ln">931</span><span class="c"> <span class="s"> * </span>Utility method
</span></code><code id="L932"><span class="ln">932</span><span class="c"> **
</span></code><code id="L933"><span class="ln">933</span><span class="c"> <span class="s"> * </span>Find dot coordinates on the given cubic bezier curve at the given t.
</span></code><code id="L934"><span class="ln">934</span><span class="c"> > Parameters
</span></code><code id="L935"><span class="ln">935</span><span class="c"> <span class="s"> - </span>p1x (number) x of the first point of the curve
</span></code><code id="L936"><span class="ln">936</span><span class="c"> <span class="s"> - </span>p1y (number) y of the first point of the curve
</span></code><code id="L937"><span class="ln">937</span><span class="c"> <span class="s"> - </span>c1x (number) x of the first anchor of the curve
</span></code><code id="L938"><span class="ln">938</span><span class="c"> <span class="s"> - </span>c1y (number) y of the first anchor of the curve
</span></code><code id="L939"><span class="ln">939</span><span class="c"> <span class="s"> - </span>c2x (number) x of the second anchor of the curve
</span></code><code id="L940"><span class="ln">940</span><span class="c"> <span class="s"> - </span>c2y (number) y of the second anchor of the curve
</span></code><code id="L941"><span class="ln">941</span><span class="c"> <span class="s"> - </span>p2x (number) x of the second point of the curve
</span></code><code id="L942"><span class="ln">942</span><span class="c"> <span class="s"> - </span>p2y (number) y of the second point of the curve
</span></code><code id="L943"><span class="ln">943</span><span class="c"> <span class="s"> - </span>t (number) position on the curve (<span class="d">0</span>.<span class="d">.1</span>)
</span></code><code id="L944"><span class="ln">944</span><span class="c"> <span class="s"> = </span>(object) point information <b>in</b> format:
</span></code><code id="L945"><span class="ln">945</span><span class="c"> o {
</span></code><code id="L946"><span class="ln">946</span><span class="c"> o x: (number) x coordinate of the point
</span></code><code id="L947"><span class="ln">947</span><span class="c"> o y: (number) y coordinate of the point
</span></code><code id="L948"><span class="ln">948</span><span class="c"> o m: {
</span></code><code id="L949"><span class="ln">949</span><span class="c"> o x: (number) x coordinate of the left anchor
</span></code><code id="L950"><span class="ln">950</span><span class="c"> o y: (number) y coordinate of the left anchor
</span></code><code id="L951"><span class="ln">951</span><span class="c"> o }
</span></code><code id="L952"><span class="ln">952</span><span class="c"> o n: {
</span></code><code id="L953"><span class="ln">953</span><span class="c"> o x: (number) x coordinate of the right anchor
</span></code><code id="L954"><span class="ln">954</span><span class="c"> o y: (number) y coordinate of the right anchor
</span></code><code id="L955"><span class="ln">955</span><span class="c"> o }
</span></code><code id="L956"><span class="ln">956</span><span class="c"> o start: {
</span></code><code id="L957"><span class="ln">957</span><span class="c"> o x: (number) x coordinate of the start of the curve
</span></code><code id="L958"><span class="ln">958</span><span class="c"> o y: (number) y coordinate of the start of the curve
</span></code><code id="L959"><span class="ln">959</span><span class="c"> o }
</span></code><code id="L960"><span class="ln">960</span><span class="c"> o end: {
</span></code><code id="L961"><span class="ln">961</span><span class="c"> o x: (number) x coordinate of the end of the curve
</span></code><code id="L962"><span class="ln">962</span><span class="c"> o y: (number) y coordinate of the end of the curve
</span></code><code id="L963"><span class="ln">963</span><span class="c"> o }
</span></code><code id="L964"><span class="ln">964</span><span class="c"> o alpha: (number) angle of the curve derivative at the point
</span></code><code id="L965"><span class="ln">965</span><span class="c"> o }
</span></code><code id="L966"><span class="ln">966</span><span class="c"> \*/</span>
</code><code id="L967"><span class="ln">967</span> R.findDotsAtSegment<span class="s"> = </span><b>function</b> (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
</code><code id="L968"><span class="ln">968</span> <b>var</b> t1<span class="s"> = </span><span class="d">1</span><span class="s"> - </span>t,
</code><code id="L969"><span class="ln">969</span> x<span class="s"> = </span>pow(t1, <span class="d">3</span>)<span class="s"> * </span>p1x<span class="s"> + </span>pow(t1, <span class="d">2</span>)<span class="s"> * </span><span class="d">3</span><span class="s"> * </span>t<span class="s"> * </span>c1x<span class="s"> + </span>t1<span class="s"> * </span><span class="d">3</span><span class="s"> * </span>t<span class="s"> * </span>t<span class="s"> * </span>c2x<span class="s"> + </span>pow(t, <span class="d">3</span>)<span class="s"> * </span>p2x,
</code><code id="L970"><span class="ln">970</span> y<span class="s"> = </span>pow(t1, <span class="d">3</span>)<span class="s"> * </span>p1y<span class="s"> + </span>pow(t1, <span class="d">2</span>)<span class="s"> * </span><span class="d">3</span><span class="s"> * </span>t<span class="s"> * </span>c1y<span class="s"> + </span>t1<span class="s"> * </span><span class="d">3</span><span class="s"> * </span>t<span class="s"> * </span>t<span class="s"> * </span>c2y<span class="s"> + </span>pow(t, <span class="d">3</span>)<span class="s"> * </span>p2y,
</code><code id="L971"><span class="ln">971</span> mx<span class="s"> = </span>p1x<span class="s"> + </span><span class="d">2</span><span class="s"> * </span>t<span class="s"> * </span>(c1x<span class="s"> - </span>p1x)<span class="s"> + </span>t<span class="s"> * </span>t<span class="s"> * </span>(c2x<span class="s"> - </span><span class="d">2</span><span class="s"> * </span>c1x<span class="s"> + </span>p1x),
</code><code id="L972"><span class="ln">972</span> my<span class="s"> = </span>p1y<span class="s"> + </span><span class="d">2</span><span class="s"> * </span>t<span class="s"> * </span>(c1y<span class="s"> - </span>p1y)<span class="s"> + </span>t<span class="s"> * </span>t<span class="s"> * </span>(c2y<span class="s"> - </span><span class="d">2</span><span class="s"> * </span>c1y<span class="s"> + </span>p1y),
</code><code id="L973"><span class="ln">973</span> nx<span class="s"> = </span>c1x<span class="s"> + </span><span class="d">2</span><span class="s"> * </span>t<span class="s"> * </span>(c2x<span class="s"> - </span>c1x)<span class="s"> + </span>t<span class="s"> * </span>t<span class="s"> * </span>(p2x<span class="s"> - </span><span class="d">2</span><span class="s"> * </span>c2x<span class="s"> + </span>c1x),
</code><code id="L974"><span class="ln">974</span> ny<span class="s"> = </span>c1y<span class="s"> + </span><span class="d">2</span><span class="s"> * </span>t<span class="s"> * </span>(c2y<span class="s"> - </span>c1y)<span class="s"> + </span>t<span class="s"> * </span>t<span class="s"> * </span>(p2y<span class="s"> - </span><span class="d">2</span><span class="s"> * </span>c2y<span class="s"> + </span>c1y),
</code><code id="L975"><span class="ln">975</span> ax<span class="s"> = </span>(<span class="d">1</span><span class="s"> - </span>t)<span class="s"> * </span>p1x<span class="s"> + </span>t<span class="s"> * </span>c1x,
</code><code id="L976"><span class="ln">976</span> ay<span class="s"> = </span>(<span class="d">1</span><span class="s"> - </span>t)<span class="s"> * </span>p1y<span class="s"> + </span>t<span class="s"> * </span>c1y,
</code><code id="L977"><span class="ln">977</span> cx<span class="s"> = </span>(<span class="d">1</span><span class="s"> - </span>t)<span class="s"> * </span>c2x<span class="s"> + </span>t<span class="s"> * </span>p2x,
</code><code id="L978"><span class="ln">978</span> cy<span class="s"> = </span>(<span class="d">1</span><span class="s"> - </span>t)<span class="s"> * </span>c2y<span class="s"> + </span>t<span class="s"> * </span>p2y,
</code><code id="L979"><span class="ln">979</span> alpha<span class="s"> = </span>(<span class="d">90</span><span class="s"> - </span>math.atan2(mx<span class="s"> - </span>nx, my<span class="s"> - </span>ny)<span class="s"> * </span><span class="d">180</span><span class="s"> / </span>PI);
</code><code id="L980"><span class="ln">980</span> (mx > nx<span class="s"> || </span>my < ny)<span class="s"> && </span>(alpha += <span class="d">180</span>);
</code><code id="L981"><span class="ln">981</span> <b>return</b> {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha};
</code><code id="L982"><span class="ln">982</span> };
</code><code id="L983"><span class="ln">983</span> <b>var</b> pathDimensions<span class="s"> = </span>cacher(<b>function</b> (path) {
</code><code id="L984"><span class="ln">984</span> <b>if</b> (!path) {
</code><code id="L985"><span class="ln">985</span> <b>return</b> {x: <span class="d">0</span>, y: <span class="d">0</span>, width: <span class="d">0</span>, height: <span class="d">0</span>};
</code><code id="L986"><span class="ln">986</span> }
</code><code id="L987"><span class="ln">987</span> path<span class="s"> = </span>path2curve(path);
</code><code id="L988"><span class="ln">988</span> <b>var</b> x<span class="s"> = </span><span class="d">0</span>,
</code><code id="L989"><span class="ln">989</span> y<span class="s"> = </span><span class="d">0</span>,
</code><code id="L990"><span class="ln">990</span> X<span class="s"> = </span>[],
</code><code id="L991"><span class="ln">991</span> Y<span class="s"> = </span>[],
</code><code id="L992"><span class="ln">992</span> p;
</code><code id="L993"><span class="ln">993</span> <b>for</b> (<b>var</b> i<span class="s"> = </span><span class="d">0</span>, ii<span class="s"> = </span>path.length; i < ii; i++) {
</code><code id="L994"><span class="ln">994</span> p<span class="s"> = </span>path[i];
</code><code id="L995"><span class="ln">995</span> <b>if</b> (p[<span class="d">0</span>]<span class="s"> == </span><i>"M"</i>) {
</code><code id="L996"><span class="ln">996</span> x<span class="s"> = </span>p[<span class="d">1</span>];
</code><code id="L997"><span class="ln">997</span> y<span class="s"> = </span>p[<span class="d">2</span>];
</code><code id="L998"><span class="ln">998</span> X.push(x);