Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
4784dfe7
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,发现更多精彩内容 >>
提交
4784dfe7
编写于
3月 22, 2014
作者:
T
thorsummoner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implemented Hilbert in 2d
上级
8413a860
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
331 addition
and
0 deletion
+331
-0
examples/canvas_lines_colors_2d.html
examples/canvas_lines_colors_2d.html
+212
-0
examples/js/geometries/hilbert2D.js
examples/js/geometries/hilbert2D.js
+59
-0
src/extras/geometries/hilbert2D.js
src/extras/geometries/hilbert2D.js
+60
-0
未找到文件。
examples/canvas_lines_colors_2d.html
0 → 100644
浏览文件 @
4784dfe7
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - lines - cubes - colors
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
background-color
:
#000000
;
margin
:
0px
;
overflow
:
hidden
;
}
a
{
color
:
#0078ff
;
}
#info
{
position
:
absolute
;
top
:
10px
;
width
:
100%
;
color
:
#ffffff
;
padding
:
5px
;
font-family
:
Monospace
;
font-size
:
13px
;
text-align
:
center
;
z-index
:
100
;
}
a
{
color
:
orange
;
text-decoration
:
none
;
}
a
:hover
{
color
:
#0080ff
;
}
</style>
</head>
<body>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
>
three.js
</a>
- color lines WebGL demo
[
<a
href=
"http://en.wikipedia.org/wiki/Hilbert_curve"
>
Hilbert curve
</a>
thanks to
<a
href=
"http://www.openprocessing.org/visuals/?visualID=15599"
>
Thomas Diewald
</a>
]
</div>
<script
src=
"../build/three.min.js"
></script>
<script
src=
"js/Detector.js"
></script>
<script
src=
"js/libs/stats.min.js"
></script>
<script
src=
"js/geometries/hilbert2D.js"
></script>
<script>
if
(
!
Detector
.
webgl
)
Detector
.
addGetWebGLMessage
();
var
mouseX
=
0
,
mouseY
=
0
,
windowHalfX
=
window
.
innerWidth
/
2
,
windowHalfY
=
window
.
innerHeight
/
2
,
camera
,
scene
,
renderer
,
material
;
init
();
animate
();
function
init
()
{
var
i
,
container
;
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
camera
=
new
THREE
.
PerspectiveCamera
(
33
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
10000
);
camera
.
position
.
z
=
700
;
scene
=
new
THREE
.
Scene
();
renderer
=
new
THREE
.
CanvasRenderer
(
{
antialias
:
false
}
);
renderer
.
setClearColor
(
0x000000
,
1
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
container
.
appendChild
(
renderer
.
domElement
);
var
geometry3
=
new
THREE
.
Geometry
(),
points
=
hilbert2D
(
new
THREE
.
Vector3
(
0
,
0
,
0
),
400.0
,
4
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
),
colors3
=
[];
for
(
i
=
0
;
i
<
points
.
length
;
i
++
)
{
geometry3
.
vertices
.
push
(
points
[
i
]
);
colors3
[
i
]
=
new
THREE
.
Color
(
0xffffff
);
colors3
[
i
].
setHSL
(
i
/
points
.
length
,
1.0
,
0.5
);
}
geometry3
.
colors
=
colors3
;
// lines
material
=
new
THREE
.
LineBasicMaterial
(
{
color
:
0xffffff
,
opacity
:
1
,
linewidth
:
3
,
vertexColors
:
THREE
.
VertexColors
}
);
var
line
,
p
,
scale
=
0.3
,
d
=
225
;
line
=
new
THREE
.
Line
(
geometry3
,
material
);
line
.
scale
.
x
=
line
.
scale
.
y
=
line
.
scale
.
z
=
scale
*
1.5
;
line
.
position
.
x
=
0
;
line
.
position
.
y
=
0
;
line
.
position
.
z
=
0
;
scene
.
add
(
line
);
//
stats
=
new
Stats
();
stats
.
domElement
.
style
.
position
=
'
absolute
'
;
stats
.
domElement
.
style
.
top
=
'
0px
'
;
//container.appendChild( stats.domElement );
//
document
.
addEventListener
(
'
mousemove
'
,
onDocumentMouseMove
,
false
);
document
.
addEventListener
(
'
touchstart
'
,
onDocumentTouchStart
,
false
);
document
.
addEventListener
(
'
touchmove
'
,
onDocumentTouchMove
,
false
);
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
onWindowResize
()
{
windowHalfX
=
window
.
innerWidth
/
2
;
windowHalfY
=
window
.
innerHeight
/
2
;
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
composer
.
reset
();
}
function
onDocumentMouseMove
(
event
)
{
mouseX
=
event
.
clientX
-
windowHalfX
;
mouseY
=
event
.
clientY
-
windowHalfY
;
}
function
onDocumentTouchStart
(
event
)
{
if
(
event
.
touches
.
length
>
1
)
{
event
.
preventDefault
();
mouseX
=
event
.
touches
[
0
].
pageX
-
windowHalfX
;
mouseY
=
event
.
touches
[
0
].
pageY
-
windowHalfY
;
}
}
function
onDocumentTouchMove
(
event
)
{
if
(
event
.
touches
.
length
==
1
)
{
event
.
preventDefault
();
mouseX
=
event
.
touches
[
0
].
pageX
-
windowHalfX
;
mouseY
=
event
.
touches
[
0
].
pageY
-
windowHalfY
;
}
}
//
function
animate
()
{
requestAnimationFrame
(
animate
);
render
();
stats
.
update
();
}
function
render
()
{
camera
.
position
.
x
+=
(
mouseX
-
camera
.
position
.
x
)
*
.
05
;
camera
.
position
.
y
+=
(
-
mouseY
+
200
-
camera
.
position
.
y
)
*
.
05
;
camera
.
lookAt
(
scene
.
position
);
var
time
=
Date
.
now
()
*
0.0005
;
for
(
var
i
=
0
;
i
<
scene
.
children
.
length
;
i
++
)
{
var
object
=
scene
.
children
[
i
];
if
(
object
instanceof
THREE
.
Line
)
object
.
rotation
.
y
=
time
*
(
i
%
2
?
1
:
-
1
);
}
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
examples/js/geometries/hilbert2D.js
0 → 100644
浏览文件 @
4784dfe7
/**
* Hilbert Curve: Generates 2D-Coordinates in a very fast way.
*
* @author Dylan Grafmyre
*
* Based on work by:
* @author Thomas Diewald
* @link http://www.openprocessing.org/sketch/15493
*
* @param center Center of Hilbert curve.
* @param size Total width of Hilbert curve.
* @param iterations Number of subdivisions.
* @param v1 Corner index -X, -Z.
* @param v2 Corner index -X, +Z.
* @param v3 Corner index +X, +Z.
* @param v4 Corner index +X, -Z.
*/
function
hilbert2D
(
center
,
size
,
iterations
,
v0
,
v1
,
v2
,
v3
)
{
// Default Vars
var
center
=
undefined
!==
center
?
center
:
new
THREE
.
Vector3
(
0
,
0
,
0
),
size
=
undefined
!==
size
?
size
:
10
,
half
=
size
/
2
,
iterations
=
undefined
!==
iterations
?
iterations
:
1
,
v0
=
undefined
!==
v0
?
v0
:
0
,
v1
=
undefined
!==
v1
?
v1
:
1
,
v2
=
undefined
!==
v2
?
v2
:
2
,
v3
=
undefined
!==
v3
?
v3
:
3
;
var
vec_s
=
[
new
THREE
.
Vector3
(
center
.
x
-
half
,
center
.
y
,
center
.
z
-
half
),
new
THREE
.
Vector3
(
center
.
x
-
half
,
center
.
y
,
center
.
z
+
half
),
new
THREE
.
Vector3
(
center
.
x
+
half
,
center
.
y
,
center
.
z
+
half
),
new
THREE
.
Vector3
(
center
.
x
+
half
,
center
.
y
,
center
.
z
-
half
)
];
var
vec
=
[
vec_s
[
v0
],
vec_s
[
v1
],
vec_s
[
v2
],
vec_s
[
v3
]
];
// Recurse iterations
if
(
0
<=
--
iterations
)
{
var
tmp
=
[];
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
0
],
half
,
iterations
,
v0
,
v3
,
v2
,
v1
)
);
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
1
],
half
,
iterations
,
v0
,
v1
,
v2
,
v3
)
);
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
2
],
half
,
iterations
,
v0
,
v1
,
v2
,
v3
)
);
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
3
],
half
,
iterations
,
v2
,
v1
,
v0
,
v3
)
);
// Return recursive call
return
tmp
;
}
// Return complete Hilbert Curve.
return
vec
;
}
src/extras/geometries/hilbert2D.js
0 → 100644
浏览文件 @
4784dfe7
/**
* Hilbert Curve: Generates 2D-Coordinates in a very fast way.
*
* @author Dylan Grafmyre
*
* Based on work by:
* @author Thomas Diewald
* @link http://www.openprocessing.org/sketch/15493
*
* @param center Center of Hilbert curve.
* @param size Total width of Hilbert curve.
* @param iterations Number of subdivisions.
* @param v1 Corner index -X, -Z.
* @param v2 Corner index -X, +Z.
* @param v3 Corner index +X, +Z.
* @param v4 Corner index +X, -Z.
*/
function
hilbert2D
(
center
,
size
,
iterations
,
v0
,
v1
,
v2
,
v3
)
{
// Default Vars
var
center
=
undefined
!==
center
?
center
:
new
THREE
.
Vector3
(
0
,
0
,
0
),
size
=
undefined
!==
size
?
size
:
10
,
size
=
undefined
!==
side
?
side
:
10
,
half
=
size
/
2
,
iterations
=
undefined
!==
iterations
?
iterations
:
1
,
v0
=
undefined
!==
v0
?
v0
:
0
,
v1
=
undefined
!==
v1
?
v1
:
1
,
v2
=
undefined
!==
v2
?
v2
:
2
,
v3
=
undefined
!==
v3
?
v3
:
3
;
var
vec_s
=
[
new
THREE
.
Vector3
(
center
.
x
-
half
,
center
.
y
,
center
.
z
-
half
),
new
THREE
.
Vector3
(
center
.
x
-
half
,
center
.
y
,
center
.
z
+
half
),
new
THREE
.
Vector3
(
center
.
x
+
half
,
center
.
y
,
center
.
z
+
half
),
new
THREE
.
Vector3
(
center
.
x
+
half
,
center
.
y
,
center
.
z
-
half
)
];
var
vec
=
[
vec_s
[
v0
],
vec_s
[
v1
],
vec_s
[
v2
],
vec_s
[
v3
]
];
// Recurse iterations
if
(
0
<=
--
iterations
)
{
var
tmp
=
[];
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
0
],
half
,
iterations
,
v0
,
v3
,
v2
,
v1
)
);
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
1
],
half
,
iterations
,
v0
,
v1
,
v2
,
v3
)
);
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
2
],
half
,
iterations
,
v0
,
v1
,
v2
,
v3
)
);
Array
.
prototype
.
push
.
apply
(
tmp
,
hilbert2D
(
vec
[
3
],
half
,
iterations
,
v2
,
v1
,
v0
,
v3
)
);
// Return recursive call
return
tmp
;
}
// Return complete Hilbert Curve.
return
vec
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录