Link Search Menu Expand Document

04 Generative Art

In this fourth Python programming assignment, you move the user interaction from the Terminal to the web browser. You organise the code in several files, and you import modules to rely on code from other developers. Finally, you create an algorithm that generates random Scalable Vector Graphics (SVG) that you expose on the web.


Through this assignment, we explore the following concepts:

While-Loop

For-Loop

String

web endpoint

SVG

Modules

Flask


Amanda J Hogan’s talk inspired the first step of this assignment. Thank you!

💨 Brief Refresher

Let’s start with a brief refresher of the topics we covered in previous assignments that might be useful to remember.

  • While-Loop – a structure that repeats a block of code while a condition is true. It involves an initialisation code, a condition to continue iterating as long as it is true and the Change code which modify the condition.
1
2
3
# initialisation code
while (condition):
    # change code
  • For-Loop – a structure that makes the boundaries of the loop explicit. In contrast with the while-loop, we recommend for-loop when we know how many iterations are needed. This time we define a variable as part of the structure, often named i for ‘index’, which keeps track of the iteration number. start, finish, and change define the number of iterations.
1
2
for i in range(start, finish, change):
    # action
  • Function – a block of code that performs an action, identified by a name. A function defines a set of actions that we can call in a single line, everywhere in the code. It receives information through parameters and returns a result. We use the name to call it, i.e. running the associated code block (e.g. print()). When calling a function, we provide the values (or arguments) necessary for each function’s parameter. So, functions are handy because it avoids duplicating code, making the development more efficient and robust.
1
2
3
4
5
6
7
8
9
def name(parameter1, parameter2):
    """This is an example of function definition.
    parameter1 -- a first example parameter
    parameter2 -- a second example parameter
    """

    # Action

    return result

⏰ Time Management and Expectations

There is a lot to explore with this assignment. Make sure you understand Step 3 and the Lists in Step 5.

Next: Review


Table of contents