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 = {})


938
939
940
941
942
943
944
945
# File 'lib/rubylabs.rb', line 938

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