Code Python pin
Code Python pin
The Python code below will draw a Christmas tree with surrounding lights and snow effect. You can also
change the text in the form you like to send to friends and people on Christmas.
import turtle
import random
web_based = True
# web_based = False
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
screen = turtle.Screen()
if not web_based:
screen.setup(width, height)
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, y)
if not outline:
triangle.end_fill()
ball.hideturtle()
ball.penup()
ball.setposition(x, y)
ball.color(colour)
ball.dot(size)
The Christmas tree code in Python will use the Turtle library to draw, so you need to import Turtle.
If you still don’t know how to use Python, read on Series of articles about Python on AnonyViet for
background knowledge. Then you can easily execute the Merry Christmas python Code below:
With basic Python knowledge, you can draw a Christmas tree with an extremely simple For loop. Here is
the Full Code:
def draw_tree(height):
print("*", end="")
print()
draw_tree(5)
On the last line: draw_tree(5)change the number 5 to another number to change the height of the
Christmas tree in Python.
***
*****
*******
*********
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x, y)
turtle.pendown()
turtle.begin_fill()
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
turtle.setheading(0)
oogway.penup()
oogway.color(color)
oogway.fillcolor(color)
oogway.goto(x, y)
oogway.pendown()
oogway.begin_fill()
oogway.circle(radius)
oogway.end_fill()
BG_COLOR = "#0080ff"
oogway = Turtle()
oogway.speed(2)
screen = oogway.getscreen()
screen.bgcolor(BG_COLOR)
screen.title("Merry Christmas")
screen.setup(width=1.0, height=1.0)
y = -100
# create tree
width = 240
oogway.speed(10)
width = width - 10
height = 10
x = 0 - width/2
y = y + height
oogway.speed(1)
oogway.penup()
oogway.color('yellow')
oogway.goto(-20, y+10)
oogway.begin_fill()
oogway.pendown()
for i in range(5):
oogway.forward(40)
oogway.right(144)
oogway.end_fill()
tree_height = y + 40
# create moon in sky
oogway.speed(10)
number_of_stars = randint(20,30)
# print(number_of_stars)
for _ in range(0,number_of_stars):
x_star = randint(-(screen.window_width()//2),screen.window_width()//2)
size = randint(5,20)
oogway.penup()
oogway.color('white')
oogway.goto(x_star, y_star)
oogway.begin_fill()
oogway.pendown()
for i in range(5):
oogway.forward(size)
oogway.right(144)
oogway.end_fill()
oogway.speed(1)
oogway.penup()
oogway.color("white")
oogway.pendown()
oogway.hideturtle()
screen.mainloop()
This code will draw a snowman and have snowfall with arbitrary text. You can use the Python editor to
rename your name however you like. Let’s convert python to exe and send it to your crush, he will
surely love you.
import turtle
import random
import time
window = turtle.Screen()
window.setup(width, height)
window.bgcolor("sky blue")
window.title("Happy Holidays")
snowball_rate = 1, 3
snowball_size = 5, 15
wind_change = 1, 5
max_wind = 3
# Create all circle-shaped objects
turtle_name.color(colour)
turtle_name.penup()
turtle_name.setposition(x, y)
turtle_name.dot(size)
list_of_snowballs = []
def make_snowball():
snowball = turtle.Turtle()
snowball.color("white")
snowball.penup()
snowball.hideturtle()
snowball.size = random.randint(*snowball_size)
list_of_snowballs.append(snowball)
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:
# Snowman: buttons
button_seperation = 25
y_positions[1],
y_positions[1] + button_seperation]
for y in button_y_positions:
# Snowman: eyes
y_offset = 10
x_seperation = 15
# Snowman: nose
snowman.color("orange")
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()
text = turtle.Turtle()
text.color("red")
text.penup()
text.setposition(-100, 170)
#chữ thứ 1
text.setposition(130, 140)
text.color("dark green")
#chữ thứ 3
#chữ thứ 4
text.setx(50)
#chữ thứ 2
text.hideturtle()
time_delay = 0
start_time = time.time()
wind = 0
wind_delay = 5
wind_timer = time.time()
wind_step = 0.1
while True:
make_snowball()
start_time = time.time()
time_delay = random.randint(*snowball_rate) / 10
move_snowball(snowball, wind=wind)
snowball.clear()
list_of_snowballs.remove(snowball)
wind += wind_step
if wind >= max_wind:
wind_step = -wind_step
wind_step = abs(wind_step)
wind_timer = time.time()
wind_delay = random.randint(*wind_change) / 10
window.update()
turtle.done()
The Python code below will draw a Christmas tree with surrounding lights and snow effect. You can also
change the text in the form you like to send to friends and people on Christmas.
import turtle
import random
web_based = True
# web_based = False
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
screen = turtle.Screen()
if not web_based:
screen.setup(width, height)
# screen.tracer(0)
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, 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()
def snow_fall():
if rand_make_snow == 0:
snow = turtle.Turtle()
snow.hideturtle()
snow.penup()
list_of_snow.append(snow)
"white", snow)
move_snow(snow)
snow.clear()
list_of_snow.remove(snow)
del snow
screen.update()
triangle_1 = turtle.Turtle()
triangle_1.speed(draw_speed)
outline = True
outline = False
screen.tracer(0)
stem = turtle.Turtle()
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()
A Merry Christmas is coming, as a Coder you can design your own Noel in Python to increase your
friends or relatives. If you don’t have time, you can use the Codes collected below. Each Code Python
Noel has its own design but all have the common feature of having a Christmas tree with falling snow.
The Christmas tree code in Python will use the Turtle library to draw, so you need to import Turtle.
If you still don’t know how to use Python, read on Series of articles about Python on AnonyViet for
background knowledge. Then you can easily execute the Merry Christmas python Code below:
With basic Python knowledge, you can draw a Christmas tree with an extremely simple For loop. Here is
the Full Code:
def draw_tree(height):
print("*", end="")
draw_tree(5)
On the last line: draw_tree(5)change the number 5 to another number to change the height of the
Christmas tree in Python.
***
*****
*******
*********
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x, y)
turtle.pendown()
turtle.begin_fill()
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
turtle.setheading(0)
def create_circle(turtle, x, y, radius, color):
oogway.penup()
oogway.color(color)
oogway.fillcolor(color)
oogway.goto(x, y)
oogway.pendown()
oogway.begin_fill()
oogway.circle(radius)
oogway.end_fill()
BG_COLOR = "#0080ff"
oogway = Turtle()
oogway.speed(2)
screen = oogway.getscreen()
screen.bgcolor(BG_COLOR)
screen.title("Merry Christmas")
screen.setup(width=1.0, height=1.0)
y = -100
# create tree
width = 240
oogway.speed(10)
width = width - 10
height = 10
x = 0 - width/2
oogway.speed(1)
oogway.penup()
oogway.color('yellow')
oogway.goto(-20, y+10)
oogway.begin_fill()
oogway.pendown()
for i in range(5):
oogway.forward(40)
oogway.right(144)
oogway.end_fill()
tree_height = y + 40
oogway.speed(10)
number_of_stars = randint(20,30)
# print(number_of_stars)
for _ in range(0,number_of_stars):
x_star = randint(-(screen.window_width()//2),screen.window_width()//2)
size = randint(5,20)
oogway.penup()
oogway.color('white')
oogway.goto(x_star, y_star)
oogway.begin_fill()
oogway.pendown()
for i in range(5):
oogway.forward(size)
oogway.right(144)
oogway.end_fill()
oogway.speed(1)
oogway.penup()
oogway.color("white")
oogway.pendown()
oogway.hideturtle()
screen.mainloop()
This code will draw a snowman and have snowfall with arbitrary text. You can use the Python editor to
rename your name however you like. Let’s convert python to exe and send it to your crush, he will
surely love you.
import turtle
import random
import time
window = turtle.Screen()
window.setup(width, height)
window.bgcolor("sky blue")
window.title("Happy Holidays")
snowball_rate = 1, 3
snowball_size = 5, 15
wind_change = 1, 5
max_wind = 3
turtle_name.color(colour)
turtle_name.penup()
turtle_name.setposition(x, y)
turtle_name.dot(size)
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)
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
size = 75
for y in y_positions:
# 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:
# Snowman: eyes
y_offset = 10
x_seperation = 15
snowman.color("orange")
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()
text.color("red")
text.penup()
text.setposition(-100, 170)
#chữ thứ 1
text.setposition(130, 140)
text.color("dark green")
#chữ thứ 3
text.color("black")
#chữ thứ 4
text.setx(50)
#chữ thứ 2
text.hideturtle()
time_delay = 0
start_time = time.time()
wind = 0
wind_delay = 5
wind_timer = time.time()
wind_step = 0.1
while True:
make_snowball()
start_time = time.time()
time_delay = random.randint(*snowball_rate) / 10
move_snowball(snowball, wind=wind)
snowball.clear()
list_of_snowballs.remove(snowball)
if time.time() - wind_timer > wind_delay:
wind += wind_step
wind_step = -wind_step
wind_step = abs(wind_step)
wind_timer = time.time()
wind_delay = random.randint(*wind_change) / 10
window.update()
turtle.done()
Code Python pine node with snow
The Python code below will draw a Christmas tree with surrounding lights and snow effect. You can also
change the text in the form you like to send to friends and people on Christmas.
import turtle
import random
web_based = True
# web_based = False
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
if not web_based:
screen.setup(width, height)
# screen.tracer(0)
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, 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()
if rand_make_snow == 0:
snow = turtle.Turtle()
snow.hideturtle()
snow.penup()
list_of_snow.append(snow)
"white", snow)
snow.clear()
list_of_snow.remove(snow)
del snow
screen.update()
triangle_1 = turtle.Turtle()
triangle_1.speed(draw_speed)
outline = True
outline = False
screen.tracer(0)
stem = turtle.Turtle()
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()
# tree stem
stem.color("brown")
screen.tracer(1)
stem.pendown()
stem.begin_fill()
stem.setposition(width / 30, -width / 4.8)
stem.end_fill()
screen.bgcolor("sky blue")
# decorations: balls
screen.tracer(2)
random.choice(ball_colours),
turtle.Turtle())
screen.update()
# snow is falling…
list_of_snow = []
screen.tracer(0)
for _ in range(50):
snow_fall()
text_1 = turtle.Turtle()
text_1.hideturtle()
text_1.penup()
text_1.color("red")
text_1.write("Merry Christmas",
font=("Apple Chancery", max(int(30 / i_scale), 15), "bold"),
align="center")
for _ in range(25):
snow_fall()
text_1.color("black")
text_1.write("from",
align="center")
if web_based:
text_1.setposition(width / 6, -width / 2.14)
else:
text_1.color("forest green")
align="center")
# text_1.setposition(150, -280)
if web_based:
else:
align="center")
if web_based:
for _ in range(200):
snow_fall()
else:
while True:
snow_fall()
turtle.done()