Marching squares: Difference between revisions

m
julia example
(Added Wren)
m (julia example)
Line 5:
 
See: [https://en.wikipedia.org/wiki/Marching_squares Marching squares]
 
 
=={{header|Julia}}==
Uses the marching squares algorithm: see github.com/JuliaGeometry/Contour.jl/blob/master/src/Contour.jl
<lang ruby>using Contour, Plots
 
const example = Float64.([
0 0 0 0 0;
0 0 0 0 0;
0 0 1 1 0;
0 0 1 1 0;
0 0 0 1 0;
0 0 0 0 0;
])
cl = first(levels(contours(1:6, 1:5, example)))
xs, ys = coordinates(first(lines(cl)))
 
# Showing the points of the contour as origin (0, 0) at bottom left
points = [(Int(round(ys[i])) - 1, 6 - Int(round(xs[i]))) for i in eachindex(xs)]
@show points
</lang>{{out}}
<pre>
points = [(3, 4), (4, 3), (4, 2), (4, 1), (3, 0), (2, 1), (2, 1), (1, 2), (1, 3), (2, 4), (3, 4)]
</pre>
 
 
4,102

edits