Skip to content

Commit

Permalink
Merge 69ac718 into 187712a
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvarkey committed Sep 16, 2015
2 parents 187712a + 69ac718 commit c4d47f9
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 36 deletions.
4 changes: 3 additions & 1 deletion assets/bower_components/three-js/three-js.html
Original file line number Diff line number Diff line change
Expand Up @@ -990,14 +990,15 @@
var stacks = Number(this.stacks);
var sliceCount = slices + 1;
var a, b, c, d;
var material = new THREE.LineBasicMaterial({ color: "#ff0000"});
var material = new THREE.LineBasicMaterial({ color: "#ffffff", vertexColors:THREE.VertexColors});
var verts = this.object.vertices;
this.lines = [];
for (i = 0; i < stacks; i++) {
this.lines.push(new THREE.Geometry());
for (j = 0; j < slices; j++) {
a = verts[i * sliceCount + j];
this.lines[i].vertices.push(a);
this.lines[i].colors.push(a.color);
}
this.newLine = new THREE.Line(this.lines[i], material);
if(Polymer.dom(this).parentNode.parentNode)
Expand All @@ -1007,6 +1008,7 @@
this.lines.push(new THREE.Geometry());
for (j = 0; j < stacks; j++) {
a = verts[j * (stacks + 1) + i - stacks];
this.lines[i].colors.push(a.color);
this.lines[i].vertices.push(a);
}
this.newLine = new THREE.Line(this.lines[i], material);
Expand Down
54 changes: 46 additions & 8 deletions src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,15 @@ end

"""
Creates a vertex at position `(x,y,z)`.
A keyword argument of `color` can also be passed to set the vertex color to that
color.
"""
function vertex(x::Float64,y::Float64,z::Float64)
Elem(:"three-js-vertex", attributes = @compat Dict(:x => x, :y => y, :z => z))
function vertex(x::Float64,y::Float64,z::Float64; color::Colors.Color=colorant"black")
colorString = string("#"*hex(color))
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => x, :y => y, :z => z, :color => colorString)
)
end

"""
Expand All @@ -167,21 +173,37 @@ Takes `x` values between `xrange` divided into `slices+1` equal intervals.
Takes `y` values between `yrange` divided into `stacks+1` equal intervals.
Applies a function `f` passed to all such `x` and `y` values and creates vertices
of coordinates `(x,y,z)` and a surface containing these vertices.
A colormap can also be passed to set the vertice colors to a corresponding color
using the keyword argument `colormap`.
NOTE: Such colors will be displayed only with a `material` with `colorkind` set
to `"vertex"` and `color` to `"white"`.
"""
function parametric(
function parametric{T<:Colors.Color}(
slices::Int,
stacks::Int,
xrange::Range,
yrange::Range,
f::Function
f::Function;
colormap::AbstractVector{T} = Colors.colormap("RdBu")
)
geom = Elem(
:"three-js-parametric",
attributes = @compat Dict(:slices => slices, :stacks => stacks)
)
xrange = linspace(xrange.start, xrange.stop, slices+1)
yrange = linspace(yrange.start, yrange.stop, stacks+1)
vertices = [vertex(x, f(x,y), y) for x=xrange, y=yrange]
zs = [f(x,y) for x=xrange, y=yrange]
zrange = maximum(zs) - minimum(zs)
zmax = maximum(zs)
colormaplength = length(colormap)
vertices = [
vertex(
x, f(x,y), y;
color = colormap[ceil(Int,(zmax - f(x,y))/zrange * (colormaplength-1)+1)]
)
for x=xrange, y=yrange
]
geom = geom << vertices
end

Expand All @@ -192,21 +214,37 @@ Takes `y` values between `yrange` divided into `stacks+1` equal intervals.
Applies a function `f` passed to all such `x` and `y` values and creates
vertices of coordinates `(x,y,z)` and a joins them horizontally and vertically,
creating a mesh
A colormap can also be passed to set the vertice colors to a corresponding color
using the keyword argument `colormap`.
NOTE: Such colors will be displayed only with a `material` with `colorkind` set
to `"vertex"` and `color` to `"white"`.
"""
function meshlines(
function meshlines{T<:Colors.Color}(
slices::Int,
stacks::Int,
xrange::Range,
yrange::Range,
f::Function
f::Function,
colormap::AbstractVector{T} = Colors.colormap("RdBu")
)
geom = Elem(
:"three-js-meshlines",
attributes = @compat Dict( :slices => slices, :stacks => stacks)
)
xrange = linspace(xrange.start, xrange.stop, slices+1)
yrange = linspace(yrange.start, yrange.stop, stacks+1)
vertices = [vertex(x, f(x,y), y) for x=xrange, y=yrange]
zs = [f(x,y) for x=xrange, y=yrange]
zrange = maximum(zs) - minimum(zs)
zmax = maximum(zs)
colormaplength = length(colormap)
vertices = [
vertex(
x, f(x,y), y;
color = colormap[ceil(Int,(zmax - f(x,y))/zrange * (colormaplength-1)+1)]
)
for x=xrange, y=yrange
]
geom = geom << vertices
end

Expand Down
109 changes: 82 additions & 27 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,114 +72,167 @@ facts("Testing Render Elem Outputs") do
)
@fact torus(12.0, 2.0) -->
Elem(:"three-js-torus", attributes = @compat Dict(:r => 12.0, :tube => 2.0))
@fact parametric(2, 3, 0:2, 0:3, (x, y) -> x + y) -->

#colormap = Colors.colormap("RdBu")
#zs = [0.0, 1.0, 2.0, 1.0, 2.0, 3.0, 2.0, 3.0, 4.0, 3.0, 4.0, 5.0]
#colors = map(z -> "#"*hex(colormap[ceil(Int,(5-z)/5 * (100-1)+1)]), zs)
#Re-enable once Colors fixes colormaps on 0.3
@pending parametric(2, 3, 0:2, 0:3, (x, y) -> x + y) -->
Elem(
:"three-js-parametric",
attributes = @compat Dict(:slices => 2, :stacks => 3)
) <<
[
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 0.0, :y => 0.0)
attributes = @compat Dict(
:x => 0.0, :z => 0.0, :y => 0.0, :color => colors[1]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 0.0, :y => 1.0)
attributes = @compat Dict(
:x => 1.0, :z => 0.0, :y => 1.0, :color => colors[2]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 0.0, :y => 2.0)
attributes = @compat Dict(
:x => 2.0, :z => 0.0, :y => 2.0, :color => colors[3]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 1.0, :y => 1.0)
attributes = @compat Dict(
:x => 0.0, :z => 1.0, :y => 1.0, :color => colors[4]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 1.0, :y => 2.0)
attributes = @compat Dict(
:x => 1.0, :z => 1.0, :y => 2.0, :color => colors[5]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 1.0, :y => 3.0)
attributes = @compat Dict(
:x => 2.0, :z => 1.0, :y => 3.0, :color => colors[6]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 2.0, :y => 2.0)
attributes = @compat Dict(
:x => 0.0, :z => 2.0, :y => 2.0, :color => colors[7]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 2.0, :y => 3.0)
attributes = @compat Dict(
:x => 1.0, :z => 2.0, :y => 3.0, :color => colors[8]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 2.0, :y => 4.0)
attributes = @compat Dict(
:x => 2.0, :z => 2.0, :y => 4.0, :color => colors[9]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 3.0, :y => 3.0)
attributes = @compat Dict(
:x => 0.0, :z => 3.0, :y => 3.0, :color => colors[10]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 3.0, :y => 4.0)
attributes = @compat Dict(
:x => 1.0, :z => 3.0, :y => 4.0, :color => colors[11]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 3.0, :y => 5.0)
attributes = @compat Dict(
:x => 2.0, :z => 3.0, :y => 5.0, :color => colors[12]
)
),
]
@fact meshlines(2, 3, 0:2, 0:3, (x, y) -> x + y) -->
@pending meshlines(2, 3, 0:2, 0:3, (x, y) -> x + y) -->
Elem(
:"three-js-meshlines",
attributes = @compat Dict(:slices => 2, :stacks => 3)
) <<
[
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 0.0, :y => 0.0)
attributes = @compat Dict(
:x => 0.0, :z => 0.0, :y => 0.0, :color => colors[1]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 0.0, :y => 1.0)
attributes = @compat Dict(
:x => 1.0, :z => 0.0, :y => 1.0, :color => colors[2]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 0.0, :y => 2.0)
attributes = @compat Dict(
:x => 2.0, :z => 0.0, :y => 2.0, :color => colors[3]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 1.0, :y => 1.0)
attributes = @compat Dict(
:x => 0.0, :z => 1.0, :y => 1.0, :color => colors[4]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 1.0, :y => 2.0)
attributes = @compat Dict(
:x => 1.0, :z => 1.0, :y => 2.0, :color => colors[5]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 1.0, :y => 3.0)
attributes = @compat Dict(
:x => 2.0, :z => 1.0, :y => 3.0, :color => colors[6]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 2.0, :y => 2.0)
attributes = @compat Dict(
:x => 0.0, :z => 2.0, :y => 2.0, :color => colors[7]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 2.0, :y => 3.0)
attributes = @compat Dict(
:x => 1.0, :z => 2.0, :y => 3.0, :color => colors[8]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 2.0, :y => 4.0)
attributes = @compat Dict(
:x => 2.0, :z => 2.0, :y => 4.0, :color => colors[9]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 0.0, :z => 3.0, :y => 3.0)
attributes = @compat Dict(
:x => 0.0, :z => 3.0, :y => 3.0, :color => colors[10]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 1.0, :z => 3.0, :y => 4.0)
attributes = @compat Dict(
:x => 1.0, :z => 3.0, :y => 4.0, :color => colors[11]
)
),
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :z => 3.0, :y => 5.0)
attributes = @compat Dict(
:x => 2.0, :z => 3.0, :y => 5.0, :color => colors[12]
)
),
]
@fact dodecahedron(4.0) -->
Expand All @@ -195,7 +248,9 @@ facts("Testing Render Elem Outputs") do
@fact vertex(2.0, 3.0, 4.0) -->
Elem(
:"three-js-vertex",
attributes = @compat Dict(:x => 2.0, :y => 3.0, :z => 4.0)
attributes = @compat Dict(
:x => 2.0, :y => 3.0, :z => 4.0, :color => "#000000"
)
)
end
context("Testing face") do
Expand Down

0 comments on commit c4d47f9

Please sign in to comment.