Class: Scratchpad::Pen
- Inherits:
-
Object
- Object
- Scratchpad::Pen
- Extended by:
- Scratchpad
- Includes:
- Math
- Defined in:
- lib/scratchpad.rb
Overview
/便利関数
Constant Summary collapse
- BLUE =
color_bytes_to_floats [0, 3, 126]
- ORANGE =
color_bytes_to_floats [255, 109, 50]
- GREEN =
color_bytes_to_floats [0, 124, 126]
Constants included from Scratchpad
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #down(ev) ⇒ Object
- #down? ⇒ Boolean
-
#initialize ⇒ Pen
constructor
A new instance of Pen.
- #move(ev) ⇒ Object
-
#path ⇒ Object
[[x, y, radius]*].
- #radius ⇒ Object
- #up(ev) ⇒ Object
Methods included from Scratchpad
chess_distance, color_bytes_to_floats, distance, dot_product, midpoint, plus, scalar_times, vec_lerp, vector
Constructor Details
#initialize ⇒ Pen
Returns a new instance of Pen.
89 90 91 92 93 94 |
# File 'lib/scratchpad.rb', line 89 def initialize @is_down = false @interpolator = Interpolator.new @path = [] @color = BLUE end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
83 84 85 |
# File 'lib/scratchpad.rb', line 83 def color @color end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
82 83 84 |
# File 'lib/scratchpad.rb', line 82 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
82 83 84 |
# File 'lib/scratchpad.rb', line 82 def y @y end |
Instance Method Details
#down(ev) ⇒ Object
107 108 109 |
# File 'lib/scratchpad.rb', line 107 def down(ev) @is_down = true end |
#down? ⇒ Boolean
119 120 121 |
# File 'lib/scratchpad.rb', line 119 def down? @is_down end |
#move(ev) ⇒ Object
115 116 117 |
# File 'lib/scratchpad.rb', line 115 def move(ev) @path = @interpolator.feed(ev.x, ev.y, @is_down) end |
#path ⇒ Object
- [x, y, radius]*
97 98 99 100 101 102 103 104 105 |
# File 'lib/scratchpad.rb', line 97 def path f = proc { |x| [-5.0/10.0 * x + 8.0, 0.3].max #x } @path.map { |x, y, velocity| [x, y, sqrt(f.(velocity))] } end |
#radius ⇒ Object
123 124 125 |
# File 'lib/scratchpad.rb', line 123 def radius 2.0 end |
#up(ev) ⇒ Object
111 112 113 |
# File 'lib/scratchpad.rb', line 111 def up(ev) @is_down = false end |