Pencil code program: Chaos game
About this lesson
The ‘chaos game’ is a way to see how patterns can result from certain random events. Use this program to run the ‘chaos game’, randomly moving the turtle to create a pattern (for more information, search 'chaos game’). Have students analyze or fill in or change parts of the pencil code program.
Year band: 7-8Curriculum Links Assessment
Links with Digital Technologies Curriculum Area
|Processes and Production Skills||
Design algorithms represented diagrammatically and in English, and trace algorithms to predict output for a given input and to identify errors (ACTDIP029)
Implement and modify programs with user interfaces involving branching, iteration and functions in general-purpose programming language (ACTDIP030)
Student self-assessment task
Consider the commands used to move the Bee-Bot. Students complete a simple cloze activity to evaluate understanding:
Bee-Bots travel ______cm each time they move one step. The arrow keys at the front and back are used to program the Bee-Bot to move __________ or _____________. The arrow keys on each side are used to program the Bee-Bot to move __________ or ____________. I can start a new program by pressing the ___________ button.
Roll out a bag of marbles onto the floor. Look at the random pattern made. If the bag of marbles was released would the same pattern be made? Ask students to explain.
Discuss random other events and randomisation with relevant examples.
Ask students, ‘Would you expect to see patterns with random events?’ Why or why not?
Introduce the ‘chaos game’ as a way to see how patterns can result from certain random events.
Use the pencil code program step below to run the ‘chaos game’, randomly moving the turtle to create a pattern (for more information, search 'chaos game’).
Provide students with a link to pencilcode.net and the pencil code program step below. Run the program and ask students to describe their observations. Ask the following questions:
- What are the parts of the program? What results onscreen?
- What is the program doing?
- At what point do you see a pattern emerging?
Have students analyze or fill in or change parts of the pencil code program. This program could be used to further your understanding of how you could use Pencil Code in the classroom, as a demonstration or discussion with your students, or as a way to introduce various CT concepts, such as pattern recognition or abstraction, to your students by inviting them to extend the existing functionality of the program.
Ways to remix the program
- Change fd value from 200 to another number for each sprite. What happens when you don’t use the same value for each of the three dots (sprites)?
- Change the speed from 1000 to another value
- Change the range from 1..2000 to another value eg. 1..50000
- Change the value of the factor multiplying the fd distance(p), from 0.5 to another value eg try 0.75 for starters
Computational Thinking Concepts
|Abstraction||Identifying and extracting relevant information to define main idea(s)|
|Pattern Recognition||Observing patterns, trends, and regularities in data|
* Explore the Computational Thinking Concepts Guide for a list of the CT concepts, including tips for implementing each concept in your classroom.
Pencil Code Program
Copy/Paste the following program into a ‘Blank Editor’ on the Pencil Code website.
# Copyright 2015 Google Inc. All Rights Reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. v = [ new Sprite('red dot').fd(200) new Sprite('blue dot').rt(120).fd(200) new Sprite('green dot').lt(120).fd(200) ] speed 1000 for [1..2000] p = random v turnto p fd distance(p) * 0.5 dot black, 2 await done defer()