三角圆图

三角圆图

李兴球Python三角圆图

李兴球Python三角圆图

李兴球Python三角圆图


以下是画这个图形的部分源代码:

"""
   三角圆图.py
"""
import turtle

def draw_circle(pos,radius):
    """以pos为中心点为半径为radius的圆"""    
     pass
    
turtle.speed(0)
turtle.delay(0)
turtle.penup()
turtle.pensize(2)
# 画一个三角形,获取它们的顶点坐标
turtle.begin_poly() 
turtle.fd(200)
turtle.lt(120)
turtle.fd(200)
turtle.lt(120)
turtle.fd(200)
turtle.lt(120)
turtle.end_poly()
p = list(turtle.get_poly())                # 转换成列表
p.pop()
# 求出三角形中心点坐标,以这个为圆心画圆
centerx = (p[0][0] + p[1][0] + p[2][0])/3
centery = (p[0][1] + p[1][1] + p[2][1])/3
center = centerx,centery

s = turtle.getscreen()
s.onclick(inside)
for radius in range(4,120,10):           # 画一些圆,超出三角范围则不画
    draw_circle(center,radius)
turtle.ht()
turtle.done()

需要全部源代码,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客