Voronoi diagram: Difference between revisions

Added Easylang
(Added Easylang)
 
(3 intermediate revisions by 2 users not shown)
Line 616:
</syntaxhighlight>
 
 
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=fZBBboMwFET3PsVbVZAqjl2JXTlJxAIMqJYS0xqngttXtqlo2qgb+H4zns8w3pzhbX2faOmQAvBDuHnH/OEDRcuBlmc6DnSlkMLNNgwzNS+VGCePJUxkGC+75dzwVONb11sX0Eppjuikrf9o5o+mkibTlpUaFTdFHv0RLr8h0F+to0Zz4hs9+MrNS52rF24524YjS0nh1jyv5e60Iz2vKXyH+7b+DtoM7Q6luH+b6TL5WDlamw1ep8+BhRM6FldSVaw/T5vNDyagpNbpIVKqFDkx/oYHbVNyrpjycsM4RtVYby4DSlZCii8= Run it]
 
{{trans|BASIC256}}
<syntaxhighlight>
func hypo a b .
return sqrt (a * a + b * b)
.
nsites = 25
for i to nsites
nx[] &= randint 1001 - 1
ny[] &= randint 1001 - 1
nc[] &= randint 1000 - 1
.
for y = 0 to 1000
for x = 0 to 1000
dmin = 1 / 0
for i to nsites
d = hypo (nx[i] - x) (ny[i] - y)
if d < dmin
dmin = d
imin = i
.
.
color nc[imin]
move x / 10 - 0.05 y / 10 - 0.05
rect 0.11 0.11
.
.
color 000
for i to nsites
move nx[i] / 10 ny[i] / 10
circle 0.5
.
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
Line 655 ⟶ 691:
Bsave "Voronoi_diadram.bmp",0
Sleep</syntaxhighlight>
 
 
=={{header|Go}}==
Line 2,130 ⟶ 2,165:
 
Note that for large numbers of points, using a KDTree will be much faster thanks to lookups in log(N) time rather than N comparisons at every coordinate. The code below has running time O(X*Y*log(N)), whereas the code above has running time O(X*Y*N). For 1000 points, the code below is 250x faster than the above.
 
Alternative metrics can be supported by using a [https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KDTree.html#sklearn.neighbors.KDTree.query scikit-learn KDTree ].
 
<syntaxhighlight lang="python">
Line 2,151 ⟶ 2,188:
# Export an RGB image
rgb = colors[labels]
img = Image.fromarray(rgb, mode='RGB').save('VoronoiDiagram.png', 'PNG')
img.save('VoronoiDiagram.png', 'PNG')
img.show()
return rgb
</syntaxhighlight>
Line 3,265 ⟶ 3,304:
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
import "random" for Random
1,995

edits