Class: DYI::Drawing::ColumnBrush

Inherits:
Brush show all
Defined in:
lib/dyi/drawing/pen_3d.rb

Overview

Since:

  • 0.0.0

Constant Summary

Constants inherited from Brush

Brush::ALIAS_ATTRIBUTES

Constants inherited from PenBase

PenBase::DROP_SHADOW_OPTIONS

Instance Attribute Summary

Attributes inherited from Brush

#color, #rule

Attributes inherited from PenBase

#display, #drop_shadow, #fill, #fill_opacity, #fill_rule, #opacity, #stroke, #stroke_dasharray, #stroke_dashoffset, #stroke_linecap, #stroke_linejoin, #stroke_miterlimit, #stroke_opacity, #stroke_width, #visibility

Instance Method Summary collapse

Methods inherited from Brush

method_missing

Methods inherited from PenBase

#draw_closed_path, #draw_image, #draw_line, #draw_line_on_direction, #draw_path, #draw_polygon, #draw_polyline, #draw_rectangle, #draw_rectangle_on_corner, #draw_sector, #draw_text, #import_image

Constructor Details

#initialize(options = {}) ⇒ ColumnBrush

Returns a new instance of ColumnBrush.

Since:

  • 1.1.0



186
187
188
189
190
# File 'lib/dyi/drawing/pen_3d.rb', line 186

def initialize(options={})
  self.flank_color = options.delete(:flank_color)
  self.dy = options.delete(:dy)
  super
end

Instance Method Details

#draw_circle(canvas, center_point, radius, options = {}) ⇒ Object

Draw a cylinder by specifying the upper surface, which is a circle

Since:

  • 1.1.0



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/dyi/drawing/pen_3d.rb', line 214

def draw_circle(canvas, center_point, radius, options={})
  radius = Length.new(radius).abs
  center_point = Coordinate.new(center_point)
  group_options = {}
  parts_options = merge_option(options)
  (flank_painting = @painting.dup).fill = flank_color
  flank_options = parts_options.merge(:painting => flank_painting)
  [:anchor_href, :anchor_target, :css_class, :id].each do |key|
    group_options[key] = parts_options.delete(key)
  end
  shape = Shape::ShapeGroup.draw_on(canvas, group_options)
  super(shape, center_point + [0, dy], radius, parts_options)
  draw_closed_path(shape, center_point - [radius, 0], flank_options) {|path|
    path.rarc_to([radius * 2, 0], radius, radius)
    path.rline_to([0, dy])
    path.rarc_to([- radius * 2, 0], radius, radius, 0, false, false)
  }
  draw_closed_path(shape, center_point - [radius, 0], flank_options) {|path|
    path.rarc_to([radius * 2, 0], radius, radius, 0, false, false)
    path.rline_to([0, dy])
    path.rarc_to([- radius * 2, 0], radius, radius)
  }
  super(shape, center_point, radius, parts_options)
  shape
end

#draw_ellipse(canvas, center_point, radius_x, radius_y, options = {}) ⇒ Object

Draw a cylinder by specifying the upper surface, which is a ellipse

Since:

  • 1.1.0



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/dyi/drawing/pen_3d.rb', line 242

def draw_ellipse(canvas, center_point, radius_x, radius_y, options={})
  radius_x, radius_y = Length.new(radius_x).abs, Length.new(radius_y).abs
  center_point = Coordinate.new(center_point)
  group_options = {}
  parts_options = merge_option(options)
  (flank_painting = @painting.dup).fill = flank_color
  flank_options = parts_options.merge(:painting => flank_painting)
  [:anchor_href, :anchor_target, :css_class, :id].each do |key|
    group_options[key] = parts_options.delete(key)
  end
  shape = Shape::ShapeGroup.draw_on(canvas, group_options)
  super(shape, center_point + [0, dy], radius_x, radius_y, parts_options)
  draw_closed_path(shape, center_point - [radius_x, 0], flank_options) {|path|
    path.rarc_to([radius_x * 2, 0], radius_x, radius_y)
    path.rline_to([0, dy])
    path.rarc_to([- radius_x * 2, 0], radius_x, radius_y, 0, false, false)
  }
  draw_closed_path(shape, center_point - [radius_x, 0], flank_options) {|path|
    path.rarc_to([radius_x * 2, 0], radius_x, radius_y, 0, false, false)
    path.rline_to([0, dy])
    path.rarc_to([- radius_x * 2, 0], radius_x, radius_y)
  }
  super(shape, center_point, radius_x, radius_y, parts_options)
  shape
end

#draw_toroid(canvas, center_point, radius_x, radius_y, inner_radius, options = {}) ⇒ Object

Since:

  • 1.1.0



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/dyi/drawing/pen_3d.rb', line 269

def draw_toroid(canvas, center_point, radius_x, radius_y, inner_radius, options={})
  if inner_radius >= 1 || 0 > inner_radius
    raise ArgumentError, "inner_radius option is out of range: #{inner_radius}"
  end
  radius_x, radius_y = Length.new(radius_x).abs, Length.new(radius_y).abs
  center_point = Coordinate.new(center_point)
  arc_right_pt = center_point + [radius_x, 0]
  arc_left_pt = center_point - [radius_x , 0]
  inner_radius_x = radius_x * inner_radius
  inner_radius_y = radius_y * inner_radius
  inner_arc_right_pt = center_point + [inner_radius_x , 0]
  inner_arc_left_pt = center_point - [inner_radius_x, 0]
  group_options = {}
  parts_options = merge_option(options)
  (flank_painting = @painting.dup).fill = flank_color
  flank_options = parts_options.merge(:painting => flank_painting)
  [:anchor_href, :anchor_target, :css_class, :id].each do |key|
    group_options[key] = parts_options.delete(key)
  end
  shape = Shape::ShapeGroup.draw_on(canvas, group_options)

  super(shape, center_point + [0, dy], radius_x, radius_y, inner_radius, parts_options)
  draw_sector_back_flank(shape, center_point,
                         radius_x, radius_y,
                         arc_left_pt, arc_right_pt,
                         180, 180, flank_options)
  draw_sector_back_flank(shape, center_point,
                         inner_radius_x, inner_radius_y,
                         inner_arc_left_pt, inner_arc_right_pt,
                         180, 180, flank_options)
  draw_sector_front_flank(shape, center_point,
                          inner_radius_x, inner_radius_y,
                          inner_arc_right_pt, inner_arc_left_pt,
                          0, 180, flank_options)
  draw_sector_front_flank(shape, center_point,
                          radius_x, radius_y,
                          arc_right_pt, arc_left_pt,
                          0, 180, flank_options)
  super(shape, center_point, radius_x, radius_y, inner_radius, parts_options)
end

#dyObject

Since:

  • 0.0.0



192
193
194
# File 'lib/dyi/drawing/pen_3d.rb', line 192

def dy
  @dy || Length.new(16)
end

#dy=(value) ⇒ Object

Since:

  • 0.0.0



196
197
198
# File 'lib/dyi/drawing/pen_3d.rb', line 196

def dy=(value)
  @dy = Length.new_or_nil(value)
end

#flank_colorObject

Returns a flank color

Since:

  • 1.1.0



202
203
204
# File 'lib/dyi/drawing/pen_3d.rb', line 202

def flank_color
  @flank_color || color.merge('black', 0.2)
end

#flank_color=(color) ⇒ Object

Set a flank color

Since:

  • 1.1.0



208
209
210
# File 'lib/dyi/drawing/pen_3d.rb', line 208

def flank_color=(color)
  @flank_color = Color.new_or_nil(color)
end