Class: Scratchpad::Pen

Inherits:
Object
  • Object
show all
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

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scratchpad

chess_distance, color_bytes_to_floats, distance, dot_product, midpoint, plus, scalar_times, vec_lerp, vector

Constructor Details

#initializePen

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

#colorObject

Returns the value of attribute color.



83
84
85
# File 'lib/scratchpad.rb', line 83

def color
  @color
end

#xObject (readonly)

Returns the value of attribute x.



82
83
84
# File 'lib/scratchpad.rb', line 82

def x
  @x
end

#yObject (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

Returns:

  • (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

#pathObject

[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

#radiusObject



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