Easy Draw Module
Search…
Style Guide
The documentation will show examples a certain way, but it doesn't mean you have to write your code that way.
I have designed the documentation for what I believe is best for beginner students to work with the module and learn certain concepts.
Below I outline some examples of this:

Importing Easy Draw

In all examples Easy Draw is imported the following way:
1
import easy_draw
2
​
3
easy_draw.load_canvas()
4
​
5
square = easy_draw.Rectangle(
6
xy = (100, 100),
7
width = 200,
8
height = 200
9
)
10
​
11
easy_draw.end()
Copied!
This mean in order to use any of the Easy Draw commands, you need to use the module name and a dot operator.
Example: easy_draw.load_canvas()
My philosophy: It is best practice to have students work with modules using full module name first, but it does not prevent you for doing the following examples.
It is possible to indiscriminately import everything from a module at one fell swoop. This is called a wildcard import and it is done like this from module import * . It makes it so you do not need to reference the module to use its commands. See below:
1
from easy_draw import *
2
​
3
load_canvas()
4
​
5
square = Rectangle(
6
xy = (100, 100),
7
width = 200,
8
height = 200
9
)
10
​
11
end()
Copied!
Yes, the code is much less complex looking now. However, this is not Python best practice and wildcard imports should be avoided according to PEP 8. I want students to know they are working with a module and not abstract that experience too much.
You can also nickname the module when importing so you do not have to type easy_draw each time. You do this by using the import module as nickname structure.
1
import easy_draw as ed
2
​
3
ed.load_canvas()
4
​
5
square = ed.Rectangle(
6
xy = (100, 100),
7
width = 200,
8
height = 200
9
)
10
​
11
ed.end()
Copied!
I have done this with modules before and students seem to get confused about what the module's actual name is. Then when they come across code online that doesn't nickname the way they expect, they are confused. So, I only show this trick later on when they are more experienced or when a student asks "do I really have to type easy_draw each time?"

Using Object Constructors

In the examples you will notice that the object constructor functions are stylized to have each argument (property value) on separate lines:
1
square = easy_draw.Rectangle(
2
xy = (100, 100),
3
width = 200,
4
height = 200
5
)
Copied!
I have students stylize the constructor method calls this way so it is easier for them to see the individual property values of the object they are instantiating.
Of course you can put these values all on one line which is the typical way to call functions and pass argument values.
1
square = easy_draw.Rectangle(xy = (100, 100), width = 200, height = 200)
Copied!
​
You may also notice that each example explicitly states the instance variable (property) name when assigning it a value in the constructor function call. I use this practice to help students learn the parameter needed to construct the object. Previous to doing this students would plug in values and not really know what the value was for. Explicitly using the name ensures the student knows what each value is used for. Example:
1
square = easy_draw.Rectangle(
2
xy = (100, 100),
3
width = 200,
4
height = 200
5
)
Copied!
But, of course, you can use positional arguments and provide the values in the order the constructor function expects them. Rectangle(xy, width, height)
1
square = easy_draw.Rectangle((100, 100), 200, 200)
Copied!
However, the optional properties of an object (like color) are not positional arguments. These properties are keyword arguments and need to use the instance variable (property) name to set the value.
1
square = easy_draw.Rectangle((100, 100), 200, 200, color = "red")
Copied!

Function and Property Names

All constructor functions start with a capital letter and use CamelCasing.
Examples: Rectangle(), Oval(), Text(), RegPolygon()
All other functions and instance variables/property names use all lowercase letters and snake_casing.
Examples: load_canvas(), color, .rotate(), border_width

Storing Objects in Variables

All examples show objects being stored in a variable. If you want to be able to use a method on an object or change a property of that object, you must store it in a variable to reference the object later. So, all examples show objects being stored and referenced from a variable.
1
square = easy_draw.Rectangle(
2
xy = (100, 100),
3
width = 200,
4
height = 200
5
)
6
​
7
square.rotate(45)
Copied!
The above example shows the Rectangle object is stored in a variable named square. Because it stored in a variable, we can use the .rotate() method on it.
​
However, the shape will be drawn without storing the object in a variable.
1
easy_draw.Rectangle(
2
xy = (100, 100),
3
width = 200,
4
height = 200
5
)
Copied!
If you try the above, it still creates the square.
​
You can call methods on an object without storing it in a variable by immediately following the constructor function call with the method call.
1
easy_draw.Rectangle(
2
xy = (100, 100),
3
width = 200,
4
height = 200
5
).rotate(45)
Copied!
OR
1
easy_draw.Rectangle(xy = (100, 100), width = 200, height = 200).rotate(45)
Copied!

Coordinates as Tuples or

Lots of shape drawing and game Python libraries will require x and y coordinates as separate values. I have found that students see these values as a pair, so Easy draw objects expect x and y coordinate to be coupled as a tuple.
Example: This -- xy =(100, 200) | Not this -- x = 100, y = 200
​
However, the points_list for Polygon and Line must be pairs of x and y (an even amount of numbers) but not in tuples, simply just listed:
Example:
  • This -- points_list = [50, 210, 180, 250, 300, 210]
  • Not this -- points_list = [(50, 210), (180, 250), (300, 210)]
Last modified 9mo ago