Skip to content
Open

Main #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lessons/10_Turtles/10_Welcome/10_Welcome.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -50,7 +50,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
"version": "3.12.13"
},
"syllabus": {
"uid": "RRTPqCQu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
lines that start with a # are comments. They are not executed by Python. The
lines inside the three quotes are also comments, but of a different sort (
called "doc comments" ) Comments are used to explain what the code does. Read
the program and try to understand what each line does.
"""

import turtle # Tell Python we want to work with the turtle
the program and try to understand what each line does. # Tell Python we want to work with the turtle
turtle.setup(600,600,0,0) # Set the size of the window

tina = turtle.Turtle() # Create a turtle named tina
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
"version": "3.12.13"
},
"syllabus": {
"uid": "IloYptI2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,34 @@

Then change the code so that the turtle has a different image ( look in the 'images'
directory ) and moves to the corners of the screen in a square pattern.
"""
"""

import turtle
def set_turtle_image(turtle, image_name):
"""set the turtles shape to a custom imagen."""
from pathlib import Path
image_dir = Path(__file__).parent.parent /"images"
image_path = str(image_dir / image_name)

screen = turtle.getscreen()
screen.addshape(image_path)
turtle.shape(image_path)

#set up the screen
screen = turtle.screen()
screen.setup(width=600, height=600)

# create a turtle and set its shape to the custom gif
t = turtle.turtle()

set_turtle_image(t, "pikachu.gif")

t.penup()
t.speed(3)

for i in range(4):
t.goto(200, 200)
t.goto(-200, -200)


turtle.exitonclick()