Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Saturday, 8 May 2010

Random Voronoi Sketch

Here is a simple sketch, that flashes new random voronoi cells, with random fill.

load_libraries 'mesh'         # http://www.leebyron.com/else/mesh/
import 'megamu.mesh.Voronoi'
require 'set'
attr_reader :voronoi, :points

def setup()
  size(300, 300)
  color_mode HSB, 1.0
end

def draw
  points = Set.new
  10.times do
    10.times do    
      points.add([rand*300, rand*300])
    end
  end 
  voronoi = Voronoi.new((points.to_a).to_java(Java::float[]))
  regions = voronoi.get_regions
  regions.each do |region|
    region_coordinates = region.get_coords
    fill(rand, rand, rand)
    region.draw(self)
  end 
end


No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2