Class: RubyLabs::Canvas::Circle

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

Overview

Circle

A Circle object is a proxy for a Tk oval.  

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

Instance Attribute Summary

Attributes inherited from TkObject

#coords, #name, #penpoint

Instance Method Summary collapse

Methods inherited from TkObject

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

Constructor Details

#initialize(x, y, r, args = {}) ⇒ Circle

Create a new circle with center at (x,y) and radius r. Attributes of the circle can be passed in a hash object at the end of the argument list.

Example – create a green cicle with radius 5 at location (20,20):

>> x = Canvas::Circle.new(20, 20, 5, :fill => "green")
=> #<RubyLabs::Canvas::Circle:...>

:call-seq:

x = Circle.new(x, y, r, args = {})


931
932
933
934
935
936
937
938
# File 'lib/rubylabs.rb', line 931

def initialize(x, y, r, args = {})
  raise "No canvas" unless @@pipe
  @name = TkObject.nextId
  @coords = [ x-r, y-r, x+r, y+r ] 
  @penpoint = [ r, r ]
  cmnd = "set #{@name} [.canvas create oval #{@coords.join(" ")} #{TkObject.options(args)}]"
  @@pipe.puts cmnd
end