*********
*********
Resize images
Due Date: October 22, 2024
*********
*********
Flying Butterfly Animation - Python Program Description
Due Date: October 24, 2024
This document provides a description of the Python Turtle program that animates a butterfly with moving wings. The butterfly flies around the screen following a random path, with its wings flapping up and down to mimic real butterfly movements.
Key Features of the Program:
- The butterfly consists of a central body and two wings, each animated separately to create a flapping effect.
- The program generates a random flight path for the butterfly to follow.
- The wings continuously flap while the butterfly moves, creating a realistic flying motion.
- The screen background is set to a sky-blue color to simulate an outdoor environment.
- The movement speed and path points are controlled to make the butterfly’s movement feel natural and unpredictable.
How to Run the Program:
To run this program, you'll need Python installed along with the Turtle module.
Save the program code to a .py
file and run it to see the butterfly animation.
Your file name is PX_lastname_ButterFly.py
Original program value: (100 points)
Source Code:
Sample output image:
Falling Snowflakes - Python Program Description
Due Date: October 28, 2024
This program animates falling snowflakes using Python's Turtle module. Each snowflake falls from the top of the screen with a random speed, size, and path, simulating a winter scene.
Key Features:
- Snowflake Class: Each snowflake is represented as an object in the Snowflake class. The snowflake is shaped like a circle and is drawn using the Turtle object. Each snowflake is given:
- A random size, using
shapesize()
.
- A random falling speed, using the
speed_y
attribute.
- A horizontal drift to simulate wind, making the snowflakes sway slightly left or right.
- Falling Behavior: Each snowflake falls downward by updating its vertical position (
ycor()
) and also moves slightly sideways using the drift attribute. The fall is achieved by adjusting the turtle's position with the goto()
method. When the snowflake reaches the bottom of the screen, it reappears at the top with new randomized properties (size, speed, and position).
- Randomization:
- The size of each snowflake is randomly set between small and large, making each snowflake look unique.
- The speed of falling is randomized for each snowflake, meaning some fall faster than others.
- The snowflakes also drift horizontally with a slight random 'wind effect,' which simulates the natural movement of falling snow.
- Animation: The program runs in an infinite loop where each snowflake is constantly updated in position. The snowflakes are created at the beginning, stored in a list, and continuously redrawn on the screen as they fall. The
screen.update()
method refreshes the screen for a smooth animation, and the time.sleep()
function controls the speed of the falling animation.
How the Program Works:
The Turtle module provides graphical functionality. The screen is set up to be 800x600 pixels with a dark blue background to represent a night sky.
The snowflake objects are created from a custom class Snowflake. Each object is positioned at random starting points at the top of the screen and begins falling with random attributes like speed, size, and horizontal drift.
The main animation loop continually updates the snowflake positions on the screen. When a snowflake reaches the bottom, it is reset to the top, maintaining an endless winter snowfall effect.
You can modify this program by changing the number of snowflakes, their speed, and even adding other elements such as wind effects or snow accumulation.
I put your program out of order.
This is a puzzle to put together.
Look at your prior assignments.
They are similar to this one.
# Create a class for Snowflake
# Create a number of snowflakes
# Keep the window open
# List to hold snowflakes
# Main loop to animate the snowflakes
# Reset snowflake to the top once it falls below the screen
# Run the animation
# Setup the screen
animate_snowflakes()
class Snowflake(turtle.Turtle):
def __init__(self):
def animate_snowflakes():
def fall(self):
for _ in range(50):
for snowflake in snowflakes:
if self.ycor() < -300:
import random
import time
import turtle
new_x = self.xcor() + self.drift
new_y = self.ycor() - self.speed_y
screen = turtle.Screen()
screen.bgcolor("darkblue")
screen.mainloop()
screen.setup(width=800, height=600)
screen.title("Falling Snowflakes")
screen.tracer(0) # Turn off automatic updates for smooth animation
screen.update() # Update the screen for smooth animation
self.color("white")
self.drift = random.uniform(-1, 1) # Random horizontal drift
self.goto(new_x, new_y)
self.goto(random.randint(-390, 390), random.randint(250, 400))
self.goto(random.randint(-390, 390), random.randint(250, 400))
self.penup()
self.shape("circle")
self.shapesize(stretch_wid=self.size, stretch_len=self.size)
self.shapesize(stretch_wid=self.size, stretch_len=self.size)
self.size = random.uniform(0.5, 1.5)
self.size = random.uniform(0.5, 1.5) # Reset size
self.speed(0)
self.speed_y = random.uniform(1, 3) # Random speed for each snowflake
self.speed_y = random.uniform(1, 3) # Reset speed
snowflake = Snowflake()
snowflake.fall()
snowflakes = []
snowflakes.append(snowflake)
super().__init__()
time.sleep(0.02) # Control the speed of animation
while True:
Your file name will be PX_Lastname_snowflakes.
Files to Submit
• PX_snowflakes_lastname.png (Screenshot of the program)
• PX_snowflakes _lastname (Google Drive document)
• PX_snowflakes _lastname.py (Actual Python program)
• PX_snowflakes _lastname.mp4 (Video of the program running)
•
Drop off your 4 files into Google Classroom.