Skip to content

Commit c9d9bd3

Browse files
committed
fruits
1 parent 274b022 commit c9d9bd3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

external_library/gem/fruits.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
require 'ruby_wordcram'
4+
5+
# Literate colors from propane
6+
# uses `web_to_color_array` to create a hash of fruity colors
7+
# to join two words as `cherry\ red` use back slash
8+
class Fruits < Propane::App
9+
10+
PALETTE = %w(#b2c248 #c40000 #a61733 #f7ca18 #32cd23 #ffc800 #f27935 #ffe5b4 #913d88 #f22613 #c72c48 #ff43a4).freeze
11+
FRUITS = %w(avocado cherry\ red cranberry lemon lime mango orange peach plum pomegranate raspberry strawberry).freeze
12+
13+
def settings
14+
size 600, 480
15+
end
16+
17+
def setup
18+
sketch_title 'Fruity Colors'
19+
background(255)
20+
colors = FRUITS.zip(web_to_color_array(PALETTE)).to_h
21+
longest = FRUITS.max { |a, b| a.length <=> b.length }
22+
shortest = FRUITS.min { |a, b| a.length <=> b.length }
23+
words = FRUITS.map do |fruit|
24+
weight = norm_strict(fruit.length, longest.length, shortest.length)
25+
word = Word.new(fruit, weight)
26+
word.set_font(create_font(data_path('MINYN___.TTF'), 1))
27+
word.set_color(colors[fruit])
28+
end
29+
WordCram.new(self)
30+
.from_words(words.to_java(Word))
31+
.sized_by_weight(20, 80)
32+
.draw_all
33+
end
34+
end
35+
36+
Fruits.new

0 commit comments

Comments
 (0)