Created
November 11, 2014 03:40
-
-
Save eschnett/a9e7f70e4910e4ba2768 to your computer and use it in GitHub Desktop.
Sample code for plotting vertices and edges of a mesh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mkplot(elt::Element) | |
maxcolor = 100 | |
rank_colormaps = (colormap("Reds", maxcolor+1), | |
colormap("Greens", maxcolor+1), | |
colormap("Blues", maxcolor+1), | |
colormap("Purples", maxcolor+1), | |
colormap("Oranges", maxcolor+1)) | |
elts = boundaries(elt, elt.rank) | |
ctr = meanpos(elts) | |
contract(pos) = pos - 0.1 * (pos-ctr) | |
pos1(pos) = length(pos) >= 1 ? pos[1] : 0.0 | |
pos2(pos) = length(pos) >= 2 ? pos[2] : 0.0 | |
pos3(pos) = length(pos) >= 3 ? pos[3] : 0.0 | |
xy(pos) = (pos1(pos), pos2(pos)) | |
z(pos) = pos3(pos) | |
cmin = 25; cmax = 75 | |
zmin = 0.0; zmax = 1.0 | |
colval(pos) = clamp(int(cmin + (cmax-cmin) * (z(pos)-zmin) / (zmax-zmin)), | |
0, maxcolor) | |
col(pos) = rank_colormaps[elt.rank+1][colval(pos)+1] | |
ctxts = {} | |
if elt.rank==0 | |
for i in 1:length(elts) | |
push!(ctxts, compose(context(), | |
circle(xy(contract(elts[i].pos))..., 0.03), | |
fill(col(ctr)))) | |
end | |
else | |
for i in 1:length(elts) | |
for j in i+1:length(elts) | |
push!(ctxts, compose(context(), | |
line([xy(contract(elts[i].pos)), | |
xy(contract(elts[j].pos))]), | |
stroke(col(ctr)))) | |
end | |
end | |
end | |
compose(context(), ctxts) | |
end | |
function mkplot(mf::Manifold) | |
ctxts = {} | |
for rank in 0:mf.maxrank | |
for elt in mf.eltss[rank+1] | |
push!(ctxts, mkplot(elt)) | |
end | |
end | |
compose(context(), ctxts) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment