Turtle drawing module of interest in playing the Python

1. Draw the Olympic rings

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)

Here Insert Picture Description

2. Draw five-pointed star

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)

Here Insert Picture Description

3. Draw Tai Chi Bagua map

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()

Here Insert Picture Description

Published 139 original articles · won praise 55 · views 60000 +

Guess you like

Origin blog.csdn.net/Vickers_xiaowei/article/details/104165303