Voronoi diagram: Difference between revisions

no edit summary
m (→‎{{header|Perl}}: typo in image link)
No edit summary
Line 2,657:
return check
end sub</lang>
 
{{trans|Python}}
<lang Yabasic>width = 500 : height = 500
open window width, height
 
export sub hypot(a, b)
return (sqrt(a^2+b^2))
end sub
sub generate_voronoi_diagram(width, height, num_cells)
local nx(num_cells), ny(num_cells), nr(num_cells), ng(num_cells), nb(num_cells)
 
for i = 1 to num_cells
nx(i) = ran(width)
ny(i) = ran(height)
nr(i) = ran(256)
ng(i) = ran(256)
nb(i) = ran(256)
next
for y = 1 to height
for x = 1 to width
dmin = hypot(width-1, height-1)
j = -1
for i = 1 to num_cells
d = hypot(nx(i)-x, ny(i)-y)
if d < dmin dmin = d : j = i
next
color nr(j), ng(j), ng(j)
dot x, y
next
next
 
end sub
generate_voronoi_diagram(width, height, 25)</lang>
 
=={{header|zkl}}==
672

edits