Class: RubyLabs::Canvas::Line

Inherits:
TkObject
  • Object
show all
Defined in:
lib/rubylabs.rb

Overview

Line

A Line object is a proxy for a line segment defined by a pair of (x,y) coordinates.  

There are no instance methods for Lines beyond those defined in the TkObject base class.

Instance Attribute Summary

Attributes inherited from TkObject

#coords, #name, #penpoint

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TkObject

#erase, #fill=, #lower, nextId, options, #raise, reset

Constructor Details

#initialize(x0, y0, x1, y1, args = {}) ⇒ Line

Create a new line segment that runs from (x0,y0) to (x1,y1). Attributes of the line can be passed in a hash object at the end of the argument list.

Example – create a gray line one pixel wide from (0,0) to (100,100):

>> z = Line.new(0, 0, 100, 100, :fill => :gray, :width => 1)
=> #<RubyLabs::Canvas::Line:...>

:call-seq:

x = Line.new(x0, y0, x1, y1, args = {})


885
886
887
888
889
890
891
892
# File 'lib/rubylabs.rb', line 885

def initialize(x0, y0, x1, y1, args = {})
  raise "No canvas" unless @@pipe
  @name = TkObject.nextId
  @coords = [ x0, y0, x1, y1 ] 
  @penpoint = nil
  cmnd = "set #{@name} [.canvas create line #{@coords.join(" ")} #{TkObject.options(args)}]"
  @@pipe.puts cmnd
end

Class Method Details

.erase_all(tag) ⇒ Object

Erase all Line objects that are tagged with the ID tag. Tags are optional arguments defined by passing -tag x to Line.new (see the visualization methods in tsplab.rb, which uses tags to erase all edges from a graph in a single call).

:call-seq:

Line.erase_all(tag)


903
904
905
# File 'lib/rubylabs.rb', line 903

def Line.erase_all(tag)
  @@pipe.puts ".canvas delete withtag #{tag}"
end