Class: Okab::Path
- Inherits:
-
Object
- Object
- Okab::Path
- Defined in:
- lib/okab/page.rb,
sig/okab.rbs
Instance Attribute Summary collapse
-
#commands ⇒ Array[String]
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
- #close ⇒ self
- #curve_to(x1, y1, x2, y2, x3, y3) ⇒ self
- #ellipse(x, y, width, height) ⇒ self
-
#initialize ⇒ Path
constructor
A new instance of Path.
- #line_to(x, y) ⇒ self
- #move_to(x, y) ⇒ self
- #rect(x, y, width, height) ⇒ self
Constructor Details
#initialize ⇒ Path
Returns a new instance of Path.
9 |
# File 'lib/okab/page.rb', line 9 def initialize = (@commands = []) |
Instance Attribute Details
#commands ⇒ Array[String] (readonly)
Returns the value of attribute commands.
7 8 9 |
# File 'lib/okab/page.rb', line 7 def commands @commands end |
Instance Method Details
#close ⇒ self
13 |
# File 'lib/okab/page.rb', line 13 def close = command("h") |
#curve_to(x1, y1, x2, y2, x3, y3) ⇒ self
12 |
# File 'lib/okab/page.rb', line 12 def curve_to(x1, y1, x2, y2, x3, y3) = command("#{[x1, y1, x2, y2, x3, y3].map { |v| number(v) }.join(' ')} c") |
#ellipse(x, y, width, height) ⇒ self
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/okab/page.rb', line 16 def ellipse(x, y, width, height) k = 0.5522847498307936 cx, cy, rx, ry = x + width / 2.0, y + height / 2.0, width / 2.0, height / 2.0 move_to(cx + rx, cy) curve_to(cx + rx, cy + k * ry, cx + k * rx, cy + ry, cx, cy + ry) curve_to(cx - k * rx, cy + ry, cx - rx, cy + k * ry, cx - rx, cy) curve_to(cx - rx, cy - k * ry, cx - k * rx, cy - ry, cx, cy - ry) curve_to(cx + k * rx, cy - ry, cx + rx, cy - k * ry, cx + rx, cy) close end |
#line_to(x, y) ⇒ self
11 |
# File 'lib/okab/page.rb', line 11 def line_to(x, y) = command("#{number(x)} #{number(y)} l") |
#move_to(x, y) ⇒ self
10 |
# File 'lib/okab/page.rb', line 10 def move_to(x, y) = command("#{number(x)} #{number(y)} m") |
#rect(x, y, width, height) ⇒ self
14 |
# File 'lib/okab/page.rb', line 14 def rect(x, y, width, height) = command("#{[x, y, width, height].map { |v| number(v) }.join(' ')} re") |