Presentation is loading. Please wait.

Presentation is loading. Please wait.

Frozen Graphics Lesson 3.

Similar presentations


Presentation on theme: "Frozen Graphics Lesson 3."— Presentation transcript:

1 Frozen Graphics Lesson 3

2 Homework There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has been set for a lesson They can be completed in a booklet or online using Moodle. Your teacher will let you know her/his preferred method. Make sure you have written your homework clearly in your planner. The homework is to be completed for the next lesson

3 Objective of the lesson
Use Scratch to draw repeating patterns. All of you will: Use Python to draw a snowflake, or part of a snowflake to the screen Most of you will: Draw a snowflake or repeated number of snowflakes to the screen Some of you will: Draw repeated snowflakes to the screen with a random element using the random function

4 Starter Open Idle3 (Python 3)
Click File>New File to open the Python editor Type the following into the editor Give your turtle a name. Mine is called timmy ‘import turtle’ allows us to your ‘turtle’ type words Turtle.Turtle() is the function used run the turtle but we have now given it the name elsa (we have defined it)

5 We will make a Python snowflake
Can you draw the start of this Snowflake HINTS My main line is 20 long My branched lines are 10 long I have sometimes turned left(45) I have sometimes turned right(45) I have sometimes gone forward I have sometimes gone backward Else the turtle needs to point forwards at the end

6 Did you get it correct? Now repeat this 3 times

7 Did you get it correct? Now make it return to the start point and turn left by 45 degrees It only needs to do this once

8 Did you get it correct? Now make this whole s sequence repeat 8 times

9 Did you get it correct? There is a loop within a loop
The first loop draws one of the snowflakes arms The second loop repeats this 8 times

10 I can make the code for making the snowflake into a function
I can make the code for making the snowflake into a function. This means that I can reuse the code I define the snowflake code by typing def and the name of the reusable piece of code e.g. snowflake then (): Code then needs indenting each time there is a :

11 I can then run this reusable code by typing in snowflake()
This would make 10 snowflakes

12 I can then run this reusable code by typing in snowflake()
This would make 10 snowflakes How could I make it more efficient?

13 Did you get it correct? The problem is that they draw 10 snowflakes all on top of each other. We can solve this by moving and turning before we draw the next snowflake

14 The snowflakes are joined up
We can solve this by using elsa.penup() elsa.pendown() when it moves between snowflakes Try to code this in

15 Did you get it correct? However, snowflake positions should be random

16 Did you get it correct? However, snowflake positions should be random

17 We need to tell the program that we will be using random numbers by importing the random function
We can create a random number from this functionfandowm

18 We can create a random number from this function.
I will call the random number, ‘randomnumber’ This will equal a random integer (whole number) between 50 and 200 randomnumber = random.randint(50,200) I need to use the randomnumber which is generated for the distance between the snowflakes and the turns

19 Try experimenting with the randomnumber by changing the range that it chooses from between 50 and 200 You can create new randomnumbers, giving them different names for the sizes of the snowflakes.

20 Random snowflake solution


Download ppt "Frozen Graphics Lesson 3."

Similar presentations


Ads by Google