Class: SolidRuby::CSGModifiers::Color

Inherits:
CSGModifier show all
Defined in:
lib/solidruby/csg_modifiers/color.rb

Instance Attribute Summary

Attributes inherited from SolidRubyObject

#attributes, #children, #siblings, #transformations

Instance Method Summary collapse

Methods inherited from CSGModifier

#to_rubyscad

Methods inherited from SolidRubyObject

#&, alias_attr, #debug, #debug?, #mirror, #place, #rotate, #rotate_around, #save, #scale, #to_rubyscad, #translate, #union, #walk_tree, #walk_tree_classes

Constructor Details

#initialize(object, attributes, opacity = nil) ⇒ Color

Returns a new instance of Color.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/solidruby/csg_modifiers/color.rb', line 18

def initialize(object, attributes, opacity = nil)
  @operation = 'color'
  if attributes.is_a? String
    attributes = "\"#{attributes}\""
    attributes += ", #{opacity}" unless opacity.nil?
  elsif attributes.is_a? Hash
    attributes[:a] ||= 255

    r = attributes[:r] / 255.0
    g = attributes[:g] / 255.0
    b = attributes[:b] / 255.0
    a = attributes[:a] / 255.0
    attributes = {c: [r, g, b], alpha: a}
  end

  super(object, attributes)
end