Mundo em Python

POSTAIS OU CARTÕES DE NATAL

# Postal de àrvores de Natal: Link para a página original


import turtle
import random
web_based = True
if web_based:
i_scale = 1.5
snow_size = 4
snow_speed = 3
draw_speed = 10
rate_of_snow_balls = 6
else:
i_scale = 1
snow_size = 7
snow_speed = 2
draw_speed = 10
rate_of_snow_balls = 2

width = 600 / i_scale
height = 600 / i_scale screen = turtle.Screen()
screen.title("FELIZ NATAL!") def make_triangle(x, y, size, outline, triangle):
triangle.hideturtle()
triangle.penup()
triangle.setposition(x, y)
triangle.pensize(3)
if outline:
triangle.pendown()
if not outline:
triangle.fillcolor("forest green")
triangle.begin_fill()
triangle.setposition(x + size, y - size)
triangle.setposition(x - size, y - size)
triangle.setposition(x, y)
if not outline:
triangle.end_fill()
def make_ball(x, y, size, colour, ball):
ball.hideturtle()
ball.penup()
ball.setposition(x, y)
ball.color(colour)
ball.dot(size) def move_snow(snow):
position = snow.position()
snow.clear()
make_ball(position[0], position[1] - snow_speed, snow_size, "white", snow) def snow_fall():
rand_make_snow = random.randint(0, rate_of_snow_balls)
if rand_make_snow == 0:
snow = turtle.Turtle()
snow.hideturtle()
snow.penup()
list_of_snow.append(snow)
make_ball(random.randint(-width / 2, width / 2), width / 2, snow_size,
"white", snow)
for snow in list_of_snow:
move_snow(snow)
if snow.position()[1] <= -width / 2:
snow.clear()
list_of_snow.remove(snow)
del snow
screen.update() # Fazer a àrvore de Natal
triangle_1 = turtle.Turtle()
triangle_1.speed(draw_speed)
outline = True
for repeat in range(2):
make_triangle(0, width / 3, width / 6, outline, triangle_1)
make_triangle(0, width / 4, width / 4, outline, triangle_1)
make_triangle(0, width / 8, width / 3, outline, triangle_1)
outline = False

screen.tracer(0)
stem = turtle.Turtle()
# NEVE
stem.penup()
stem.hideturtle()
stem.setposition(-width, -width / 3)
stem.color("white")
stem.begin_fill()
stem.setposition(width, -width / 3)
stem.setposition(width, -width / 2)
stem.setposition(-width, -width / 2)
stem.end_fill()
screen.update() # TRONCO DE NATAL
stem.color("brown")
stem.setposition(-width / 30, -width / 4.8)
screen.tracer(1)
stem.pendown()
stem.begin_fill()
stem.setposition(width / 30, -width / 4.8)
stem.setposition(width / 30, -3 * width / 8)
stem.setposition(-width / 30, -3 * width / 8)
stem.setposition(-width / 30, -width / 4.8)
stem.end_fill() screen.bgcolor("sky blue") # BOLAS DE NATAL
screen.tracer(2)
ball_colours = ["red", "red", "red", "gold", "violet", "white"]
ball_positions = [(-width / 30, width / 4), (3 * width / 40, width / 5),
(-width / 20, width / 6), (width / 30, width / 9),
(-width / 12, width / 30), (width / 12, width / 24),
(-width / 9, -width / 20), (width / 8, -width / 15),
(0, -width / 6), (-width / 6, -width / 6),
(width / 5, -width / 7.5)
]
for position in ball_positions:
make_ball(position[0], position[1], 20 / i_scale,
random.choice(ball_colours),
turtle.Turtle())
screen.update() # QUEDA DE BOLAS
list_of_snow = []
screen.tracer(0)
for _ in range(50):
snow_fall()
text_1 = turtle.Turtle()
text_1.hideturtle()
text_1.penup()
text_1.setposition(0, width / 2.7)
text_1.color("red")
text_1.write("Feliz Natal!",
font=("Apple Chancery", max(int(30 / i_scale), 15), "bold"),
align="center")
for _ in range(25):
snow_fall()
if web_based:
for _ in range(200):
snow_fall()
else:
while True:
snow_fall()
turtle.done()

imagem1.png


# Bonecos de Nevel: Link para a página original


import time
import turtle
import random
width = height = 500

window = turtle.Screen()
window.setup(width, height)
window.bgcolor("sky blue")
window.title("Feliz Natal") snowball_rate = 1, 3
snowball_size = 5, 15
wind_change = 1, 5
max_wind = 3

def make_circle(turtle_name, x, y, size, colour):
turtle_name.color(colour)
turtle_name.penup()
turtle_name.setposition(x, y)
turtle_name.dot(size) # Fazer Bolas de Neve
list_of_snowballs = []
def make_snowball():
snowball = turtle.Turtle()
snowball.color("white")
snowball.penup()
snowball.setposition(random.randint(-2 * width, width / 2), height / 2)
snowball.hideturtle()
snowball.size = random.randint(*snowball_size)
list_of_snowballs.append(snowball)
def move_snowball(turtle_name, falling_speed=1, wind=0):
turtle_name.clear()
turtle_name.sety(turtle_name.ycor() - falling_speed)
if wind:
turtle_name.setx(turtle_name.xcor() + wind)
turtle_name.dot(turtle_name.size)
# Snowman: body
snowman = turtle.Turtle()
x_position = 0
y_positions = 75, 0, -100
size = 75
for y in y_positions:
make_circle(snowman, x_position, y, size, "white")
size = size * 1.5

# Snowman: buttons
button_seperation = 25
button_y_positions = [y_positions[1] - button_seperation,
y_positions[1],
y_positions[1] + button_seperation]
for y in button_y_positions:
make_circle(snowman, x_position, y, 10, "black") # Snowman: eyes
y_offset = 10
x_seperation = 15
for x in x_position - x_seperation, x_position + x_seperation:
make_circle(snowman, x, y_positions[0] + y_offset, 20, "green")
make_circle(snowman, x, y_positions[0] + y_offset, 10, "black") # Snowman: nose
snowman.color("orange")
snowman.setposition(x_position - 10, y_positions[0] - y_offset)
snowman.shape("triangle")
snowman.setheading(200)
snowman.turtlesize(0.5, 2.5) window.tracer(0) # Ground
grass = turtle.Turtle()
grass.fillcolor("forest green")
grass.penup()
grass.setposition(-width / 2, -height / 2)
grass.begin_fill()
for _ in range(2):
grass.forward(width)
grass.left(90)
grass.forward(70)
grass.left(90)
grass.end_fill() ground = turtle.Turtle()
for x in range(int(-width / 2), int(width / 2), int(width / 200)):
make_circle(ground, x, -180, random.randint(5, 20), "white") text = turtle.Turtle()
text.color("red")
text.penup()
text.setposition(10, 170)
text.write("Um Santo Natal", font=("Apple Chancery", 30, "bold"), align="center")
text.setposition(130, 140)
text.hideturtle() time_delay = 0
start_time = time.time()
wind = 0
wind_delay = 5
wind_timer = time.time()
wind_step = 0.1
while True:
if time.time() - start_time > time_delay:
make_snowball()
start_time = time.time()
time_delay = random.randint(*snowball_rate) / 10

for snowball in list_of_snowballs:
move_snowball(snowball, wind=wind)
if snowball.ycor() < -height / 2:
snowball.clear()
list_of_snowballs.remove(snowball) if time.time() - wind_timer > wind_delay:
wind += wind_step
if wind >= max_wind:
wind_step = -wind_step
elif wind <= 0:
wind_step = abs(wind_step) wind_timer = time.time()
wind_delay = random.randint(*wind_change) / 10

window.update() turtle.done()

imagem2.png


 

0