设为首页 加入收藏

TOP

Python turtle绘制阴阳太极图代码解析
2019-03-29 12:08:25 】 浏览:613
Tags:Python turtle 绘制 阴阳 太极图 代码 解析

代码
导入turtle库
import turtle


创建画布
window = turtle.Screen
......
window.exitonclick()


创建画笔
bage = turtle.Turtle()


设置画笔颜色
bage.color("black", "black")


设置画笔的宽度
bage.width(3)


准备开始填充图形
bage.begin_fill()


画一个半径为radius/2,弧度为180的半圆,画红线所示半圆
radius = 100
bage.circle(radius/2, 180)


画黄线所示的圆,半径radius,弧度180半圆
bage.circle(radius, 180)


将画笔方向旋转180度
bage.left(180)


画绿线所示半圆,画一个半径为radius/2,弧度180半圆,此时半径值为负
bage.cirle(-radius/2, 180)


结束填充
bage.end_fill()


画笔向左旋转90度,正好指向画板上方
bage.left(90)


抬起画笔,在运动时不会留下痕迹
bage.up()


向前移动radius0.35,这样小圆边线距离大圆边线上下各radius0.35


bage.forward(radius*0.35)



隐藏画笔
bage.ht()



完整代码


import turtle


window = turtle.Screen()


bage = turtle.Turtle()


radius = 100
bage.width(3)
bage.color("black", "black")
bage.begin_fill()
bage.circle(radius/2, 180)
bage.circle(radius, 180)
bage.left(180)
bage.circle(-radius/2, 180)
bage.end_fill()


bage.left(90)
bage.up()
bage.forward(radius*0.35)
bage.right(90)
bage.down()
bage.color("white", "white")
bage.begin_fill()
bage.circle(radius*0.15)
bage.end_fill()


bage.left(90)
bage.up()
bage.backward(radius*0.7)
bage.down()
bage.left(90)
bage.color("black", "black")
bage.begin_fill()
bage.circle(radius*0.15)
bage.end_fill()


bage.right(90)
bage.up()
bage.backward(radius*0.65)
bage.right(90)
bage.down()
bage.circle(radius, 180)
bage.ht()
   
window.exitonclick()


效果图如下:


Python turtle绘制阴阳太极图代码解析


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇利用Python的turtle重复画六边形 下一篇用Python绘制个花朵代码示例

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目