Unit 8 Flashcards
What is the difference in writing the code when we learned about the turtle module in a previous unit and drawing with loops?
We had to write the same lines of code several times in order to draw shapes when we learned about the turtle module in a previous unit. But drawing with loops would make drawing with our turtle much simpler.
Can we use for loop when drawing with loops?
Yes. That way, we don’t have to write quite as much code. This also helps prevent typos and it’s a lot more efficient.
Draw a triangle using for loop.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Triangle = turtle.Pen()
For count in range(0,3):
Triangle.forward(50)
Triangle.left(120)
Draw a pentagon using for loop.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Pentagon = turtle.Pen()
For count in range(0,5):
pentagon.forward(50)
Pentagon.left(72 )
Draw an octagon using for loop.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
#Create the pen object
Import turtle
Shape = turtle.Pen()
#Loop to draw the octagon
For count in range (0,8):
Shape.forward(60)
Shape.left(360/8)
Using functions can _____ when it comes to drawing with the turtle.
Save a lot of time
Make drawing more interactive
Write a function that draws a triangle of a particular size and then a program that asks the user how big of a triangle they would like to see.
Now, we want to turn this into a function that takes a parameter for the length and then uses that to draw the triangle.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Triangle = turtle.Pen()
Def draw_triangle(length):
For count in range(0,3):
Triangle.forward(length)
Triangle.left(120)
Triangle_size = int(input(“How long should each side of the triangle be?”))
Draw_triangle(triangle_size)
Write a program that draws a shape of any number of sides.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Shape = turtle.Pen()
Sides = int(input(“How many sides should the shape have?”))
Size = int(input(“How long should each side be?”))
Def draw_shape(length, number_of_sides):
For count in range(0,3):
Shape.forward(length)
Shape.left(360/ number_of_sides)
Draw_shape(size, sides)
Draw an octagon with a function by first asking the user how long they would like each side of the octagon to be. Then, write a function to draw an octagon that has 8 sides, each of the user’s specified length, in pixels.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
#Create the pen object
Import turtle
Shape = turtle.Pen()
#Function to draw the octagon
Def draw_shape(length, num):
For count in range(0, num):
Shape.forward(length)
Shape.left(360/num)
#Main program
#Prompt the user to enter side length
Shape_side = int(input(“How long should each side be?”))
Draw_shape(shape_side, 8)
How do you control our colour options even more?
By adding specific values to our code.
What other ways other there to control the colour of the turtle?
RGB values where R stands for red, G stands for green, B stands for blue. These values tell you how much red, how much green, and how much blue are in your particular colour (on a scale of 0 to 1, which matches up to 0% of a colour to 100% of a colour).
How do you make a blue triangle on turtle module?
Set red and green to 0 and blue to 1.
What does this code mean?
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Triangle = turtle.Pen()
Def draw_triangle(length):
Triangle.color(0,0,1)
Triangle.begin_fill()
For count in range(0,3):
Triangle.forward(length)
Triangle.left(120)
Triangle.end_fill()
Triangle_size = int(input(“How long should each side of the triangle be?”))
Draw_triangle(triangle_size)
This line: triangle.color(0,0,1) is where we set the color to blue.
This line: triangle.begin_fill() is where we tell our turtle to start filling in with color.
This line: triangle.end_fill() is where we tell our turtle to stop filling it in. Until we write that line, the turtle won’t fill in the shape with color.
Write a program that uses RGB to draw a triangle filled with blue color that is 120 pixels large.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Triangle = turtle.Pen()
Def draw_triangle(length, red_value, green_value, blue_value):
Triangle.color(red_value, green_value, blue_value)
Triangle.begin_fill()
For count in range(0,3):
Triangle.forward(length)
Triangle.left(120)
Triangle.end_fill()
Triangle_size = int(input(“How long should each side of the triangle be?”))
Red = float(input(“How much red should the triangle have (on a scale of 0 to 1)?”))
Green = float(input(“How much red should the triangle have (on a scale of 0 to 1)?”))
Blue = float(input(“How much red should the triangle have (on a scale of 0 to 1)?”))
Draw_triangle(triangle_size, red, green, blue)
What code sets shape_pen’s color to purple (half blue and half red)?
shape_pen.color(0.5,0,0.5)
Remember that the format for using color() is color(RED_VALUE, GREEN_VALUE, BLUE__VALUE)
How do we make spirals using the turtle module?
Loops and functions.
Write a program that creates a triangle spiral.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
Import turtle
Triangle = turtle.Pen()
Def draw_triangle_spiral(number_of_lines):
For count in range (0, number_of_lines):
Triangle.forward(count)
Triangle.left(120)
Lines = int(input(“How many lines should be in our triangle spiral?”))
Draw_triangle_spiral(lines)
Using a function, create a design of spiralling lines in an octagon shape.
Please ignore the capital letters of the first letter. It is suppose to be small letters.
#Create the pen object
Import turtle
Shape = turtle.Pen()
#Function to draw spiralling lines graphics
Def draw_spiral_shape(num_sides):
For count in range (0,60):
Shape.forward(count)
Shape.left(360/num_sides)
#Main program
Draw_spiral_shape(8)