Class: Vizcore::Shape::DrawContext
- Inherits:
-
Object
- Object
- Vizcore::Shape::DrawContext
- Defined in:
- lib/vizcore/shape.rb
Overview
Context passed into custom shape draw methods.
Instance Attribute Summary collapse
-
#audio ⇒ Object
readonly
Returns the value of attribute audio.
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#globals ⇒ Object
readonly
Returns the value of attribute globals.
-
#layer_name ⇒ Object
readonly
Returns the value of attribute layer_name.
-
#palette ⇒ Object
readonly
Returns the value of attribute palette.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#resolution ⇒ Object
readonly
Returns the value of attribute resolution.
-
#shape_id ⇒ Object
readonly
Returns the value of attribute shape_id.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #draw(&block) ⇒ Object
- #height ⇒ Object
-
#initialize(params:, param_schema: {}, shape_id: nil, layer_name: nil, palette: [], audio: {}, time: 0.0, frame: 0, resolution: [1280, 720], globals: {}) ⇒ DrawContext
constructor
A new instance of DrawContext.
- #param(name, default = nil) ⇒ Object
- #shapes ⇒ Object
- #width ⇒ Object
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
#audio ⇒ Object (readonly)
Returns the value of attribute audio.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def audio @audio end |
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def frame @frame end |
#globals ⇒ Object (readonly)
Returns the value of attribute globals.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def globals @globals end |
#layer_name ⇒ Object (readonly)
Returns the value of attribute layer_name.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def layer_name @layer_name end |
#palette ⇒ Object (readonly)
Returns the value of attribute palette.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def palette @palette end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def params @params end |
#resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def resolution @resolution end |
#shape_id ⇒ Object (readonly)
Returns the value of attribute shape_id.
223 224 225 |
# File 'lib/vizcore/shape.rb', line 223 def shape_id @shape_id end |
#time ⇒ Object (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 |
#height ⇒ Object
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 |
#shapes ⇒ Object
244 245 246 |
# File 'lib/vizcore/shape.rb', line 244 def shapes @builder.shapes end |
#width ⇒ Object
232 233 234 |
# File 'lib/vizcore/shape.rb', line 232 def width resolution[0] end |