CODEKALEIDOSCOPE

Creative Code. Colourful Thinking.

Lesson 5

Lesson 5 of 8

Lesson 5 - Data Types and Generative Art

Use numbers and strings as creative ingredients for generative Turtle artwork.

Do Now — 5 mins Theory — 10 mins I Do — 5 mins We Do — 10 mins You Do — 20 mins Plenary — 5 mins

Lesson Journey

Use these stages to move from reading code to creating your own version.

  1. Predict
  2. Run
  3. Investigate
  4. Modify
  5. Make

Learning Aim

To use different data types to control creative program output.

Defined End Point

By the end of this lesson, you will be able to use data types and random values to create controlled variation in generative artwork.

Key Vocabulary

data typeintegerstringrandom

Do Now

Sort the Data

12
"blue"
50
"teal"
100
"flower"
36
"circle"

Integer

Whole numbers

String

Text in quotation marks

  1. Which values are numbers?
  2. Which values are text?
  3. Which values could control a Turtle design?

Stretch: What might randint(1, 10) do?

Retrieval Practice

  • What does a loop repeat?
  • What does range() control?
  • How can angle affect a pattern?

Theory

Predict which values are numbers and which values are text.

Read the code first. Do not run it yet.

colour = "green"
size = 60

pencolor(colour)
circle(size)

Prediction question

Why does "green" need quotation marks, but 60 does not?

I Do

Watch the Demonstration

Watch how data values become creative choices in Turtle artwork.

Type this code into Mu Editor and run it.

from turtle import *
from random import choice

colours = ["cyan", "magenta", "yellow", "purple"]
size = 40

speed(0)

for i in range(16):
    pencolor(choice(colours))
    circle(size)
    right(22)

done()

Typing the code yourself helps build Python fluency and debugging skills.

We Do

Identify how different data types affect the design.

Strings

Which values are written in quotation marks?

Numbers

Which values control size or repeats?

List

How does the colours list create variation?

You Do

Modify one data value at a time and test the result.

Change colour names
Change size number
Change loop value
Add another colour

Workbook Activity

Create a generative artwork using numbers, strings and a list of colours.

Bronze

Change the list of colours.

Silver

Change the size and repeat values.

Gold

Add random choices for shape size or turn angle.

WAGOLL

Example code and output.

Use the example to connect the Python instructions with the visual result.

Example code

from turtle import *
from random import choice

colours = ["cyan", "magenta", "yellow", "purple"]
size = 40

speed(0)

for i in range(16):
    pencolor(choice(colours))
    circle(size)
    right(22)

done()

Example Output

This WAGOLL uses data values to create controlled generative variation.

Plenary

Explain what you learned and identify the next improvement you would make.

Extension task

Add another list and use it to vary pen size or circle size.

Plenary question

How can data make artwork feel generative?

Lesson Hub←  PreviousNext  →