Class: DYI::Drawing::ColumnBrush
- Defined in:
- lib/dyi/drawing/pen_3d.rb
Overview
Constant Summary
Constants inherited from Brush
Constants inherited from PenBase
Instance Attribute Summary
Attributes inherited from Brush
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
-
#draw_circle(canvas, center_point, radius, options = {}) ⇒ Object
Draw a cylinder by specifying the upper surface, which is a circle.
-
#draw_ellipse(canvas, center_point, radius_x, radius_y, options = {}) ⇒ Object
Draw a cylinder by specifying the upper surface, which is a ellipse.
- #draw_toroid(canvas, center_point, radius_x, radius_y, inner_radius, options = {}) ⇒ Object
- #dy ⇒ Object
- #dy=(value) ⇒ Object
-
#flank_color ⇒ Object
Returns a flank color.
-
#flank_color=(color) ⇒ Object
Set a flank color.
-
#initialize(options = {}) ⇒ ColumnBrush
constructor
A new instance of ColumnBrush.
Methods inherited from Brush
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.
186 187 188 189 190 |
# File 'lib/dyi/drawing/pen_3d.rb', line 186 def initialize(={}) self.flank_color = .delete(:flank_color) self.dy = .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
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, ={}) radius = Length.new(radius).abs center_point = Coordinate.new(center_point) = {} = merge_option() (flank_painting = @painting.dup).fill = flank_color = .merge(:painting => flank_painting) [:anchor_href, :anchor_target, :css_class, :id].each do |key| [key] = .delete(key) end shape = Shape::ShapeGroup.draw_on(canvas, ) super(shape, center_point + [0, dy], radius, ) draw_closed_path(shape, center_point - [radius, 0], ) {|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], ) {|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, ) 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
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, ={}) radius_x, radius_y = Length.new(radius_x).abs, Length.new(radius_y).abs center_point = Coordinate.new(center_point) = {} = merge_option() (flank_painting = @painting.dup).fill = flank_color = .merge(:painting => flank_painting) [:anchor_href, :anchor_target, :css_class, :id].each do |key| [key] = .delete(key) end shape = Shape::ShapeGroup.draw_on(canvas, ) super(shape, center_point + [0, dy], radius_x, radius_y, ) draw_closed_path(shape, center_point - [radius_x, 0], ) {|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], ) {|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, ) shape end |
#draw_toroid(canvas, center_point, radius_x, radius_y, inner_radius, options = {}) ⇒ Object
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, ={}) 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] = {} = merge_option() (flank_painting = @painting.dup).fill = flank_color = .merge(:painting => flank_painting) [:anchor_href, :anchor_target, :css_class, :id].each do |key| [key] = .delete(key) end shape = Shape::ShapeGroup.draw_on(canvas, ) super(shape, center_point + [0, dy], radius_x, radius_y, inner_radius, ) draw_sector_back_flank(shape, center_point, radius_x, radius_y, arc_left_pt, arc_right_pt, 180, 180, ) draw_sector_back_flank(shape, center_point, inner_radius_x, inner_radius_y, inner_arc_left_pt, inner_arc_right_pt, 180, 180, ) draw_sector_front_flank(shape, center_point, inner_radius_x, inner_radius_y, inner_arc_right_pt, inner_arc_left_pt, 0, 180, ) draw_sector_front_flank(shape, center_point, radius_x, radius_y, arc_right_pt, arc_left_pt, 0, 180, ) super(shape, center_point, radius_x, radius_y, inner_radius, ) end |
#dy ⇒ Object
192 193 194 |
# File 'lib/dyi/drawing/pen_3d.rb', line 192 def dy @dy || Length.new(16) end |
#dy=(value) ⇒ Object
196 197 198 |
# File 'lib/dyi/drawing/pen_3d.rb', line 196 def dy=(value) @dy = Length.new_or_nil(value) end |
#flank_color ⇒ Object
Returns a flank color
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
208 209 210 |
# File 'lib/dyi/drawing/pen_3d.rb', line 208 def flank_color=(color) @flank_color = Color.new_or_nil(color) end |