赞
踩
本文适合大中小学生新手入门,相比黑框框会有趣一点
有五角星、螺旋、爱心、雪花、笑脸等...
Python的海龟画图是一种用编程的方式来绘制几何图形的方法。
它的灵感来源于1967年的Logo语言,其中有一个叫做“海龟”的小机器人,它可以在一张纸上移动和旋转,用它身上的笔画出各种图案。Python的海龟画图库就是用Python语言来模拟这个过程,你可以通过控制海龟的颜色、速度、方向、位置等属性,来创造出不同的效果。Python的海龟画图不仅可以让你学习编程的基本概念,还可以让你享受到绘画的乐趣,你可以用它来画出五角星、螺旋、彩虹、雪花等各种有趣的图形
- import turtle
- t = turtle.Turtle()
- t.color("red")
- t.fillcolor("yellow")
- t.begin_fill()
- for i in range(5):
- t.forward(100)
- t.right(144)
- t.end_fill()
- turtle.done()
- import turtle
- import random
- t = turtle.Turtle()
- t.speed(0)
- colors = ["red", "green", "blue", "yellow", "purple", "orange"]
- for i in range(100):
- t.color(random.choice(colors))
- t.forward(i * 2)
- t.right(60)
- turtle.done()
- import turtle
- t = turtle.Turtle()
- t.pensize(16)#设置画笔粗细
- t.speed(0)
- t.penup()
- t.goto(-200, -100)
- t.pendown()
- colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
- for i in range(7):
- t.color(colors[i])
- t.circle(100 + i * 20)
- t.penup()
- t.right(90)
- t.forward(20)
- t.left(90)
- t.pendown()
- turtle.done()
- import turtle
- t = turtle.Turtle()
- t.color("orange")
- t.fillcolor("yellow")
- t.begin_fill()
- for i in range(12):
- t.forward(100)
- t.left(150)
- t.end_fill()
- turtle.done()
- import turtle
- t = turtle.Turtle()
- t.speed(0)
- t.color("blue")
- def snowflake(length, level):
- if level == 0:
- t.forward(length)
- else:
- snowflake(length / 3, level - 1)
- t.left(60)
- snowflake(length / 3, level - 1)
- t.right(120)
- snowflake(length / 3, level - 1)
- t.left(60)
- snowflake(length / 3, level - 1)
- t.penup()
- t.goto(-100, 100)
- t.pendown()
- for i in range(3):
- snowflake(200, 4)
- t.right(120)
- turtle.done()
- import turtle
- t = turtle.Turtle()
- t.speed(0)
- t.color("black")
- t.penup()
- t.goto(-200, 200)
- t.pendown()
- for i in range(8):
- for j in range(8):
- if (i + j) % 2 == 0:
- t.fillcolor("white")
- else:
- t.fillcolor("black")
- t.begin_fill()
- for k in range(4):
- t.forward(50)
- t.right(90)
- t.end_fill()
- t.forward(50)
- t.backward(400)
- t.right(90)
- t.forward(50)
- t.left(90)
- turtle.done()
- import turtle
- t = turtle.Turtle()
- t.speed(0)
- t.color("red")
- t.fillcolor("pink")
- t.begin_fill()
- t.left(140)
- t.forward(180)
- t.circle(-90, 200)
- t.setheading(60)
- t.circle(-90, 200)
- t.forward(180)
- t.end_fill()
- turtle.done()
- import turtle
- t = turtle.Turtle()
- t.speed(0)
- t.color("black")
- t.fillcolor("yellow")
- t.begin_fill()
- t.circle(100)
- t.end_fill()
- t.penup()
- t.goto(-30, 120)
- t.pendown()
- t.fillcolor("black")
- t.begin_fill()
- t.circle(10)
- t.end_fill()
- t.penup()
- t.goto(30, 120)
- t.pendown()
- t.begin_fill()
- t.circle(10)
- t.end_fill()
- t.penup()
- t.goto(-30,100)
- t.pendown()
- t.right(90)
- t.circle(30, 180)
- t.hideturtle()
- turtle.done()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。