Class: Dare::Canvas
- Inherits:
-
Object
- Object
- Dare::Canvas
- Defined in:
- lib/dare/canvas.rb
Instance Attribute Summary collapse
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #context ⇒ Object
-
#initialize(opts = {}) ⇒ Canvas
constructor
A new instance of Canvas.
Constructor Details
#initialize(opts = {}) ⇒ Canvas
Returns a new instance of Canvas.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/dare/canvas.rb', line 4 def initialize(opts = {}) opts[:width] ||= 640 opts[:height] ||= 480 opts[:border] ||= false `var my_canvas = document.createElement("canvas")` @id = rand(36**8).to_s(36) `my_canvas.setAttribute('id', #{@id})` `my_canvas.width = #{opts[:width]}` `my_canvas.height = #{opts[:height]}` `my_canvas.style.border = "solid 1px black"` if opts[:border] `document.body.appendChild(my_canvas)` @canvas = `my_canvas` end |
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
3 4 5 |
# File 'lib/dare/canvas.rb', line 3 def canvas @canvas end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/dare/canvas.rb', line 3 def id @id end |
Instance Method Details
#context ⇒ Object
17 18 19 |
# File 'lib/dare/canvas.rb', line 17 def context `#{@canvas}.getContext('2d')` end |