Pythonでクリスマスツリー、桜の木、漫画の絵柄を描き、exeファイルにパッケージングする。
2022-02-13 17:16:03
記事目次
Pythonでクリスマスツリー、桜の木、漫画の絵柄を描き、exeファイルにパッケージする。
どのようにデスクトップ上で直接実行するexeファイルにpythonのコードを生成するには、記事を参照してください。 pythonファイルをexe形式にパッケージする方法
効果
1. クリスマスツリー・プレイン
import turtle
# Define the green leaf function of a Christmas tree
def tree(d, s):
if d <= 0:
return
turtle.forward(s)
tree(d - 1, s * .8)
turtle.right(120)
tree(d - 3, s * .5)
turtle.right(120)
tree(d - 3, s * .5)
turtle.right(120)
turtle.backward(s)
n = 100
turtle.speed('fastest') # set speed
turtle.left(90)
turtle.forward(3 * n)
turtle.color("orange", "yellow")
turtle.left(126)
# turtle.begin_fill()
for i in range(5):
turtle.forward(n / 5)
turtle.right(144)
turtle.forward(n / 5)
turtle.left(72)
turtle.end_fill()
turtle.right(126)
turtle.color("dark green")
turtle.backward(n * 4.8)
# Execute the function
tree(15, n)
turtle.backward(n / 5)
from turtle import *
import time
setup(500, 500, startx=None, starty=None)
speed(0)
pencolor("pink")
pensize(10)
penup()
hideturtle()
goto(0, 150)
showturtle()
pendown()
shape(name="classic")
# 1
seth(-120)
for i in range(10):
fd(12)
right(2)
penup()
goto(0, 150)
seth(-60)
pendown()
for i in range(10):
fd(12)
left(2)
seth(-150)
penup()
fd(10)
pendown()
for i in range(5):
fd(10)
right(15)
seth(-150)
penup()
fd(8)
pendown()
for i in range(5):
fd(10)
right(15)
seth(-155)
penup()
fd(5)
pendown()
for i in range(5):
fd(7)
right(15)
# 2
penup()
goto(-55, 34)
pendown()
seth(-120)
for i in range(10):
fd(8)
right(5)
penup()
goto(50, 35)
seth(-60)
pendown()
for i in range(10):
fd(8)
left(5)
seth(-120)
penup()
fd(10)
seth(-145)
pendown()
for i in range(5):
fd(10)
right(15)
penup()
fd(10)
seth(-145)
pendown()
for i in range(5):
fd(12)
right(15)
penup()
fd(8)
seth(-145)
pendown()
for i in range(5):
fd(10)
right(15)
penup()
seth(-155)
fd(8)
pendown()
for i in range(5):
fd(11)
right(15)
# 3
penup()
goto(-100, -40)
seth(-120)
pendown()
for i in range(10):
fd(6)
right(3)
penup()
goto(80, -39)
seth(-50)
pendown()
for i in range(10):
fd(6)
left(3)
seth(-155)
penup()
fd(10)
pendown()
for i in range(5):
fd(8)
right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
fd(8)
right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
fd(7)
right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
fd(7)
right(10)
penup()
fd(8)
seth(-140)
pendown()
for i in range(7):
fd(6)
right(10)
# 4
penup()
goto(-120, -95)
seth(-130)
pendown()
for i in range(7):
fd(10)
right(5)
penup()
goto(100, -95)
seth(-50)
pendown()
for i in range(7):
fd(10)
left(5)
penup()
seth(-120)
fd(10)
seth(-155)
pendown()
for i in range(6):
fd(8)
right(10)
penup()
seth(-160)
fd(10)
seth(-155)
pendown()
for i in range(6):
fd(8)
right(10)
penup()
seth(-160)
fd(10)
seth(-155)
pendown()
for i in range(6):
fd(8)
fd(10)
seth(-165)
pendown()
for i in range(5):
fd(10)
right(11)
# 5
penup()
goto(-70, -165)
seth(-85)
pendown()
for i in range(3):
fd(5)
left(3)
penup()
goto(70, -165)
seth(-95)
pendown()
for i in range(3):
fd(5)
right(3)
seth(-170)
penup()
fd(10)
pendown()
pendown()
for i in range(10):
fd(12)
right(2)
# 6
penup()
goto(70, -165)
pendown()
seth(-90)
pensize(8)
pencolor("#de8891")
circle(-20, 90)
penup()
goto(30, -185)
pendown()
seth(-180)
pensize(8)
pencolor("#de8891")
fd(40)
penup()
goto(-5, -170)
pendown()
seth(-180)
pensize(8)
pencolor("#de8891")
fd(35)
def guest(x, y, z):
penup()
goto(x, y)
seth(-z)
pendown()
for angel in range(5):
fd(10)
right(10)
def guet(x, y, z):
penup()
goto(x, y)
seth(-z)
pendown()
for angel in range(5):
fd(10)
left(10)
def qu(x, y, z):
penup()
goto(x, y)
seth(-z)
pendown()
for angel in range(5):
fd(6)
right(10)
seth(-150)
fd(20)
# branches
guest(-70, -150, 160)
guest(100, -150, 160)
guet(110, -110, 50)
guest(160, -140, 150)
qu(80, -120, 180)
guest(70, -85, 165)
guest(-40, -85, 165)
guet(90, -50, 50)
guest(130, -80, 150)
pencolor("pink")
qu(-40, -60, 180)
pencolor('#de8891')
qu(80, -30, 180)
pencolor("pink")
qu(40, 10, 180)
pencolor("#de8891")
guest(-60, 30, 120)
guest(-20, -20, 150)
guet(45, 40, 60)
guest(-30, 40, 170)
guest(-30, 110, 115)
guet(40, 90, 60)
guest(80, 50, 160)
pencolor("#de8891")
def hdj(x, y):
penup()
goto(x, y)
seth(80)
pendown()
pensize(2)
circle(5)
seth(10)
fd(15)
seth(120)
fd(20)
seth(240)
fd(20)
seth(180)
fd(20)
seth(-60)
fd(20)
seth(50)
fd(20)
seth(-40)
fd(30)
seth(-130)
fd(5)
seth(135)
fd(30)
seth(-60)
fd(30)
seth(-150)
fd(6)
seth(110)
fd(30)
def uit(x, y):
penup()
goto(x, y)
pendown()
pensize(2)
circle(5)
seth(-10)
fd(15)
seth(90)
fd(15)
seth(200)
fd(15)
seth(160)
fd(15)
seth(-90)
fd(15)
seth(10)
fd(15)
seth(-60)
fd(20)
seth(-180)
fd(5)
seth(110)
fd(20)
seth(-90)
fd(20)
seth(-180)
fd(6)
seth(70)
fd(15)
hideturtle()
def yut(x, y, z):
penup()
goto(x, y)
pendown()
seth(z)
for po in range(5):
fd(4)
left(36)
def ytu(x, y, z):
penup()
goto(x, y)
pendown()
seth(z)
for kk in range(5):
fd(4)
left(36)
# small bow
seth(0)
uit(40, -160)
hdj(-80, -120)
yut(-67, -115, 120)
yut(-86, -123, 150)
hdj(40, -50)
yut(52, -45, 130)
yut(34, -55, 160)
seth(0)
uit(-20, -60)
ytu(-4, -60, 100)
ytu(-20, -60, 120)
hdj(-30, 20)
yut(-15, 25, 130)
yut(-40, 20, 180)
uit(30, 70)
ytu(45, 70, 100)
ytu(30, 70, 120)
# Big bow
pencolor("#f799e6")
pensize(5)
penup()
seth(0)
goto(0, 150)
pendown()
circle(10)
seth(-15)
fd(40)
seth(90)
fd(40)
seth(200)
fd(40)
seth(160)
fd(40)
seth(-90)
fd(40)
seth(15)
fd(40)
seth(-70)
pencolor("#f799e6")
pensize(4)
fd(40)
seth(-180)
fd(10)
seth(100)
fd(40)
seth(-100)
fd(40)
seth(-180)
fd(10)
seth(70)
fd(40)
penup()
seth(0)
goto(0, 130)
pencolor("pink")
pendown()
def iou(x, y, z):
penup()
goto(x, y)
pencolor("#f799e6")
pendown()
seth(z)
for po in range(10):
fd(4)
left(18)
seth(0)
iou(35, 145, 100)
iou(-7, 145, 110)
pencolor("red")
pensize(7)
penup()
goto(-35, 135)
import turtle as t # as is to take an alias, subsequent calls to t are turtle
from turtle import *
import random as r
import time
n = 100.0
speed("fastest") # define speed
screensize(bg='black') # define the background color, you can change the color yourself
left(90)
forward(3 * n)
color("orange", "yellow") # Define the color of the topmost star, the outer circle is orange, the inner is yellow
begin_fill()
left(126)
for i in range(5): # Draw the pentagram
forward(n / 5)
right(144) # the angle of the pentagram
forward(n / 5)
left(72) # continue to change the angle
end_fill()
right(126)
def drawlight(): # Define the method for drawing colored lights
if r.randint(0, 30) == 0: # If you think there are too many lights, you can increase the range of values and there will be fewer lights
color('tomato') # Define the first color
circle(6) # Define the size of the lights
elif r.randint(0, 30) == 1:
color('orange') # Define the second color
circle(3) # Define the size of the colored light
else:
color('dark green') # Draw empty branches for the rest of the random number cases
color("dark green") # Define the color of the branch
backward(n * 4.8)
def tree(d, s): # Start drawing the tree
if d <= 0: return
forward(s)
tree(d - 1, s * .8)
right(120)
tree(d - 3, s * .5)
drawlight() # Also call the small colored light method
right(120)
tree(d - 3, s * .5)
right(120)
backward(s)
tree(15, n)
backward(n / 2)
for i in range(200): # Loop through the small decorations at the bottom
a = 200 - 400 * r.random()
b = 10 - 20 * r.random()
up()
forward(b)
left(90)
forward(a)
down()
if r.randint(0, 1) == 0:
color('tomato')
else:
color('wheat')
circle(2)
up()
backward(a)
right(90)
backward(b)
t.color("dark red", "red") # Define the font color
t.write("Merry Christmas ", align="center", font=("Comic Sans MS", 40, "bold")) # Define text, position, font, size
def drawsnow(): # Define the method for drawing snowflakes
t.ht() # hide the pen tip, ht=hideturtle
t.pensize(2) # Define pen size
for i in range(200): # how many snowflakes to draw
t.pencolor("white") # Define the brush color as white, which is actually the snowflake as white
t.pu() # lift the brush, pu=penup
t.setx(r.randint(-350, 350)) # define the x coordinate, randomly selected from -350 to 350
t.sety(r.randint(-100, 350)) # define the y coordinate, note that snowflakes generally don't fall on the ground, so they don't start with too small a vertical axis
t.pd() # drop strokes, pd = pendown
dens = 6 # the number of snowflake petals is set to 6
snowsize = r.randint(1, 10) # define snowflake size
for j in range(dens): # is 6, that is to draw 5 times, that is, a snowflake pentagram
# t.forward(int(snowsize)) # int() takes an integer
t.fd(int(snowsize))
t.backward(int(snowsize))
# t.bd(int(snowsize)) # notice there is no bd=backward, but there is fd=forward, small bug
t.right(int(360 / dens)) # turn angle
drawsnow() # call the method that draws snowflakes
t.done() # done, otherwise it would just close
from turtle import *
from random import *
from math import *
def tree(n,l):
pd()#downstroke
# shading effect
t = cos(radians(shading()+45))/8+0.25
pencolor(t,t,t)
pensize(n/3)
forward(l)#draw the branch
if n>0:
b = random()*15+10 #right branch deflection angle
c = random()*15+10 #left branch deflection angle
d = l*(random()*0.25+0.7) #the length of the next branch
# right angle, draw right branch
right(b)
tree(n-1,d)
#Turn left by a certain angle and draw the left branch
left(b+c)
tree(n-1,d)
#Turn back
right(c)
else:
#draw the leaves
right(90)
n=cos(radians(heading()-45))/4+0.5
pencolor(n,n*0.8,n*0.8)
circle(3)
left(90)
#Add 0.3 times the number of falling leaves
if(random()>0.7):
pu()
#drift down
t = heading()
an = -40 +random()*40
setheading(an)
dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2)
forward(dis)
setheading(t)
#draw the leaves
pd()
right(90)
n = cos(radians(heading()-45))/4+0.5
pencolor(n*0.5+0.5,0.4+n*0.4,0.4+n*0.4)
circle(2)
pu()# lift pen
backward(300)#backward300
tree(12,100)#recursive 7 levels
done()
import turtle
from random import random
from random import randint
def draw_petal(turtle_obj, flower):
# draw the petals that have fallen
for i in range(int(flower)):
# There is a positive and a negative to make the brush go in two directions
x = flower - 4 * flower * random()
# overall width of petals (-10, 10)
y = 10 - 20 * random()
# Lift the brush, y forward, 90 left, x away, drop the brush
turtle_obj.penup()
turtle_obj.forward(y)
turtle_obj.left(90)
turtle_obj.forward(x)
turtle_obj.pendown()
# Coral
turtle_obj.pencolor("lightcoral")
# Draw a circle
turtle_obj.circle(1)
# Go back to the start
# lift the pen, back x, turn right 90, back y, drop the pen
turtle_obj.penup()
turtle_obj.backward(x)
turtle_obj.right(90)
turtle_obj.backward(y)
turtle_obj.pendown()
# Draw the branches of the tree
def draw_tree(turtle_obj, branch, tree_color):
# Set a minimum branch length
min_branch = 4
if branch > min_branch:
if branch < 8:
# Branch to the left and right with probability 0.5
if randint(0, 1) == 0:
# Left is white
turtle_obj.pencolor("snow")
else:
# right is coral
turtle_obj.pencolor("lightcoral")
# branches
turtle_obj.pensize(branch / 2)
elif 8 <= branch <= 16:
# With probability 0.33, divide into left, middle and right branches
if randint(0, 2) == 0:
# Left is white
turtle_obj.pencolor("snow")
else:
# Middle and right are coral
turtle_obj.pencolor("lightcoral")
# tree branches
turtle_obj.pensize(branch / 4)
else:
# brown
turtle_obj.pencolor(tree_color)
# Fine branches
turtle_obj.pensize(branch / 10)
# The initial trunk length
turtle_obj.forward(branch)
# Random degree factor
a = 1.5 * random()
# rotate clockwise by a random angle (0 to 30 degrees)
turtle_obj.right(20 * a)
# Random length factor
b = 1.5 * random()
# Draw to the right until you can't draw any more
draw_tree(turtle_obj, branch - 10 * b, tree_color)
# turn left at a random angle
turtle_obj.left(40 * a)
# Draw to the left, until it does not move
draw_tree(turtle_obj, branch - 10 * b, tree_color)
# turn right by an angle
turtle_obj.right(20 * a)
# Lift the pen
turtle_obj.penup()
# end of recursion back to the start
turtle_obj.backward(branch)
turtle_obj.pendown()
def get_screen(width, height, color, speed):
# Create a screen
screen_obj = turtle.
# Screen size: (width, height), color: color
screen_obj.screensize(width, height, bg=color)
screen_obj.setup(1.0, 1.0)
# speed multiplier
screen_obj.tracer(speed)
return screen_obj
def trees(tree_num):
# color
color = ['brown', 'tan', 'black']
for j in range(tree_num):
# trunk color
tree_color = color[randint(0, len(color) - 1)]
# Brush size
pensize = randint(2, 5)
# Forward pixels
forward = ((-1) ** pensize) * pensize * randint(20, 50)
# backward pixels
if pensize <= 3:
backward = ((-1) ** pensize) * (5 - pensize) * randint(10, 15)
else:
backward = pensize * randint(45, 50)
# Create a brush
turtle_obj = turtle.
# The thickness of the brush
turtle_obj.pensize(pensize)
# Lift the brush, forward, turn 90 left, backward, drop the brush
turtle_obj.penup()
turtle_obj.forward(forward)
turtle_obj.left(90)
turtle_obj.backward(backward)
turtle_obj.pendown()
# Brush color: brown
turtle_obj.pencolor(tree_color)
# Branch thickness
branch = pensize * 15
# Number of flowers
flowers = branch
# * -- utf-8 -- *
# Author: Tang
import turtle as t
t.speed(10)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')
# Cat face
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # turn 3 degrees to the left
t.fd(a) # steps forward a
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # turn 3 degrees to the left
t.fd(a) # steps forward a
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
t.pu()
t.goto(-38, 190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
# Left beard
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80, 40)
t.circle(80, 80)
t.end_fill()
t.pu()
t.home()
t.goto(-80, 70)
t.pd()
t.forward(160)
t.pu()
t.home()
t.goto(-50, 50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
# Tie
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
# bells
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pensize(3)
t.right(115)
t.forward(7)
t.mainloop()
2. クリスマスツリー-かわいい
from turtle import *
import time
setup(500, 500, startx=None, starty=None)
speed(0)
pencolor("pink")
pensize(10)
penup()
hideturtle()
goto(0, 150)
showturtle()
pendown()
shape(name="classic")
# 1
seth(-120)
for i in range(10):
fd(12)
right(2)
penup()
goto(0, 150)
seth(-60)
pendown()
for i in range(10):
fd(12)
left(2)
seth(-150)
penup()
fd(10)
pendown()
for i in range(5):
fd(10)
right(15)
seth(-150)
penup()
fd(8)
pendown()
for i in range(5):
fd(10)
right(15)
seth(-155)
penup()
fd(5)
pendown()
for i in range(5):
fd(7)
right(15)
# 2
penup()
goto(-55, 34)
pendown()
seth(-120)
for i in range(10):
fd(8)
right(5)
penup()
goto(50, 35)
seth(-60)
pendown()
for i in range(10):
fd(8)
left(5)
seth(-120)
penup()
fd(10)
seth(-145)
pendown()
for i in range(5):
fd(10)
right(15)
penup()
fd(10)
seth(-145)
pendown()
for i in range(5):
fd(12)
right(15)
penup()
fd(8)
seth(-145)
pendown()
for i in range(5):
fd(10)
right(15)
penup()
seth(-155)
fd(8)
pendown()
for i in range(5):
fd(11)
right(15)
# 3
penup()
goto(-100, -40)
seth(-120)
pendown()
for i in range(10):
fd(6)
right(3)
penup()
goto(80, -39)
seth(-50)
pendown()
for i in range(10):
fd(6)
left(3)
seth(-155)
penup()
fd(10)
pendown()
for i in range(5):
fd(8)
right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
fd(8)
right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
fd(7)
right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
fd(7)
right(10)
penup()
fd(8)
seth(-140)
pendown()
for i in range(7):
fd(6)
right(10)
# 4
penup()
goto(-120, -95)
seth(-130)
pendown()
for i in range(7):
fd(10)
right(5)
penup()
goto(100, -95)
seth(-50)
pendown()
for i in range(7):
fd(10)
left(5)
penup()
seth(-120)
fd(10)
seth(-155)
pendown()
for i in range(6):
fd(8)
right(10)
penup()
seth(-160)
fd(10)
seth(-155)
pendown()
for i in range(6):
fd(8)
right(10)
penup()
seth(-160)
fd(10)
seth(-155)
pendown()
for i in range(6):
fd(8)
fd(10)
seth(-165)
pendown()
for i in range(5):
fd(10)
right(11)
# 5
penup()
goto(-70, -165)
seth(-85)
pendown()
for i in range(3):
fd(5)
left(3)
penup()
goto(70, -165)
seth(-95)
pendown()
for i in range(3):
fd(5)
right(3)
seth(-170)
penup()
fd(10)
pendown()
pendown()
for i in range(10):
fd(12)
right(2)
# 6
penup()
goto(70, -165)
pendown()
seth(-90)
pensize(8)
pencolor("#de8891")
circle(-20, 90)
penup()
goto(30, -185)
pendown()
seth(-180)
pensize(8)
pencolor("#de8891")
fd(40)
penup()
goto(-5, -170)
pendown()
seth(-180)
pensize(8)
pencolor("#de8891")
fd(35)
def guest(x, y, z):
penup()
goto(x, y)
seth(-z)
pendown()
for angel in range(5):
fd(10)
right(10)
def guet(x, y, z):
penup()
goto(x, y)
seth(-z)
pendown()
for angel in range(5):
fd(10)
left(10)
def qu(x, y, z):
penup()
goto(x, y)
seth(-z)
pendown()
for angel in range(5):
fd(6)
right(10)
seth(-150)
fd(20)
# branches
guest(-70, -150, 160)
guest(100, -150, 160)
guet(110, -110, 50)
guest(160, -140, 150)
qu(80, -120, 180)
guest(70, -85, 165)
guest(-40, -85, 165)
guet(90, -50, 50)
guest(130, -80, 150)
pencolor("pink")
qu(-40, -60, 180)
pencolor('#de8891')
qu(80, -30, 180)
pencolor("pink")
qu(40, 10, 180)
pencolor("#de8891")
guest(-60, 30, 120)
guest(-20, -20, 150)
guet(45, 40, 60)
guest(-30, 40, 170)
guest(-30, 110, 115)
guet(40, 90, 60)
guest(80, 50, 160)
pencolor("#de8891")
def hdj(x, y):
penup()
goto(x, y)
seth(80)
pendown()
pensize(2)
circle(5)
seth(10)
fd(15)
seth(120)
fd(20)
seth(240)
fd(20)
seth(180)
fd(20)
seth(-60)
fd(20)
seth(50)
fd(20)
seth(-40)
fd(30)
seth(-130)
fd(5)
seth(135)
fd(30)
seth(-60)
fd(30)
seth(-150)
fd(6)
seth(110)
fd(30)
def uit(x, y):
penup()
goto(x, y)
pendown()
pensize(2)
circle(5)
seth(-10)
fd(15)
seth(90)
fd(15)
seth(200)
fd(15)
seth(160)
fd(15)
seth(-90)
fd(15)
seth(10)
fd(15)
seth(-60)
fd(20)
seth(-180)
fd(5)
seth(110)
fd(20)
seth(-90)
fd(20)
seth(-180)
fd(6)
seth(70)
fd(15)
hideturtle()
def yut(x, y, z):
penup()
goto(x, y)
pendown()
seth(z)
for po in range(5):
fd(4)
left(36)
def ytu(x, y, z):
penup()
goto(x, y)
pendown()
seth(z)
for kk in range(5):
fd(4)
left(36)
# small bow
seth(0)
uit(40, -160)
hdj(-80, -120)
yut(-67, -115, 120)
yut(-86, -123, 150)
hdj(40, -50)
yut(52, -45, 130)
yut(34, -55, 160)
seth(0)
uit(-20, -60)
ytu(-4, -60, 100)
ytu(-20, -60, 120)
hdj(-30, 20)
yut(-15, 25, 130)
yut(-40, 20, 180)
uit(30, 70)
ytu(45, 70, 100)
ytu(30, 70, 120)
# Big bow
pencolor("#f799e6")
pensize(5)
penup()
seth(0)
goto(0, 150)
pendown()
circle(10)
seth(-15)
fd(40)
seth(90)
fd(40)
seth(200)
fd(40)
seth(160)
fd(40)
seth(-90)
fd(40)
seth(15)
fd(40)
seth(-70)
pencolor("#f799e6")
pensize(4)
fd(40)
seth(-180)
fd(10)
seth(100)
fd(40)
seth(-100)
fd(40)
seth(-180)
fd(10)
seth(70)
fd(40)
penup()
seth(0)
goto(0, 130)
pencolor("pink")
pendown()
def iou(x, y, z):
penup()
goto(x, y)
pencolor("#f799e6")
pendown()
seth(z)
for po in range(10):
fd(4)
left(18)
seth(0)
iou(35, 145, 100)
iou(-7, 145, 110)
pencolor("red")
pensize(7)
penup()
goto(-35, 135)
3. クリスマスツリー - 流れる雪
import turtle as t # as is to take an alias, subsequent calls to t are turtle
from turtle import *
import random as r
import time
n = 100.0
speed("fastest") # define speed
screensize(bg='black') # define the background color, you can change the color yourself
left(90)
forward(3 * n)
color("orange", "yellow") # Define the color of the topmost star, the outer circle is orange, the inner is yellow
begin_fill()
left(126)
for i in range(5): # Draw the pentagram
forward(n / 5)
right(144) # the angle of the pentagram
forward(n / 5)
left(72) # continue to change the angle
end_fill()
right(126)
def drawlight(): # Define the method for drawing colored lights
if r.randint(0, 30) == 0: # If you think there are too many lights, you can increase the range of values and there will be fewer lights
color('tomato') # Define the first color
circle(6) # Define the size of the lights
elif r.randint(0, 30) == 1:
color('orange') # Define the second color
circle(3) # Define the size of the colored light
else:
color('dark green') # Draw empty branches for the rest of the random number cases
color("dark green") # Define the color of the branch
backward(n * 4.8)
def tree(d, s): # Start drawing the tree
if d <= 0: return
forward(s)
tree(d - 1, s * .8)
right(120)
tree(d - 3, s * .5)
drawlight() # Also call the small colored light method
right(120)
tree(d - 3, s * .5)
right(120)
backward(s)
tree(15, n)
backward(n / 2)
for i in range(200): # Loop through the small decorations at the bottom
a = 200 - 400 * r.random()
b = 10 - 20 * r.random()
up()
forward(b)
left(90)
forward(a)
down()
if r.randint(0, 1) == 0:
color('tomato')
else:
color('wheat')
circle(2)
up()
backward(a)
right(90)
backward(b)
t.color("dark red", "red") # Define the font color
t.write("Merry Christmas ", align="center", font=("Comic Sans MS", 40, "bold")) # Define text, position, font, size
def drawsnow(): # Define the method for drawing snowflakes
t.ht() # hide the pen tip, ht=hideturtle
t.pensize(2) # Define pen size
for i in range(200): # how many snowflakes to draw
t.pencolor("white") # Define the brush color as white, which is actually the snowflake as white
t.pu() # lift the brush, pu=penup
t.setx(r.randint(-350, 350)) # define the x coordinate, randomly selected from -350 to 350
t.sety(r.randint(-100, 350)) # define the y coordinate, note that snowflakes generally don't fall on the ground, so they don't start with too small a vertical axis
t.pd() # drop strokes, pd = pendown
dens = 6 # the number of snowflake petals is set to 6
snowsize = r.randint(1, 10) # define snowflake size
for j in range(dens): # is 6, that is to draw 5 times, that is, a snowflake pentagram
# t.forward(int(snowsize)) # int() takes an integer
t.fd(int(snowsize))
t.backward(int(snowsize))
# t.bd(int(snowsize)) # notice there is no bd=backward, but there is fd=forward, small bug
t.right(int(360 / dens)) # turn angle
drawsnow() # call the method that draws snowflakes
t.done() # done, otherwise it would just close
4、桜の木 - フローティング・ダウン効果
from turtle import *
from random import *
from math import *
def tree(n,l):
pd()#downstroke
# shading effect
t = cos(radians(shading()+45))/8+0.25
pencolor(t,t,t)
pensize(n/3)
forward(l)#draw the branch
if n>0:
b = random()*15+10 #right branch deflection angle
c = random()*15+10 #left branch deflection angle
d = l*(random()*0.25+0.7) #the length of the next branch
# right angle, draw right branch
right(b)
tree(n-1,d)
#Turn left by a certain angle and draw the left branch
left(b+c)
tree(n-1,d)
#Turn back
right(c)
else:
#draw the leaves
right(90)
n=cos(radians(heading()-45))/4+0.5
pencolor(n,n*0.8,n*0.8)
circle(3)
left(90)
#Add 0.3 times the number of falling leaves
if(random()>0.7):
pu()
#drift down
t = heading()
an = -40 +random()*40
setheading(an)
dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2)
forward(dis)
setheading(t)
#draw the leaves
pd()
right(90)
n = cos(radians(heading()-45))/4+0.5
pencolor(n*0.5+0.5,0.4+n*0.4,0.4+n*0.4)
circle(2)
pu()# lift pen
backward(300)#backward300
tree(12,100)#recursive 7 levels
done()
5、桜の木 - 暖かい色合い
import turtle
from random import random
from random import randint
def draw_petal(turtle_obj, flower):
# draw the petals that have fallen
for i in range(int(flower)):
# There is a positive and a negative to make the brush go in two directions
x = flower - 4 * flower * random()
# overall width of petals (-10, 10)
y = 10 - 20 * random()
# Lift the brush, y forward, 90 left, x away, drop the brush
turtle_obj.penup()
turtle_obj.forward(y)
turtle_obj.left(90)
turtle_obj.forward(x)
turtle_obj.pendown()
# Coral
turtle_obj.pencolor("lightcoral")
# Draw a circle
turtle_obj.circle(1)
# Go back to the start
# lift the pen, back x, turn right 90, back y, drop the pen
turtle_obj.penup()
turtle_obj.backward(x)
turtle_obj.right(90)
turtle_obj.backward(y)
turtle_obj.pendown()
# Draw the branches of the tree
def draw_tree(turtle_obj, branch, tree_color):
# Set a minimum branch length
min_branch = 4
if branch > min_branch:
if branch < 8:
# Branch to the left and right with probability 0.5
if randint(0, 1) == 0:
# Left is white
turtle_obj.pencolor("snow")
else:
# right is coral
turtle_obj.pencolor("lightcoral")
# branches
turtle_obj.pensize(branch / 2)
elif 8 <= branch <= 16:
# With probability 0.33, divide into left, middle and right branches
if randint(0, 2) == 0:
# Left is white
turtle_obj.pencolor("snow")
else:
# Middle and right are coral
turtle_obj.pencolor("lightcoral")
# tree branches
turtle_obj.pensize(branch / 4)
else:
# brown
turtle_obj.pencolor(tree_color)
# Fine branches
turtle_obj.pensize(branch / 10)
# The initial trunk length
turtle_obj.forward(branch)
# Random degree factor
a = 1.5 * random()
# rotate clockwise by a random angle (0 to 30 degrees)
turtle_obj.right(20 * a)
# Random length factor
b = 1.5 * random()
# Draw to the right until you can't draw any more
draw_tree(turtle_obj, branch - 10 * b, tree_color)
# turn left at a random angle
turtle_obj.left(40 * a)
# Draw to the left, until it does not move
draw_tree(turtle_obj, branch - 10 * b, tree_color)
# turn right by an angle
turtle_obj.right(20 * a)
# Lift the pen
turtle_obj.penup()
# end of recursion back to the start
turtle_obj.backward(branch)
turtle_obj.pendown()
def get_screen(width, height, color, speed):
# Create a screen
screen_obj = turtle.
# Screen size: (width, height), color: color
screen_obj.screensize(width, height, bg=color)
screen_obj.setup(1.0, 1.0)
# speed multiplier
screen_obj.tracer(speed)
return screen_obj
def trees(tree_num):
# color
color = ['brown', 'tan', 'black']
for j in range(tree_num):
# trunk color
tree_color = color[randint(0, len(color) - 1)]
# Brush size
pensize = randint(2, 5)
# Forward pixels
forward = ((-1) ** pensize) * pensize * randint(20, 50)
# backward pixels
if pensize <= 3:
backward = ((-1) ** pensize) * (5 - pensize) * randint(10, 15)
else:
backward = pensize * randint(45, 50)
# Create a brush
turtle_obj = turtle.
# The thickness of the brush
turtle_obj.pensize(pensize)
# Lift the brush, forward, turn 90 left, backward, drop the brush
turtle_obj.penup()
turtle_obj.forward(forward)
turtle_obj.left(90)
turtle_obj.backward(backward)
turtle_obj.pendown()
# Brush color: brown
turtle_obj.pencolor(tree_color)
# Branch thickness
branch = pensize * 15
# Number of flowers
flowers = branch
6.ドラえもん
# * -- utf-8 -- *
# Author: Tang
import turtle as t
t.speed(10)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')
# Cat face
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # turn 3 degrees to the left
t.fd(a) # steps forward a
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # turn 3 degrees to the left
t.fd(a) # steps forward a
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
t.pu()
t.goto(-38, 190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
# Left beard
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80, 40)
t.circle(80, 80)
t.end_fill()
t.pu()
t.home()
t.goto(-80, 70)
t.pd()
t.forward(160)
t.pu()
t.home()
t.goto(-50, 50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
# Tie
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
# bells
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()
t.pensize(3)
t.right(115)
t.forward(7)
t.mainloop()
関連
-
[解決済み】Spyder Python "オブジェクト配列は現在サポートされていません"
-
[解決済み】Pygameのカウントダウンタイマー
-
[解決済み】 errno 32 壊れたパイプを防ぐには?
-
[解決済み】TypeError: 'encoding'はこの関数の無効なキーワード引数です。
-
[解決済み】LockとRLockの違いは何ですか?
-
[解決済み】DataFrame.locで「Too many indexers」。
-
[解決済み】2D numpy配列のしきい値
-
[解決済み] TypeError: 整数の引数を期待したが、画像をグレイスケールに変換するときに浮動小数点になった。
-
データフレームの基本
-
pipインストールエラーの解決 TypeError: -= でサポートされていないオペランドタイプ: 'Retry' および 'int'.
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
[解決済み】super()がエラーで失敗する。親がオブジェクトを継承していない場合、TypeError "argument 1 must be type, not classobj" が発生する。
-
[解決済み] ValueErrorです。複数の要素を持つ配列の真偽値は曖昧である。a.any()またはa.all()を使用する。
-
[解決済み] Python3 で ** や pow() でサポートされていないオペランド型: 'str' と 'int' [重複].
-
[解決済み] Youtubedl CERTIFICATE_VERIFY_FAILED [重複]する。
-
[解決済み] QSizePolicy.MinimumとQSizePolicy.Preferredはどう違うのですか?
-
[解決済み] matplotlibのインストールでパーミッション拒否のエラーが発生する
-
[解決済み] Kerasレイヤーの重みをリセットする
-
[解決済み] Pythonで文字列から数字を抽出する方法とは?
-
[解決済み] Flask がコンソールにプリントされない
-
pandasのdrop()で軸の値を簡単に記憶する方法