python学习笔记:基本图形绘制

1.turtle库画蟒蛇

import turtle

turtle.setup(650,350,200,200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor('purple')
turtle.seth(-40)
for i in range(4):
    turtle.circle(40,80)
    turtle.circle(-40,80)
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40*2/3)
turtle.done()
                

2.turtle正方形绘制

import turtle as t

t.setup(600,600)
t.penup()
t.goto(-150,150)
t.pendown()
t.pensize(2)
t.pencolor(0,0,0)
for i in range(4):
    t.fd(300)
    t.right(90)
t.done()

3.turtle六边形绘制

import turtle as t
t.setup(600,600)
t.penup()
t.goto(-150,150)
t.pendown()
t.pensize(2)
t.pencolor(0,0,0)
for i in range(6):
    t.fd(300)
    t.right(60)
t.done()

4.turtle叠边形绘制

用turtle库,绘制一个叠边形,其中,叠边形内角为100度

import turtle as t
t.setup(600,600)
t.penup()
t.goto(0,50)
t.pendown()
t.pensize(2)
t.pencolor(0,0,0)
t.left(20)
t.fd(50)
t.right(80)
t.fd(50)
for i in range(8):
    t.left(40)
    t.fd(50)
    t.right(80)
    t.fd(50)
for i in range(9):
    t.fd(76.60444431515054)
    t.right(40)
t.done()

5.turtle风轮绘制

使用turtle库,绘制一个风轮效果,其中,每个风轮内角为45度,风轮边长150像素。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1Jj21te4-1584157401552)(attachment:image.png)]

import turtle as t
#设置画笔
t.setup(600,600)
t.pensize(2)
t.pencolor=(0,0,0)
t.penup()
t.goto(0,-150)
t.pendown()
#画曲线
for i in range(4):
    t.pendown()
    t.circle(150,45)
    t.penup()
    t.circle(150,45)
#画直线
t.pendown()
t.goto(0,150)
t.penup()
t.goto(150,0)
t.pendown()
t.goto(-150,0)
t.penup()
t.goto(-106.06601717798,106.06601717798)
t.pendown()
t.goto(106.06601717798,-106.06601717798)
t.penup()
t.goto(106.06601717798,106.06601717798)
t.pendown()
t.goto(-106.06601717798,-106.06601717798)
#结束作画
t.done()

6. turtle八边形绘制

import turtle as t
t.pensize(2)
for i in range(8):
    t.fd(100)
    t.left(45)
t.done()

7. turtle八角图形绘制

import turtle as t
t.pensize(2)
for i in range(8):
    t.fd(150)
    t.left(135)
t.done()
发布了51 篇原创文章 · 获赞 34 · 访问量 896

猜你喜欢

转载自blog.csdn.net/weixin_43412569/article/details/104857518