Skip to content

Commit 5da875c

Browse files
committed
fewer magic numbers
1 parent b74131c commit 5da875c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Literate colors from JRubyArt
22
# uses `web_to_color_array` to create a hash of fruity colors
3-
# to join two words as `cherry\ red` use back slash
3+
# to join two words as `cherry\ red` use back slash
44
require 'ruby_wordcram'
55

66
PALETTE = %w(#b2c248 #c40000 #a61733 #f7ca18 #32cd23 #ffc800 #f27935 #ffe5b4 #913d88 #f22613 #c72c48 #ff43a4).freeze
77
FRUITS = %w(avocado cherry\ red cranberry lemon lime mango orange peach plum pomegranate raspberry strawberry).freeze
88

99
def settings
10-
size 500, 500
10+
size 600, 480
1111
end
1212

1313
def setup
1414
sketch_title 'Fruity Colors'
1515
background(255)
1616
colors = FRUITS.zip(web_to_color_array(PALETTE)).to_h
17+
longest = FRUITS.max { |a, b| a.length <=> b.length }
18+
shortest = FRUITS.min { |a, b| a.length <=> b.length }
1719
words = FRUITS.map do |fruit|
18-
weight = norm_strict(fruit.length, 11, 4)
20+
weight = norm_strict(fruit.length, longest.length, shortest.length)
1921
word = Word.new(fruit, weight)
2022
word.set_font(create_font(data_path('MINYN___.TTF'), 1))
2123
word.set_color(colors[fruit])
2224
end
2325
WordCram.new(self)
24-
.from_words(words.to_java(Word))
25-
.sized_by_weight(40, 80)
26-
.draw_all
26+
.from_words(words.to_java(Word))
27+
.sized_by_weight(20, 80)
28+
.draw_all
2729
end

0 commit comments

Comments
 (0)