slugraphics
index

Library for drawing basic shapes.

 
Classes
       
Canvas
Color
Drawable
Group
Shape
FillableShape
Circle
Polygon
Rectangle
Square
Segment
Text
Point

 
class Canvas
    Represents a window which can be drawn upon.
 
  Methods defined here:
__init__(w=200, h=200, background=None, title='Graphics canvas')
Create a new drawing canvas.
 
A new canvas will be created.
    w               width of drawing area (defaults to 200)
    h               height of drawing area (defaults to 200)
    background      color of the background (defaults to White)
    title           window title (defaults to "Graphics Canvas")
add(drawable)
Adds a drawable object to the canvas.
clear()
Remove all drawable objects from the canvas.
close()
Close the canvas window (if not already closed).
getBackgroundColor()
Returns the background color as an instance of Color.
getHeight()
Get the height of the canvas.
getTitle()
Get the title of the window.
getWidth()
Get the width of the canvas.
open()
Opens a graphic window (if not already open)
refresh()
Renders all drawable objects to the screen in their current state.
remove(drawable)
Remove the drawable object from the canvas.
setBackgroundColor(backgroundColor)
Set the background color to a copy of backgroundColor.
 
backgroundColor can either be a string with the name of the color or an instance of Color.
setHeight(h)
Resets the canvas height to h.
setTitle(title)
Set the title for the canvas window.
setWidth(w)
Resets the canvas width to w.

 
class Circle(FillableShape)
    A circle that can be drawn to the screen.
 
 
Method resolution order:
Circle
FillableShape
Shape
Drawable

Methods defined here:
__init__(center=None, radius=10)
Construct a new instance of Circle.
 
center  the center of the circle.
        (Defaults to (0,0) if None specified)
 
raidus  the circle's radius.  (Defaults to 10)
getRadius()
Returns the radius of the circle.
setRadius(radius)
Set the radius of the circle to radius.

Methods inherited from FillableShape:
getFillColor()
Return the color of the shape's interior.
setFillColor(color)
Set the interior color of the shape to copy of color.
 
color can either be a string with the name of the color or an instance of Color.

Methods inherited from Shape:
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Color
    Represents a color.
 
Color can be specified by name or RGB value, and can be made transparent.
 
  Methods defined here:
__init__(colorName='White')
Create a new instance of Color.
 
The parameter can be either string with the name of the color or
an existing Color instance.  It defaults to "White"
getColorName()
Returns the name of the color.
 
If the color was set by RGB value, it returns "Custom".
getColorValue()
Returns a tuple of the red, green and blue color components.
isTransparent()
Returns a boolean variable indicating if the current color is transparent.
 
A return value of True indicates the color is not visibile.
setColorName(colorName)
Set the color to colorName.
 
It colorName is "Transparent" the resulting color will not show up on
the screen.  Otherwise the color will be visable.  colorName must be
a valid name of a color.
setColorValue(red, green, blue)
Sets the color using red, green and blue color values.
setTransparent(transparent=True)
Changes the transparency setting based upon parameter (defaults to True).
 
If transparent is True then the color will not be rendered to the screen.
If transparent is False, the color will be rendered.

 
class Drawable
    Represents objects that can be drawn to the graphics canvas.
 
  Methods defined here:
__init__(referencePoint=None)
Creates an instance of Drawable.
 
referencePoint  where the drawable object should be placed.
                (Defaults to (0,0) if None specified)
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class FillableShape(Shape)
    A shape that can be filled in.
 
 
Method resolution order:
FillableShape
Shape
Drawable

Methods defined here:
__init__(referencePoint=None)
Construct a new instance of Shape.
 
The interior color defaults to transparent.
 
referencePoint  where the shape should be located.
                (Defaults to (0,0) if None specified)
getFillColor()
Return the color of the shape's interior.
setFillColor(color)
Set the interior color of the shape to copy of color.
 
color can either be a string with the name of the color or an instance of Color.

Methods inherited from Shape:
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Group(Drawable)
    Stores a group of shapes that can act as one drawable object.
 
  Methods defined here:
__init__(referencePoint=None)
Construct a new instance of Group.
 
referencePoint is the refernce point for the entire group.
               (Defaults to (0,0) if None specified)
               If this is moved, every object of the group
               implicitly moves with it.
add(drawable)
Add a drawable object to the group.
clear()
Clear all objects from the grouping.
remove(drawable)
Remove the drawable object from the group.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Point
    Stores a two-dimensional point using cartesian coordinates.
 
  Methods defined here:
__init__(x=0, y=0)
Create a new point instance.
 
x   x-coordinate of the point(defaults to 0)
y   y-coordinate of the point(defaults to 0)
getX()
Returns the x-coordinate.
getY()
Returns the y-coordinate.
setX(x)
Set the x-coordinate to x.
setY(y)
Set the y-coordinate to y.

 
class Polygon(FillableShape)
    A polygon with three or more sides.
 
 
Method resolution order:
Polygon
FillableShape
Shape
Drawable

Methods defined here:
__init__(*points)
Create a new instance of a Polygon given the coordinates of the corners.
 
points is a list of Points representing the corners of the polygon.
addPoint(point)
Add a new point to the end of the list of points of the polygon.
clearPoints()
Erase all points from the polygon.
getNumberOfPoints(point)
Returns the number of corners of the polygon.
getPoint(index)
Returns a Point representing the index-th corner of the polygon.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.

Methods inherited from FillableShape:
getFillColor()
Return the color of the shape's interior.
setFillColor(color)
Set the interior color of the shape to copy of color.
 
color can either be a string with the name of the color or an instance of Color.

Methods inherited from Shape:
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Rectangle(FillableShape)
    A rectangle that can be drawn to the canvas.
 
 
Method resolution order:
Rectangle
FillableShape
Shape
Drawable

Methods defined here:
__init__(upperLeft=None, width=10, height=10)
Construct a new instance of a Rectangle.
 
upperLeft   is a Point representing the upper left hand corder of the screen.
            (Defaults to (0,0) if None specified)
width       the width of the rectangle.  (Defaults to 10)
height      the height of the rectangle.  (Defaults to 10)
getHeight()
Returns the height of the rectangle.
getWidth()
Returns the width of the rectangle.
setHeight(height)
Sets the height of the rectangle to height.
setWidth(width)
Sets the width of the rectangle to width.

Methods inherited from FillableShape:
getFillColor()
Return the color of the shape's interior.
setFillColor(color)
Set the interior color of the shape to copy of color.
 
color can either be a string with the name of the color or an instance of Color.

Methods inherited from Shape:
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Segment(Shape)
    A line segment that can be drawn to the screen.
 
 
Method resolution order:
Segment
Shape
Drawable

Methods defined here:
__init__(startPoint=None, endPoint=None)
Construct a new instance of Segment.
 
startPoint  the beginning of the line segment.
            (Defaults to (0,0) if None specified)
endPoint    the end of the line segment.
            (Defaults to (0,0) if None specified)
getPoints()
Returns the beginning and ending points.
move(dx, dy)
Move the line segment dx units to the right and dy units down.
 
Negative values move the object left or up.
setPoints(startPoint, endPoint)
Sets the beginning and end points to startPiont and endPoint, repsectively.

Methods inherited from Shape:
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Shape(Drawable)
    Represents objects that are drawable and have a border.
 
  Methods defined here:
__init__(referencePoint=None)
Construct an instance of Shape.
 
referencePoint  where the shape is located.
                (Defaults to (0,0) if None specified)
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Square(Rectangle)
    A square that can be drawn to a canvas.
 
 
Method resolution order:
Square
Rectangle
FillableShape
Shape
Drawable

Methods defined here:
__init__(upperLeft=None, size=10)
Construct a new instance of Square.
 
upperLeft   a Point representing the upper lefthand corner of the square.
            (Defaults to (0,0) if None specified)
size        the dimension of the square.  (Defaults to 10)
getSize()
Returns the length of a side of the square.
setHeight(height)
Set the length and width of the square to size.
setSize(size)
Set the length and width of the square to size.
setWidth(width)
Set the length and width of the square to size.

Methods inherited from Rectangle:
getHeight()
Returns the height of the rectangle.
getWidth()
Returns the width of the rectangle.

Methods inherited from FillableShape:
getFillColor()
Return the color of the shape's interior.
setFillColor(color)
Set the interior color of the shape to copy of color.
 
color can either be a string with the name of the color or an instance of Color.

Methods inherited from Shape:
getBorderColor()
Return the color of the object's border.
getBorderWidth()
Returns the width of the border.
setBorderColor(borderColor)
Set the border color to a copy of borderColor.
 
borderColor can either be a string with the name of the color or an instance of Color.
setBorderWidth(borderWidth)
Set the width of the border to borderWidth.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.

 
class Text(Drawable)
    Represents text to be drawn to the screen.
 
  Methods defined here:
__init__(referencePoint=None, text='')
Create an instance of Text.
 
referencePoint  is an Point representing the upper left hand corner of the text.
                (Defaults to (0,0) if None specified)
text            is what should be printed. (Defaults to "")
getColor()
Returns a color instance represent the current text color.
getSize()
Returns the current size of the text.
getText()
Returns the current text of the object.
setColor(color)
Sets the color of the text to be a copy of color.
 
color can either be a string with the name of the color or an instance of Color.
setSize(size)
Set the size of the text to size.
setText(text)
Set the text to be rendered to text.

Methods inherited from Drawable:
getDepth()
Returns the depth of the object.
getReferencePoint()
Gets the current reference point.
move(dx, dy)
Move the object dx units to the right and dy units down.
 
Negative values move the object left or up.
moveTo(x, y)
Move the object to the specified coordinates.
setDepth(depth)
Sets the depth of the object.
 
Objects with a higher depth will be rendered behind those with lower depths.
setReferencePoint(referencePoint)
Sets the reference point to a copy of referencePoint.