Marching squares: Difference between revisions

m
Python example
m (Python example)
Line 30:
points = [(3, 4), (4, 3), (4, 2), (4, 1), (3, 0), (2, 1), (2, 1), (1, 2), (1, 3), (2, 4), (3, 4)]
</pre>
 
=={{header|Python}}==
<lang python>from numpy import array, round
from skimage import measure
 
example = array([
[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]
])
 
def transform(xy, xmax):
x, y = xy
return (y, xmax - x)
 
# Find contours at a constant value of 0.1 and extract the first one found
contours = round(measure.find_contours(example, 0.1))[0]
print('[', ', '.join([str((p[1], 6 - p[0])) for p in contours]), ']')
</lang>{{out}}
<pre>
[ (3.0, 1.0), (2.0, 2.0), (2.0, 2.0), (1.0, 3.0), (1.0, 4.0), (2.0, 5.0), (3.0, 5.0), (4.0, 4.0), (4.0, 3.0), (4.0, 2.0), (3.0, 1.0) ]
</pre>
 
 
=={{header|Wren}}==
4,107

edits