栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python入门基础009—海龟画图

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python入门基础009—海龟画图

1.四个连环的圆

import turtle as t
t.speed(0)#调节速度,0是最快的
t.color('blue')
t.pensize(9)#调节字符粗细
for i in range(0,20):
    t.right(91)
    t.circle(100)
t.done()

2.奥运五环

import turtle
turtle.width(10)#指定画笔的粗细
turtle.speed(10)#调剂速度
#第一个蓝色的圆
turtle.color("blue")
turtle.circle(50)
#第二个黑色的圆
turtle.penup()#抬笔
turtle.goto(120,0)#圆与圆的距离为20
turtle.pendown()#落笔
turtle.color("black")
turtle.circle(50)

turtle.penup()
turtle.goto(240,0)
turtle.pendown()
turtle.color("red")
turtle.circle(50)

turtle.penup()
turtle.goto(60,-50)
turtle.pendown()
turtle.color("green")
turtle.circle(50)

turtle.penup()
turtle.goto(180,-50)
turtle.pendown()
turtle.color("yellow")
turtle.circle(50)

turtle.done()

 

3.美国队长

#1.画一个红色的圆圈
import turtle as t
t.color('white')
t.speed(0)
t.penup()
t.goto(0,-200)
t.pendown()

t.begin_fill()#填充一个红色圆
t.circle(200)
t.color('red')
t.end_fill()

#填充白色在一个环里面
t.penup()
t.goto(0,-150)
t.pendown()
t.begin_fill()
t.circle(150)
t.color('white')
t.end_fill()

#填充蓝色的环
t.penup()
t.goto(0,-100)
t.pendown()
t.begin_fill()
t.circle(100)
t.color('blue')
t.end_fill()
#画五角星
t.penup()
t.color('white')
t.goto(-70,10)
t.pendown()
t.begin_fill()
for i in range(5):
    t.forward(140)#向前走140米
    t.right(144)
t.end_fill()
t.hideturtle()#隐藏箭头
t.done()

 

4. 气球

import turtle as t
import random #随机数
t.colormode(255)
t.speed(0)
for i in range(20):
    red=random.randint(0,255)#0--255的颜色随机选
    green=random.randint(0,255)
    blue=random.randint(0,255)

    x=random.randint(-400,220)#坐标随机
    y=random.randint(-400,220)#坐标随机

    t.penup()
    t.goto(x,y)
    t.pendown()


    t.begin_fill()
    t.circle(50)
    t.color(red,green,blue)#三种随机颜色
    t.end_fill()
    t.right(90)
    t.forward(90)
    t.left(90)
t.done()

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/744197.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号