A simple(but slow

) algorithm for generating Voronoi diagrams. It wasn't exactly a challenge to get it in 3 lines, but I thought I'd post anyway ^^

+ Code Snippetglobal points = 50 : global w = 640 : global h = 480 : dim p(points,1) : dim regions(w,h) : ink rgb(200,200,200) : ln = 0 : for p = 1 to points : p(p,0) = rnd(w) : p(p,1) = rnd(h) : NEXT p
lock pixels : for y = 0 to h-1 : for x = 0 to w-1 : c_distance = w*h : for p = 1 to points : p_distance = sqrt((p(p,0)-x)^2+(p(p,1)-y)^2) : if p_distance < c_distance then c_point = p : c_distance = p_distance
next p : regions(x,y) = c_point : c = rgb(c_point,c_point,c_point) : dot x,y,rgb(c,c,c) : next xloop : next yloop : unlock pixels : wait key : end

uncompressed:

+ Code Snippetglobal points = 50 : global w = 640 : global h = 480 : dim p(points,1) : dim regions(w,h) : ink rgb(200,200,200) : ln = 0 : for p = 1 to points : p(p,0) = rnd(w) : p(p,1) = rnd(h) : NEXT p
lock pixels
for y = 0 to h-1 : for x = 0 to w-1
c_distance = w*h
for p = 1 to points
p_distance = sqrt((p(p,0)-x)^2+(p(p,1)-y)^2)
if p_distance < c_distance
c_point = p
c_distance = p_distance
endif
next p
regions(x,y) = c_point
c = rgb(c_point,c_point,c_point)
dot x,y,rgb(c,c,c)
next xloop : next yloop
unlock pixels : wait key : end

edit: I just re-read the rules and realized this probably comes under the category of "pointless," oh well ^^

edit2: some small optimizations

another edit

http://en.wikipedia.org/wiki/Voronoi_diagram