Class: Vizcore::Shape::DrawContext

Inherits:
Object
  • Object
show all
Defined in:
lib/vizcore/shape.rb

Overview

Context passed into custom shape draw methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, param_schema: {}, shape_id: nil, layer_name: nil, palette: [], audio: {}, time: 0.0, frame: 0, resolution: [1280, 720], globals: {}) ⇒ DrawContext

Returns a new instance of DrawContext.



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/vizcore/shape.rb', line 209

def initialize(params:, param_schema: {}, shape_id: nil, layer_name: nil, palette: [], audio: {}, time: 0.0, frame: 0, resolution: [1280, 720], globals: {})
  @param_schema = symbolize_param_schema(param_schema)
  @params = normalize_params(default_params.merge(symbolize_hash(params)))
  @shape_id = shape_id&.to_sym
  @layer_name = layer_name
  @palette = Array(palette)
  @audio = AudioContext.new(audio)
  @time = Float(time || 0)
  @frame = Integer(frame || 0)
  @resolution = Array(resolution)
  @globals = symbolize_hash(globals)
  @builder = PrimitiveBuilder.new
end

Instance Attribute Details

#audioObject (readonly)

Returns the value of attribute audio.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def audio
  @audio
end

#frameObject (readonly)

Returns the value of attribute frame.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def frame
  @frame
end

#globalsObject (readonly)

Returns the value of attribute globals.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def globals
  @globals
end

#layer_nameObject (readonly)

Returns the value of attribute layer_name.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def layer_name
  @layer_name
end

#paletteObject (readonly)

Returns the value of attribute palette.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def palette
  @palette
end

#paramsObject (readonly)

Returns the value of attribute params.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def params
  @params
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def resolution
  @resolution
end

#shape_idObject (readonly)

Returns the value of attribute shape_id.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def shape_id
  @shape_id
end

#timeObject (readonly)

Returns the value of attribute time.



223
224
225
# File 'lib/vizcore/shape.rb', line 223

def time
  @time
end

Instance Method Details

#draw(&block) ⇒ Object



240
241
242
# File 'lib/vizcore/shape.rb', line 240

def draw(&block)
  @builder.draw(&block)
end

#heightObject



236
237
238
# File 'lib/vizcore/shape.rb', line 236

def height
  resolution[1]
end

#param(name, default = nil) ⇒ Object



225
226
227
228
229
230
# File 'lib/vizcore/shape.rb', line 225

def param(name, default = nil)
  key = name.to_sym
  return @params[key] if @params.key?(key)

  default
end

#shapesObject



244
245
246
# File 'lib/vizcore/shape.rb', line 244

def shapes
  @builder.shapes
end

#widthObject



232
233
234
# File 'lib/vizcore/shape.rb', line 232

def width
  resolution[0]
end