-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolid-parakeet.js
68 lines (61 loc) · 1.4 KB
/
solid-parakeet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
( function ( root ) {
function call( a, b ) {
var m = map( a, b )
return hsla( theta( m.z ), phi( m.x, m.y ) )
}
function hsla( theta, phi ) {
function fn( h, s, l, a ) {
return 'hsla('
+ h
+ ', '
+ s
+ '%, '
+ l
+ '%, '
+ a
+ ')'
}
function h( phi ) {
return phi * ( 180 / Math.PI )
}
var s = 100
function l( theta ) {
return ( Math.PI - theta ) / Math.PI * 100
}
var a = 1
if ( Number.isNaN( h( phi ) ) || Number.isNaN( l( theta ) ) ) {
return fn( 0, 0, 50, a)
}
return fn( h( phi ), s, l( theta ), a )
}
function map( a, b ) {
function x( a, b ) {
return ( 2 * a ) / ( a*a + b*b + 1 )
}
function y( a, b ) {
return ( 2 * b ) / ( a*a + b*b + 1 )
}
function z( c ) {
return ( a*a + b*b - 1 ) / ( a*a + b*b + 1 )
}
if ( Math.abs( a ) == Infinity || Math.abs( b ) == Infinity ) {
return { x: 0, y: 0, z: 1 }
}
return { x: x( a, b ), y: y( a, b ), z: z( a, b ) }
}
function phi( x, y ) {
return Math.atan2( y, x )
}
function theta( z ) {
return Math.acos( z )
}
if ( typeof define === 'function' && define.amd ) {
define( [], function () {
return call
} )
} else if ( typeof exports === 'object' ) {
module.exports = call
} else {
root.solidparakeet = call
}
} )( this )