python三角网格划分示例
import numpy as np import turtle # 输入三角形的边长 length = float(input("Enter the length of the triangle: ")) # 计算最短边、最长边和三角形个数 short_side = length max_side = length + length n = int(max_side / short_side) + 1 # 初始化海龟画布 t = turtle.Turtle() t.speed(0) # 计算海龟移动的坐标 x = np.array([length * i for i in range(n)]) y = np.array([length * (i + 1) for i in range(n)]) # 绘制三角形 for i in range(n): t.penup() x[i] = x[i] + short_side y[i] = y[i] + short_side * 2 - length t.goto(x[i], y[i]) t.pendown() # 显示绘制结果 turtle.done()
#####################
标签:turtle,short,示例,python,网格,length,range,side From: https://www.cnblogs.com/herd/p/17349867.html