Skip to content

Commit 30c3d29

Browse files
committed
Latest toxicgem supports Voronoi
1 parent e6b5f46 commit 30c3d29

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
125 KB
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'toxiclibs'
2+
3+
attr_reader :gfx, :voronoi, :img, :pixels
4+
def setup
5+
sketch_title 'Monalisa Voronoi'
6+
@img = load_image(data_path('monalisa.jpg'))
7+
img.load_pixels
8+
@pixels = img.pixels
9+
@gfx = Gfx::ToxiclibsSupport.new(self)
10+
@voronoi = Toxi::Voronoi.new
11+
4_000.times do
12+
voronoi.add_point(TVec2D.new(rand(width), rand(height)))
13+
end
14+
no_loop
15+
end
16+
17+
def draw
18+
voronoi.get_regions.each do |polygon|
19+
voronoi.get_sites.each do |v|
20+
if polygon.contains_point(v)
21+
fill pixels[v.y * img.width + v.x]
22+
gfx.polygon2D(polygon)
23+
end
24+
end
25+
end
26+
save_frame(data_path('mona-lisa-voronoi.png'))
27+
end
28+
29+
def settings
30+
size(600, 894)
31+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'toxiclibs'
2+
attr_reader :gfx, :voronoi
3+
4+
def setup
5+
sketch_title 'Basic Voronoi'
6+
@gfx = Gfx::ToxiclibsSupport.new(self)
7+
@voronoi = Toxi::Voronoi.new
8+
50.times do
9+
voronoi.add_point(TVec2D.new(rand(width), rand(height)))
10+
end
11+
no_loop
12+
end
13+
14+
def draw
15+
background 0
16+
fill 0
17+
smooth
18+
strokeWeight 1
19+
stroke 255
20+
voronoi.get_regions.each { |polygon| gfx.polygon2D(polygon) }
21+
save_frame("voronoi-001.png")
22+
end
23+
24+
def settings
25+
size 450, 360
26+
end

0 commit comments

Comments
 (0)