Python Turtle有趣的作品

Python Turtle有趣的作品


笑脸

emotions.py

import turtle


def draw_circle(x_position, y_position, t_radius, t_angle, t_color):
	turtle.up()
	turtle.setpos(x_position,y_position)
	turtle.down()
	turtle.begin_fill()
	turtle.circle(t_radius,t_angle)
	turtle.color(t_color)
	turtle.end_fill()


turtle.shape('turtle')
#画脸
turtle.left(90)
draw_circle(200,0,200,360,'yellow')

#画眼睛
draw_circle(-20,100,30,360,'black')
draw_circle(80,100,30,360,'black')

#画眼睛
draw_circle(-20,100,30,180,'white')
turtle.lt(180)
draw_circle(80,100,30,180,'white')
turtle.lt(180)

#画脸颊
draw_circle(-80,-20,50,360,'pink')
draw_circle(180,-20,50,360,'pink')

#画嘴
turtle.seth(-120)

turtle.up()
turtle.pencolor('black')
turtle.setpos(80,-90)
turtle.down()
turtle.circle(-90,120)

turtle.hideturtle()
turtle.done()

抽象画

picture.py

import turtle
import random


pen = turtle.Turtle()
pen.shape('turtle')

paper = turtle.Screen()
# pen.speed(0)
paper.tracer(0)

x = -200
y = 200
size = 20

for b in range
  • 3
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
以下是一些Python Turtle的创意作品: 1. 绘制彩色螺旋线:使用Python Turtle绘制不同颜色的线条,创建一个漂亮的彩色螺旋图案。 ``` import turtle import random turtle.speed(0) turtle.bgcolor('black') colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'] for i in range(150): turtle.color(random.choice(colors)) turtle.pensize(i/10 + 1) turtle.forward(i) turtle.left(59) ``` 2. 绘制海龟赛跑游戏:使用Python Turtle创建一个简单的海龟赛跑游戏,让玩家控制一个小海龟,尽可能快地穿过障碍物。 ``` import turtle import random # Set up the screen screen = turtle.Screen() screen.setup(500, 500) screen.title("Turtle Race") # Create the turtles turtles = [] colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'] for i in range(6): turtle = turtle.Turtle() turtle.shape('turtle') turtle.color(colors[i]) turtle.penup() turtle.goto(-230, 200 - i*50) turtles.append(turtle) # Create the finish line finish = turtle.Turtle() finish.penup() finish.goto(230, 200) finish.pendown() finish.goto(230, -200) # Start the race while True: for turtle in turtles: turtle.forward(random.randint(1, 5)) if turtle.xcor() >= 230: winner = turtle.color()[0] print("The winner is", winner) turtle.goto(-100, 0) turtle.write("Winner!", font=("Arial", 16, "bold")) break ``` 3. 绘制谢尔宾斯基三角形:使用Python Turtle绘制一个谢尔宾斯基三角形,这是一个典型的分形图形。 ``` import turtle def draw_triangle(points, color, turtle): turtle.fillcolor(color) turtle.up() turtle.goto(points[0][0], points[0][1]) turtle.down() turtle.begin_fill() turtle.goto(points[1][0], points[1][1]) turtle.goto(points[2][0], points[2][1]) turtle.goto(points[0][0], points[0][1]) turtle.end_fill() def get_mid(p1, p2): return ((p1[0]+p2[0])/2, (p1[1]+p2[1])/2) def sierpinski(points, degree, turtle): colormap = ['blue', 'red', 'green', 'white', 'yellow', 'violet', 'orange'] draw_triangle(points, colormap[degree], turtle) if degree > 0: sierpinski([points[0], get_mid(points[0], points[1]), get_mid(points[0], points[2])], degree-1, turtle) sierpinski([points[1], get_mid(points[0], points[1]), get_mid(points[1], points[2])], degree-1, turtle) sierpinski([points[2], get_mid(points[2], points[1]), get_mid(points[0], points[2])], degree-1, turtle) turtle.setup(500, 500) turtle.title("Sierpinski Triangle") my_turtle = turtle.Turtle() my_turtle.speed(0) my_points = [[-200, -100], [0, 200], [200, -100]] sierpinski(my_points, 3, my_turtle) turtle.done() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dsmtyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值