|
2 | 2 | require 'propane' |
3 | 3 | require 'ruby_wordcram' |
4 | 4 |
|
5 | | -class YinYangWords < Propane::App |
| 5 | +class YinYang < Propane::App |
| 6 | + |
| 7 | + def settings |
| 8 | + size(600, 600) |
| 9 | + end |
6 | 10 |
|
7 | 11 | def setup |
8 | 12 | sketch_title 'Yin Yang Words' |
9 | 13 | background 255 |
10 | 14 | image = load_image(data_path('yinyang.png')) |
11 | 15 | 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) |
23 | 32 | placer = ShapeBasedPlacer.new(image_shape) |
24 | 33 | WordCram.new(self) |
25 | | - .from_words(repeat_word('usable', 500).to_java(Word)) |
| 34 | + .from_words(words.to_java(Word)) |
26 | 35 | .with_placer(placer) |
27 | 36 | .with_nudger(placer) |
28 | 37 | .sized_by_weight(4, 40) |
29 | 38 | .angled_at(0) |
30 | | - .with_color(color('#782CAF')) |
| 39 | + .with_color(hue) |
31 | 40 | .draw_all |
32 | | - end |
| 41 | + end |
33 | 42 |
|
34 | 43 | def repeat_word(word, times) |
35 | 44 | (0..times).map do |
36 | 45 | # Give the words a random weight, so they're sized differently. |
37 | 46 | Word.new(word, rand) |
38 | | - end |
39 | | - end |
40 | | - |
41 | | - def settings |
42 | | - size(600, 600) |
| 47 | + end |
43 | 48 | end |
44 | 49 | end |
45 | 50 |
|
46 | | -YinYangWords.new |
| 51 | +YinYang.new |
0 commit comments