-
Notifications
You must be signed in to change notification settings - Fork 0
Exercise
Winter is coming, so does Christmas. You have a small enterprise that produces Christmas tree decoration. This year you bought a machine that is able to produce embroidery and is controllable through a programmable interface.
The machine requests a matrix as an input where 0
means an empty pixel, and positive integers mean different
colors.
Your job is to design simple ornament matrices for this year's Christmas fair.
You'll have to:
- think in algorithms,
- handle edge cases,
- use parameters and default arguments,
- use nested lists and advanced list manipulation.
-
Implement the
draw_rectangle(width, height)
function to return matrices like this:1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
- There are further optional parameters,
border_color
,fill_color
, andborder_width
, all with default values of1
. - Called with default arguments, the returned matrix is a
width
-by-height
rectangle shape marked by1
s. - The rectangle's border has
border_color
, and it is filled withfill_color
. - The third optional parameter,
border_width
, specifies the width of the border. - There are no completely empty rows or columns in the returned matrix.
- The function provides reasonable answers to edge cases (all combinations of integers as parameters).
- There are further optional parameters,
-
Implement the
draw_triangle(height)
function to return arrays like this:0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 1 2 1 0 0 0 1 1 1 1 1 0 0 1 2 2 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
- There are further optional parameters,
border_color
andfill_color
, all with default values of1
. - Called with default arguments, the returned matrix consists of
height
rows and shows a tringle filled with1
s. - The triangle's border has
border_color
, and it is filled withfill_color
. - There are no completely empty rows or columns in the returned matrix.
- The function provides reasonable answers to edge cases (all combinations of integers as parameters).
- There are further optional parameters,
-
Implement the
draw_christmas_tree(blocks)
function to return arrays like this (whenblocks == 4
):0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 1 2 2 2 2 2 1 0 0 0 0 0 1 2 2 2 1 0 0 0 0 0 1 2 2 2 2 2 1 0 0 0 1 2 2 2 2 2 2 2 1 0 0 0 1 2 2 2 2 2 1 0 0 0 1 2 2 2 2 2 2 2 1 0 1 1 1 1 1 1 1 1 1 1 1
- There are further optional parameters,
border_color
andfill_color
, all with default values of1
. - Called with default arguments, the returned matrix shows a Christmas tree made of
blocks
pieces of trapezoid blocks and filled with1
s. Each block has 3 rows, and each first row is one step shorter than the last row of the block above. - The triangle's border has
border_color
, and it is filled withfill_color
. - There are no completely empty rows or columns in the returned matrix.
- The function provides reasonable answers to edge cases (all combinations of integers as parameters).
- There are further optional parameters,
-
[OPTIONAL] Implement the
draw_circle(radius)
function to return arrays like this (truncated):0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 2 2 2 2 2 2 2 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
- There are further optional parameters,
border_color
andfill_color
, all with default values of1
. - Called with default arguments, the returned matrix shows a circle of radius
r
filled with1
s. - The returned matrix shows a continuous circle outline of
border_color
, and filled withfill_color
. - There are no completely empty rows or columns in the returned matrix.
- The function provides reasonable answers to edge cases (all combinations of integers as parameters).
- There are further optional parameters,
None
- Try to solve the problems without distinguishing border and the inside first
(i.e.
border_color == fill_color
), you may find them much easier this way. - This is especially true for the
draw_circle
function. Drawing a nice border for a circle is a rather advanced exercise, even though the only extra math needed for the solution is the Pythagorean theorem to calculate distance.
For your information: Unfortunately, GitHub Classroom has an unstable service regarding repository creation and imports. If your repository fails to create or there are issues with code imports you can do the following steps:
- Wait. Sometimes it gets done after 1-2 hours.
- Write to your mentors to do it manually for you.
In the meantime, we are working on an own solution to replace GitHub Classroom. We plan to have it in the first quarter of 2020.
Click here to clone your own Git repository: https://classroom.github.com/a/obBDAwez
- Nested lists
- On default arguments in the documentation
You will need this only at review time, after completing the project. Use this form to record the review you provide for your peer.