shapes
index
c:\users\martin ohanlon\documents\raspberrypilearning\fl-object-oriented-programming\docs\week-1\code\shapes.py

# This code requires Python 3 and tkinter (which is usually installed by default)
# This code will NOT work on trinket.io as the tkinter module is not supported
# Raspberry Pi Foundation 2020
# CC-BY-SA 4.0

 
Modules
       
random

 
Classes
       
builtins.object
Paper
Shape
Oval
Rectangle
Triangle

 
class Oval(Shape)
    Oval(width=50, height=50, x=None, y=None, color='black')
 

 
 
Method resolution order:
Oval
Shape
builtins.object

Methods defined here:
draw(self)
Draws an oval on the canvas. The properties of the oval
can be set using the getter and setter methods in Shape

Methods inherited from Shape:
__init__(self, width=50, height=50, x=None, y=None, color='black')
Creates a generic 'shape' which contains properties common to all
shapes such as height, width, x y coordinates and colour.
 
Args:
    width (int): The width of the shape. Defaults to 50.
    height (int): The height of the shape. Defaults to 50.
    x (int): The x position of the shape. If None, the x position will be the middle of the screen. Defaults to None.
    y (int): The y position of the shape. If None, the y position will be the middle of the screen. Defaults to None.
    color (string): The color of the shape. Defaults to "black"
get_color(self)
Returns the colour of the shape
 
Returns:
    color (string): The color of the shape
randomize(self, smallest=20, largest=200)
Randomly generates width, height, position and colour for a shape. You can specify
the smallest and largest random size that will be generated. If not specified, the
generated shape will default to a random size between 20 and 200.
 
Args:
    smallest (int): The smallest the shape can be. Defaults to 20
    largest (int): The largest the the shape can be. Defaults to 200.
set_color(self, color)
Sets the colour of the shape
 
Args:
    color (string): The color of the shape.
set_height(self, height)
Sets the height of the shape.
 
Args:
    height (int): The height of the shape.
set_width(self, width)
Sets the width of the shape.
 
Args:
    width (int): The width of the shape
set_x(self, x)
Sets the x position of the shape
 
Args:
    x (int): The x position for the shape.
set_y(self, y)
Sets the y position of the shape
 
Args:
    y (int): The y position for the shape.

Data descriptors inherited from Shape:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Paper(builtins.object)
    Paper(width=600, height=600)
 

 
  Methods defined here:
__init__(self, width=600, height=600)
Create a Paper object which is required to draw shapes onto.
 
It is only possible to create 1 Paper object.
 
Args:
    width (int): The width of the display. Defaults to 600.
    height (int): The height of the display. Defaults to 600.
 
Returns:
    Paper: A Paper object
display(self)
Displays the paper

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
tk = None

 
class Rectangle(Shape)
    Rectangle(width=50, height=50, x=None, y=None, color='black')
 
Rectangle class is a subclass of Shape
 
 
Method resolution order:
Rectangle
Shape
builtins.object

Methods defined here:
draw(self)
Draws a rectangle on the canvas. The properties of the rectangle
can be set using the getter and setter methods in Shape

Methods inherited from Shape:
__init__(self, width=50, height=50, x=None, y=None, color='black')
Creates a generic 'shape' which contains properties common to all
shapes such as height, width, x y coordinates and colour.
 
Args:
    width (int): The width of the shape. Defaults to 50.
    height (int): The height of the shape. Defaults to 50.
    x (int): The x position of the shape. If None, the x position will be the middle of the screen. Defaults to None.
    y (int): The y position of the shape. If None, the y position will be the middle of the screen. Defaults to None.
    color (string): The color of the shape. Defaults to "black"
get_color(self)
Returns the colour of the shape
 
Returns:
    color (string): The color of the shape
randomize(self, smallest=20, largest=200)
Randomly generates width, height, position and colour for a shape. You can specify
the smallest and largest random size that will be generated. If not specified, the
generated shape will default to a random size between 20 and 200.
 
Args:
    smallest (int): The smallest the shape can be. Defaults to 20
    largest (int): The largest the the shape can be. Defaults to 200.
set_color(self, color)
Sets the colour of the shape
 
Args:
    color (string): The color of the shape.
set_height(self, height)
Sets the height of the shape.
 
Args:
    height (int): The height of the shape.
set_width(self, width)
Sets the width of the shape.
 
Args:
    width (int): The width of the shape
set_x(self, x)
Sets the x position of the shape
 
Args:
    x (int): The x position for the shape.
set_y(self, y)
Sets the y position of the shape
 
Args:
    y (int): The y position for the shape.

Data descriptors inherited from Shape:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Shape(builtins.object)
    Shape(width=50, height=50, x=None, y=None, color='black')
 

 
  Methods defined here:
__init__(self, width=50, height=50, x=None, y=None, color='black')
Creates a generic 'shape' which contains properties common to all
shapes such as height, width, x y coordinates and colour.
 
Args:
    width (int): The width of the shape. Defaults to 50.
    height (int): The height of the shape. Defaults to 50.
    x (int): The x position of the shape. If None, the x position will be the middle of the screen. Defaults to None.
    y (int): The y position of the shape. If None, the y position will be the middle of the screen. Defaults to None.
    color (string): The color of the shape. Defaults to "black"
get_color(self)
Returns the colour of the shape
 
Returns:
    color (string): The color of the shape
randomize(self, smallest=20, largest=200)
Randomly generates width, height, position and colour for a shape. You can specify
the smallest and largest random size that will be generated. If not specified, the
generated shape will default to a random size between 20 and 200.
 
Args:
    smallest (int): The smallest the shape can be. Defaults to 20
    largest (int): The largest the the shape can be. Defaults to 200.
set_color(self, color)
Sets the colour of the shape
 
Args:
    color (string): The color of the shape.
set_height(self, height)
Sets the height of the shape.
 
Args:
    height (int): The height of the shape.
set_width(self, width)
Sets the width of the shape.
 
Args:
    width (int): The width of the shape
set_x(self, x)
Sets the x position of the shape
 
Args:
    x (int): The x position for the shape.
set_y(self, y)
Sets the y position of the shape
 
Args:
    y (int): The y position for the shape.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Triangle(Shape)
    Triangle(x1=0, y1=0, x2=20, y2=0, x3=20, y3=20, color='black')
 

 
 
Method resolution order:
Triangle
Shape
builtins.object

Methods defined here:
__init__(self, x1=0, y1=0, x2=20, y2=0, x3=20, y3=20, color='black')
Overrides the Shape constructor because triangles require three
coordinate points to be drawn, unlike rectangles and ovals.
 
Args:
    x1 (int): The x position of the coordinate 1. Defaults to 0.
    y1 (int): The y position of the coordinate 1. Defaults to 0.
    x2 (int): The x position of the coordinate 2. Defaults to 20.
    y2 (int): The y position of the coordinate 2. Defaults to 0.
    x3 (int): The x position of the coordinate 3. Defaults to 20.
    y4 (int): The y position of the coordinate 3. Defaults to 20.
    color (string): The color of the shape. Defaults to "black"
draw(self)
Draws a triangle on the canvas. The properties of the triangle
can be set using the getter and setter methods in Shape
randomize(self)
Randomly chooses the location of all 3 triangle points as well
as the colour of the triangle
set_height(self, height)
Overrides the setter method for height
 
Args:
    height (int): The height of the shape
set_width(self, width)
Overrides the setter method for width
 
Args:
    width (int): The width of the shape

Methods inherited from Shape:
get_color(self)
Returns the colour of the shape
 
Returns:
    color (string): The color of the shape
set_color(self, color)
Sets the colour of the shape
 
Args:
    color (string): The color of the shape.
set_x(self, x)
Sets the x position of the shape
 
Args:
    x (int): The x position for the shape.
set_y(self, y)
Sets the y position of the shape
 
Args:
    y (int): The y position for the shape.

Data descriptors inherited from Shape:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Data
        BOTH = 'both'