Anonymous user
Voronoi diagram: Difference between revisions
→{{header|Ruby}}
Line 2,517:
{{libheader|JRubyArt}}
JRubyArt is a port of processing to ruby
<lang ruby># frozen_string_literal: true
Tile = Struct.new(:x, :y, :color) do
attr_reader :colors, :positions▼
def sq_dist(a, b)
(x - a)**2 + (y - b)**2
end▼
end
def settings
Line 2,529 ⟶ 2,534:
sketch_title 'Voronoi Diagram'
load_pixels
color_mode(HSB
@
draw_voronoi
update_pixels
Line 2,537 ⟶ 2,541:
end
def
(0..num).map {
▲end
end
def draw_voronoi
grid(width, height) do |x, y|
▲ pixels[x + y * width] = colors[index]
end
end
def draw_voronoi_centers
no_stroke
fill 0
ellipse(
end
end
</lang>
|