Skip to content

Commit 70dfa23

Browse files
committed
this is ruby it should be elegant 'dry'
1 parent 34c4155 commit 70dfa23

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

external_library/gem/ruby_wordcram/yin_yang_words.rb

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,50 @@
22
require 'propane'
33
require 'ruby_wordcram'
44

5-
class YinYangWords < Propane::App
5+
class YinYang < Propane::App
6+
7+
def settings
8+
size(600, 600)
9+
end
610

711
def setup
812
sketch_title 'Yin Yang Words'
913
background 255
1014
image = load_image(data_path('yinyang.png'))
1115
image.resize(width, height)
12-
image_shape = ImageShaper.new.shape(image, color('#000000'))
13-
placer = ShapeBasedPlacer.new(image_shape)
14-
WordCram.new(self)
15-
.from_words(repeat_word('flexible', 500).to_java(Word))
16-
.with_placer(placer)
17-
.with_nudger(placer)
18-
.sized_by_weight(4, 40)
19-
.angled_at(0)
20-
.with_color(color('#F5B502'))
21-
.draw_all
22-
image_shape = ImageShaper.new.shape(image, color('#ffffff'))
16+
create_image_shaped_wordcram(
17+
image: image,
18+
mask: color('#000000'),
19+
words: repeat_word('flexible', 500),
20+
hue: color('#F5B502')
21+
)
22+
create_image_shaped_wordcram(
23+
image: image,
24+
mask: color('#ffffff'),
25+
words: repeat_word('usable', 500),
26+
hue: color('#782CAF')
27+
)
28+
end
29+
30+
def create_image_shaped_wordcram(image:, mask:, words:, hue:)
31+
image_shape = ImageShaper.new.shape(image, mask)
2332
placer = ShapeBasedPlacer.new(image_shape)
2433
WordCram.new(self)
25-
.from_words(repeat_word('usable', 500).to_java(Word))
34+
.from_words(words.to_java(Word))
2635
.with_placer(placer)
2736
.with_nudger(placer)
2837
.sized_by_weight(4, 40)
2938
.angled_at(0)
30-
.with_color(color('#782CAF'))
39+
.with_color(hue)
3140
.draw_all
32-
end
41+
end
3342

3443
def repeat_word(word, times)
3544
(0..times).map do
3645
# Give the words a random weight, so they're sized differently.
3746
Word.new(word, rand)
38-
end
39-
end
40-
41-
def settings
42-
size(600, 600)
47+
end
4348
end
4449
end
4550

46-
YinYangWords.new
51+
YinYang.new

0 commit comments

Comments
 (0)