Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
af5b9786
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
af5b9786
编写于
2月 06, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'pksunkara/dev' into dev
上级
5a871531
95624590
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
139 addition
and
4 deletion
+139
-4
src/math/Color.js
src/math/Color.js
+117
-1
test/unit/math/Color.js
test/unit/math/Color.js
+22
-3
未找到文件。
src/math/Color.js
浏览文件 @
af5b9786
...
...
@@ -52,6 +52,61 @@ THREE.extend( THREE.Color.prototype, {
},
setHSL
:
function
(
h
,
s
,
l
)
{
// h,s,l ranges are in 0.0 - 1.0
var
f
=
function
(
v1
,
v2
,
vh
)
{
var
r
;
if
(
vh
<
0
)
{
vh
+=
1
;
}
if
(
vh
>
1
)
{
vh
-=
1
;
}
if
(
vh
<
1.0
/
6
)
{
r
=
v1
+
(
v2
-
v1
)
*
6
*
vh
;
}
else
if
(
vh
<
1.0
/
2
)
{
r
=
v2
;
}
else
if
(
vh
<
2.0
/
3
)
{
r
=
v1
+
(
v2
-
v1
)
*
6
*
(
2.0
/
3
-
vh
);
}
else
{
r
=
v1
;
}
return
r
;
};
if
(
s
===
0
)
{
this
.
r
=
this
.
g
=
this
.
b
=
l
;
}
else
{
var
p
,
q
;
if
(
l
<=
0.5
)
{
p
=
l
*
(
1.0
+
s
);
}
else
{
p
=
l
+
s
-
(
l
*
s
);
}
q
=
(
2.0
*
l
)
-
p
;
this
.
r
=
f
(
q
,
p
,
h
+
1.0
/
3
);
this
.
g
=
f
(
q
,
p
,
h
);
this
.
b
=
f
(
q
,
p
,
h
-
1.0
/
3
);
}
return
this
;
},
setHSV
:
function
(
h
,
s
,
v
)
{
// based on MochiKit implementation by Bob Ippolito
...
...
@@ -248,7 +303,68 @@ THREE.extend( THREE.Color.prototype, {
getStyle
:
function
()
{
return
'
rgb(
'
+
(
(
this
.
r
*
255
)
|
0
)
+
'
,
'
+
(
(
this
.
g
*
255
)
|
0
)
+
'
,
'
+
(
(
this
.
b
*
255
)
|
0
)
+
'
)
'
;
return
'
rgb(
'
+
(
(
this
.
r
*
255
)
|
0
)
+
'
,
'
+
(
(
this
.
g
*
255
)
|
0
)
+
'
,
'
+
(
(
this
.
b
*
255
)
|
0
)
+
'
)
'
;
},
getHSL
:
function
(
hsl
)
{
// h,s,l ranges are in 0.0 - 1.0
var
r
=
this
.
r
;
var
g
=
this
.
g
;
var
b
=
this
.
b
;
var
max
=
Math
.
max
(
Math
.
max
(
r
,
g
),
b
);
var
min
=
Math
.
min
(
Math
.
min
(
r
,
g
),
b
);
var
hue
,
saturation
;
var
lightness
=
(
min
+
max
)
/
2.0
;
if
(
min
===
max
)
{
hue
=
0
;
saturation
=
0
;
}
else
{
var
delta
=
max
-
min
;
if
(
lightness
<=
0.5
)
{
saturation
=
delta
/
(
max
+
min
);
}
else
{
saturation
=
delta
/
(
2
-
max
-
min
);
}
if
(
r
==
max
)
{
hue
=
(
g
-
b
)
/
delta
;
}
else
if
(
g
==
max
)
{
hue
=
2
+
(
(
b
-
r
)
/
delta
);
}
else
{
hue
=
4
+
(
(
r
-
g
)
/
delta
);
}
hue
/=
6
;
if
(
hue
<
0
)
{
hue
+=
1
;
}
if
(
hue
>
1
)
{
hue
-=
1
;
}
}
if
(
hsl
===
undefined
)
{
hsl
=
{
h
:
0
,
s
:
0
,
l
:
0
};
}
hsl
.
h
=
hue
;
hsl
.
s
=
saturation
;
hsl
.
l
=
lightness
;
return
hsl
;
},
...
...
test/unit/math/Color.js
浏览文件 @
af5b9786
...
...
@@ -157,13 +157,32 @@ test( "getHexString", function(){
});
test
(
"
getStyle
"
,
function
(){
var
c
=
new
THREE
.
Color
(
'
plum
'
);
var
c
=
new
THREE
.
Color
(
'
plum
'
);
var
res
=
c
.
getStyle
();
ok
(
res
==
'
rgb(221,160,221)
'
,
"
style:
"
+
res
);
});
test
(
"
getHSL
"
,
function
()
{
var
c
=
new
THREE
.
Color
(
0x80ffff
);
var
hsl
=
c
.
getHSL
();
ok
(
hsl
.
h
==
0.5
,
"
hue:
"
+
hsl
.
h
);
ok
(
hsl
.
s
==
1.0
,
"
saturation:
"
+
hsl
.
s
);
ok
(
(
Math
.
round
(
parseFloat
(
hsl
.
l
)
*
100
)
/
100
)
==
0.75
,
"
lightness:
"
+
hsl
.
l
);
});
test
(
"
setHSL
"
,
function
()
{
var
c
=
new
THREE
.
Color
();
c
.
setHSL
(
0.75
,
1.0
,
0.25
);
var
hsl
=
c
.
getHSL
();
ok
(
hsl
.
h
==
0.75
,
"
hue:
"
+
hsl
.
h
);
ok
(
hsl
.
s
==
1.00
,
"
saturation:
"
+
hsl
.
s
);
ok
(
hsl
.
l
==
0.25
,
"
lightness:
"
+
hsl
.
l
);
});
test
(
"
getHSV
"
,
function
(){
var
c
=
new
THREE
.
Color
(
'
maroon
'
);
var
c
=
new
THREE
.
Color
(
'
maroon
'
);
var
hsv
=
c
.
getHSV
();
ok
(
hsv
.
h
==
0
,
"
hue:
"
+
hsv
.
h
);
...
...
@@ -173,7 +192,7 @@ test( "getHSV", function(){
});
test
(
"
setHSV
"
,
function
(){
var
c
=
new
THREE
.
Color
();
var
c
=
new
THREE
.
Color
();
c
.
setHSV
(
0
,
1
,
1
);
var
hsv
=
c
.
getHSV
();
ok
(
hsv
.
h
==
0
,
"
hue:
"
+
hsv
.
h
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录