Class: RecursiveImage
- Inherits:
-
Object
- Object
- RecursiveImage
- Defined in:
- lib/ordinals/recursive/image.rb
Instance Method Summary collapse
- #add(obj) ⇒ Object (also: #<<)
- #count ⇒ Object (also: #size)
- #height ⇒ Object
-
#initialize(width, height) ⇒ RecursiveImage
constructor
A new instance of RecursiveImage.
- #to_svg(format = :standalone) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(width, height) ⇒ RecursiveImage
Returns a new instance of RecursiveImage.
6 7 8 9 10 11 |
# File 'lib/ordinals/recursive/image.rb', line 6 def initialize( width, height ) @width = width @height = height @recursions = [] end |
Instance Method Details
#add(obj) ⇒ Object Also known as: <<
13 |
# File 'lib/ordinals/recursive/image.rb', line 13 def add( obj ) @recursions << obj; end |
#count ⇒ Object Also known as: size
16 |
# File 'lib/ordinals/recursive/image.rb', line 16 def count() @recursions.size; end |
#height ⇒ Object
20 |
# File 'lib/ordinals/recursive/image.rb', line 20 def height() @height; end |
#to_svg(format = :standalone) ⇒ Object
23 24 25 26 27 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ordinals/recursive/image.rb', line 23 def to_svg( format=:standalone ) buf = '' if [:standalone].include?( format.downcase.to_sym ) buf +=<<TXT <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 #{width} #{height}"> TXT else ## assume :inline/:embed or such ## todo/check: add px e.g. 100 => 100px - why? why not? buf +=<<TXT <svg width="#{width}" height="#{height}"> TXT end @recursions.each_with_index do |recursion,i| id, opts = recursion.is_a?( Array )? recursion : [recursion, {}] pixelate = opts.has_key?(:pixelate) ? opts[:pixelate] : false style = pixelate ? %Q[style="image-rendering: pixelated;"] : '' ## note: assumes spritesheet has tile of same size as image itself!!!! spritesheet = opts[:spritesheet] if spritesheet num = opts[:num] || opts[:tile] spritesheet_width = spritesheet[0] tile_cols = spritesheet_width/width y,x = num.divmod( tile_cols ) buf += <<TXT <svg viewBox="#{x*width} #{y*height} #{width} #{height}"> <image href="/content/#{id}" #{style} /> </svg> TXT else buf += <<TXT <image href="/content/#{id}" #{style} /> TXT end end buf += <<TXT </svg> TXT buf end |
#width ⇒ Object
19 |
# File 'lib/ordinals/recursive/image.rb', line 19 def width() @width; end |