Creating a simple storytelling app using Python’s Turtle graphics can be a delightful way to combine coding skills with creativity. In this app, we’ll narrate a short story while the Turtle draws related scenes or characters on the screen.
Story Concept
Let’s narrate a simple story about a day in the park. The Turtle will draw a sun, a tree, and a bench to represent scenes from the story.
Python Code for Storytelling App
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import turtle # Setup the screen wn = turtle.Screen() wn.bgcolor("lightblue") wn.title("A Day in the Park - Storytelling App") # Create the drawing turtle artist = turtle.Turtle() artist.penup() artist.speed(1) # Slow drawing speed for storytelling effect # Function to draw the sun def draw_sun(): artist.goto(-200, 150) artist.color("yellow") artist.begin_fill() artist.circle(50) artist.end_fill() # Function to draw a tree def draw_tree(): artist.goto(100, -50) artist.color("brown") artist.pendown() artist.begin_fill() artist.rect = turtle.Turtle() artist.rect.shape("square") artist.rect.shapesize(2, 0.5) artist.end_fill() artist.penup() # Draw the leaves artist.goto(100, 0) artist.color("green") artist.begin_fill() artist.circle(40) artist.end_fill() # Function to draw a bench def draw_bench(): artist.goto(-150, -150) artist.color("gray") artist.pendown() artist.begin_fill() artist.rect = turtle.Turtle() artist.rect.shape("square") artist.rect.shapesize(0.5, 3) artist.end_fill() artist.penup() # Narrate the story while drawing def narrate_story(): wn.textinput("Story", "Once upon a time, there was a beautiful park. (Press OK to continue)") draw_sun() wn.textinput("Story", "In the park, there stood a tall tree that provided shade to the visitors. (Press OK to continue)") draw_tree() wn.textinput("Story", "Near the tree, there was a bench where people could sit and enjoy the view. (Press OK to continue)") draw_bench() wn.textinput("Story", "And that's the end of our story. Thank you for watching! (Press OK to finish)") narrate_story() turtle.done() |
How It Works
- Screen Setup: The Turtle graphics window is set up with a light blue background to represent the sky and titled to reflect the storytelling app’s theme.
- Drawing Functions: Separate functions (
draw_sun
,draw_tree
,draw_bench
) are defined to draw different elements of the story. Each function positions the Turtle and uses basic shapes and fills to create the scene. - Story Narration: The
narrate_story
function progresses through the story, prompting the user to press OK to continue after each scene is introduced. As the story progresses, corresponding functions are called to draw the story elements on the screen. - Interactive Storytelling: By using
wn.textinput
for narration, the app makes the story interactive, allowing the user to proceed through the story at their own pace.
Customization and Expansion
- Enhance the Story and Artwork: Add more details to the story and include additional Turtle graphics functions to draw those elements.
- Add Characters: Introduce characters using Turtle shapes or more complex drawings and animate them according to the story.
- Incorporate Sound: Use the
winsound
module (Windows) or other libraries to add background music or sound effects for a more immersive storytelling experience.
This simple storytelling app demonstrates how to use programming to bring stories to life, making it an engaging way to learn programming concepts and storytelling techniques.