Commit 5e9f6131 by BellCodeEditor

auto save

parent 7f158d9a
import turtle as t
t.speed(0)
#花柄
t.penup()
t.goto(0,-150)
t.pendown()
t.pensize(2)
t.setheading(90)
t.color('brown')
t.begin_fill()
for i in range(10):
t.left(45)
t.circle(80,60)
t.left(120)
t.circle(80,60)
t.end_fill()
#叶子
for i in range(2):
t.penup()
t.goto(0,10-50*i)
x=20+80*i
t.setheading(x)
t.pendown()
t.color('brown','green')
t.begin_fill()
t.circle(60,60)
t.left(120)
t.circle(60,60)
t.end_fill()
t.hideturtle()
t.done()
\ No newline at end of file
""" import turtle
请使用turtle模块画出五角星 pen = turtle.Pen()
""" pen.pencolor("blue")
for i in range(3):
pen.forward(200)
pen.left(120)
pen.hideturtle()
turtle.done()
\ No newline at end of file
import turtle as t
def hair(): # 画头发
t.penup()
t.goto(-50, 150)
t.pendown()
t.fillcolor('#a2774d')
t.begin_fill()
for j in range(10): # 重复执行10次
t.setheading(60 - (j * 36)) # 每次调整初始角度
t.circle(-50, 120) # 画120度的弧
t.end_fill()
def face(): # 画脸
t.penup()
t.goto(0, 100)
t.pendown()
t.fillcolor('#f2ae20')
t.begin_fill()
t.setheading(180)
t.circle(85)
t.end_fill()
#下巴
t.circle(85, 120)
t.fillcolor('white')
t.begin_fill()
t.circle(85, 120)
t.setheading(135)
t.circle(100, 95)
t.end_fill()
def ears(dir): # 画眼睛,dir用来设置方向,左右眼对称
t.penup()
t.goto((0-dir)*30, 90)
t.setheading(90)
t.pendown()
t.fillcolor('#f2ae20')
t.begin_fill()
t.circle(dir*30)
t.end_fill()
t.penup()
t.goto((0-dir)*40, 85)
t.setheading(90)
t.pendown()
t.fillcolor('white')
t.begin_fill()
t.circle(dir*17)
t.end_fill()
def nose(): # 画鼻子
t.penup()
t.goto(20, 0)
t.setheading(90)
t.pendown()
t.fillcolor('#a2774d')
t.begin_fill()
t.circle(20)
t.end_fill()
def eye(dir): # 画耳朵,dir用来设置方向,左右耳对称
t.penup()
t.goto((0-dir)*30, 20)
t.setheading(0)
t.pendown()
t.fillcolor('black')
t.begin_fill()
t.circle(10)
t.end_fill()
def mouth(): # 画嘴巴
t.penup()
t.goto(0, 0)
t.setheading(-90)
t.pendown()
t.forward(50)
t.setheading(0)
t.circle(80, 30)
t.penup()
t.goto(0, -50)
t.setheading(180)
t.pendown()
t.circle(-80, 30)
hair()
ears(1)
ears(-1)
face()
eye(1)
eye(-1)
mouth()
nose()
t.hideturtle()
t.done()
\ No newline at end of file
# -*- coding:utf-8 -*-
import turtle as t
import time
def main():
t.pensize(4)
t.hideturtle()
t.colormode(255)
t.color((255, 155, 192), "pink")
t.setup(840, 500)
t.speed(10)
# 鼻子
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
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) # 向左转3度
t.fd(a) # 向前走a的步长
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
t.pu()
t.seth(90)
t.fd(25)
t.seth(0)
t.fd(10)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
t.pu()
t.seth(0)
t.fd(20)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
# 头
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(41)
t.seth(0)
t.fd(0)
t.pd()
t.begin_fill()
t.seth(180)
t.circle(300, -30)
t.circle(100, -60)
t.circle(80, -100)
t.circle(150, -20)
t.circle(60, -95)
t.seth(161)
t.circle(-300, 15)
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
a = 0.4
for i in range(60):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # 向左转3度
t.fd(a) # 向前走a的步长
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill()
# 耳朵
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(-7)
t.seth(0)
t.fd(70)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 54)
t.end_fill()
t.pu()
t.seth(90)
t.fd(-12)
t.seth(0)
t.fd(30)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 56)
t.end_fill()
# 眼睛
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-95)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-25)
t.seth(0)
t.fd(40)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
# 腮
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-95)
t.seth(0)
t.fd(65)
t.pd()
t.begin_fill()
t.circle(30)
t.end_fill()
# 嘴
t.color(239, 69, 19)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(-100)
t.pd()
t.seth(-80)
t.circle(30, 40)
t.circle(40, 80)
# 身体
t.color("red", (255, 99, 71))
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-78)
t.pd()
t.begin_fill()
t.seth(-130)
t.circle(100, 10)
t.circle(300, 30)
t.seth(0)
t.fd(230)
t.seth(90)
t.circle(300, 30)
t.circle(100, 3)
t.color((255, 155, 192), (255, 100, 100))
t.seth(-135)
t.circle(-80, 63)
t.circle(-150, 24)
t.end_fill()
# 手
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()
t.seth(-160)
t.circle(300, 15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20, 90)
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300, 15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20, 90)
# 脚
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(-75)
t.seth(0)
t.fd(-180)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(40)
t.seth(0)
t.fd(90)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
# 尾巴
t.pensize(4)
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(70)
t.seth(0)
t.fd(95)
t.pd()
t.seth(0)
t.circle(70, 20)
t.circle(10, 330)
if __name__ == '__main__':
# 画小猪佩奇
main()
time.sleep(10)
\ No newline at end of file
from turtle import *
from random import *
def ground():
hideturtle()
speed(100)
for i in range(400):
pensize(randint(5,10))
x=randint(-400,350)
y=randint(-280,-1)
r=-y/280
g=-y/280
b=-y/280
pencolor(r,g,b)
penup()
goto(x,y)
pendown()
forward(randint(40,100))
def snow():
hideturtle()
speed(100)
pensize(2)
for i in range(100):
r=random()
g=random()
b=random()
pencolor(r,g,b)
penup()
setx(randint(-350,350))
sety(randint(1,270))
pendown()
dens=randint(8,12)
snowsize=randint(10,14)
for j in range(dens):
forward(snowsize)
backward(snowsize)
right(360/dens)
def main():
setup(800, 600, 0, 0)
tracer(False)
bgcolor("black")
snow()
ground()
tracer(True)
mainloop()
main()
\ No newline at end of file
from turtle import *
from random import *
from math import *
def tree(n,l):
pd()#下笔
#阴影效果
t = cos(radians(heading()+45))/8+0.25
pencolor(t,t,t)
pensize(n/3)
forward(l)#画树枝
if n>0:
b = random()*15+10 #右分支偏转角度
c = random()*15+10 #左分支偏转角度
d = l*(random()*0.25+0.7) #下一个分支的长度
#右转一定角度,画右分支
right(b)
tree(n-1,d)
#左转一定角度,画左分支
left(b+c)
tree(n-1,d)
#转回来
right(c)
else:
#画叶子
right(90)
n=cos(radians(heading()-45))/4+0.5
pencolor(n,n*0.8,n*0.8)
circle(3)
left(90)
#添加0.3倍的飘落叶子
if(random()>0.7):
pu()
#飘落
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)
#画叶子
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)
left(90)
pu()
#返回
t=heading()
setheading(an)
backward(dis)
setheading(t)
pu()
backward(l)#退回
bgcolor(0.5,0.5,0.5)#背景色
ht()#隐藏turtle
speed(0)#速度 1-10渐进,0 最快
tracer(0,0)
pu()#抬笔
backward(100)
left(90)#左转90度
pu()#抬笔
backward(300)#后退300
tree(12,100)#递归7层
done()
\ No newline at end of file
import turtle
import turtle
from random import randint 
def draw_star():
  # 补全画一颗星星的代码
  turtle.color('red')
  turtle.hideturtle()
  turtle.begin_fill()
  for i in range(5):
    turtle.forward(10)
    turtle.right(144)
  turtle.end_fill()
  
 
# 将 ??? 改成你想画的星星个数
for i in range(50):
  turtle.speed(0)
  turtle.penup()
  x = randint(-150, 150)
  y = randint(-100, 100)
  turtle.goto(x, y)
  turtle.pendown()
  draw_star()
 
turtle.penup()
turtle.goto(0, -130)
turtle.pendown()
turtle.write('一闪一闪亮晶晶',  font = ('SimHei', 12, 'bold'))
turtle.done()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment