趣玩Python之Turtle模块绘图

1. 绘制奥运五环

import turtle
t = turtle.Pen()

t.width(8)

t.color('blue')
t.circle(50)

t.penup()
t.forward(130)
t.pendown()

t.color('black')
t.circle(50)

t.penup()
t.forward(130)
t.pendown()

t.color('red')
t.circle(50)

t.penup()
t.goto(66,-50)
t.pendown()

t.color('yellow')
t.circle(50)

t.penup()
t.forward(130)
t.pendown()

t.color('green')
t.circle(50)

在这里插入图片描述

2. 绘制五角星

import turtle
#设置画笔属性
turtle.pensize(10)
turtle.pencolor("red")
#设置起始位置
turtle.penup()
turtle.goto(-100,100)
turtle.pendown()

turtle.fd(400)

turtle.right(144)
turtle.fd(400)

turtle.right(144)
turtle.fd(400)

turtle.right(144)
turtle.fd(400)

turtle.right(144)
turtle.fd(400)

在这里插入图片描述

3. 绘制八卦太极图

import turtle
pen=turtle.Pen()
def walk_pen(x,y):
    pen.penup()
    pen.goto(x,y)
    pen.pendown()

#设置画布属性
turtle.screensize(400,300,'blue')

#设置画笔属性
pen.color('black','black')
pen.pensize(5)

#黑色部分
radius=200
pen.begin_fill()
pen.circle(radius / 2,180)#右上角的黑色半圆
pen.circle(radius,180)#左边黑色半圆
pen.left(180)
pen.circle(-radius / 2,180)#左下角与白色衔接的半圆轮廓
pen.end_fill()

#白色部分
pen.color('black','white')
walk_pen(0,0)
pen.begin_fill()
pen.circle(-radius / 2,-180)
pen.circle(-radius,-180)
pen.left(180)
pen.circle(radius / 2,-180)
pen.end_fill()

#小白圆
walk_pen(0,radius/3)

pen.begin_fill()
pen.circle(radius/6)
pen.end_fill()

pen.color('black','black')
#小黑圆
walk_pen(0,-2*radius/3)

pen.begin_fill()
pen.circle(radius/6)
pen.end_fill()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值