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.



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/vizcore/shape.rb', line 202

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.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def audio
  @audio
end

#frameObject (readonly)

Returns the value of attribute frame.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def frame
  @frame
end

#globalsObject (readonly)

Returns the value of attribute globals.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def globals
  @globals
end

#layer_nameObject (readonly)

Returns the value of attribute layer_name.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def layer_name
  @layer_name
end

#paletteObject (readonly)

Returns the value of attribute palette.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def palette
  @palette
end

#paramsObject (readonly)

Returns the value of attribute params.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def params
  @params
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def resolution
  @resolution
end

#shape_idObject (readonly)

Returns the value of attribute shape_id.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def shape_id
  @shape_id
end

#timeObject (readonly)

Returns the value of attribute time.



216
217
218
# File 'lib/vizcore/shape.rb', line 216

def time
  @time
end

Instance Method Details

#draw(&block) ⇒ Object



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

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

#heightObject



229
230
231
# File 'lib/vizcore/shape.rb', line 229

def height
  resolution[1]
end

#param(name, default = nil) ⇒ Object



218
219
220
221
222
223
# File 'lib/vizcore/shape.rb', line 218

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

  default
end

#shapesObject



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

def shapes
  @builder.shapes
end

#widthObject



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

def width
  resolution[0]
end