/
yin_yang_mots.rb
44 lines (40 loc) · 1.02 KB
/
yin_yang_mots.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'ruby_wordcram'
def settings
size(600, 600)
end
def setup
sketch_title 'Le Yin et le Yang'
background 255
image = load_image(data_path('yinyang.png'))
image.resize(width, height)
create_image_shaped_wordcram(
image: image,
mask: color('#000000'),
words: repeat_word('souple', 500),
hue: color('#F5B502')
)
create_image_shaped_wordcram(
image: image,
mask: color('#ffffff'),
words: repeat_word('employable', 500),
hue: color('#782CAF')
)
end
def create_image_shaped_wordcram(image:, mask:, words:, hue:)
image_shape = ImageShaper.new.shape(image, mask)
placer = ShapeBasedPlacer.new(image_shape)
WordCram.new(self)
.from_words(words.to_java(Word))
.with_placer(placer)
.with_nudger(placer)
.sized_by_weight(4, 40)
.angled_at(0)
.with_color(hue)
.draw_all
end
def repeat_word(word, times)
(0..times).map do
# Give the words a random weight, so they're sized differently.
Word.new(word, rand)
end
end