Class: MagicCloud::Cloud
- Inherits:
-
Object
- Object
- MagicCloud::Cloud
- Defined in:
- lib/magic_cloud/cloud.rb
Overview
Main word-cloud class. Takes words with sizes, returns image
Constant Summary collapse
- DEFAULT_FAMILY =
'Impact'
Instance Method Summary collapse
-
#draw(width, height) ⇒ Object
rubocop:todo Metrics/MethodLength.
-
#initialize(words, options = {}) ⇒ Cloud
constructor
rubocop:todo Metrics/ClassLength.
Constructor Details
#initialize(words, options = {}) ⇒ Cloud
rubocop:todo Metrics/ClassLength
17 18 19 20 21 22 23 |
# File 'lib/magic_cloud/cloud.rb', line 17 def initialize(words, = {}) @words = words.sort_by(&:last).reverse @options = @scaler = make_scaler(words, [:scale] || :log) @rotator = make_rotator([:rotate] || :square) @palette = make_palette([:palette] || :default) end |
Instance Method Details
#draw(width, height) ⇒ Object
rubocop:todo Metrics/MethodLength
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/magic_cloud/cloud.rb', line 28 def draw(width, height) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength # FIXME: do it in init, for specs would be happy shapes = @words.each_with_index.map { |(word, size), i| = { font_family: @options[:font_family] || DEFAULT_FAMILY, font_size: scaler.call(word, size, i), color: palette.call(word, i), rotate: rotator.call(word, i) } [:font] = @options[:font] if @options[:font] Word.new( word, ) } Debug.reset! spriter = Spriter.new spriter.make_sprites!(shapes) layouter = Layouter.new(width, height) visible = layouter.layout!(shapes) canvas = Canvas.new(width, height, 'white') visible.each { |sh| sh.draw(canvas) } canvas.render end |