Voronoi diagram: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,268: | Line 1,268: | ||
# generate diagram by coloring each pixel with color of nearest site |
# generate diagram by coloring each pixel with color of nearest site |
||
for x in 0 .. img_width |
for x in 0 ..< img_width: |
||
for y in 0 .. img_height |
for y in 0 ..< img_height: |
||
var dMin = dot(img_width, img_height) |
var dMin = dot(img_width, img_height) |
||
var sMin: int |
var sMin: int |
||
for s in 0 .. nSites |
for s in 0 ..< nSites: |
||
if (let d = dot(sx[s] - x, sy[s] - y); d) < dMin: |
if (let d = dot(sx[s] - x, sy[s] - y); d) < dMin: |
||
(sMin, dMin) = (s, d) |
(sMin, dMin) = (s, d) |
||
Line 1,280: | Line 1,280: | ||
# mark each site with a black box |
# mark each site with a black box |
||
let black = img.setColor(0x000000) |
let black = img.setColor(0x000000) |
||
for s in 0 .. nSites |
for s in 0 ..< nSites: |
||
img.drawRectangle( |
img.drawRectangle( |
||
startCorner=[sx[s] - 2, sy[s] - 2], |
startCorner=[sx[s] - 2, sy[s] - 2], |