Python turtle库绘制菱形的3种方式小结

yipeiwu_com6年前Python基础

绘制一个菱形四边形,边长为 200 像素。方法1和2绘制了内角为60和120度的菱形,方法3绘制了内角为90度的菱形。

方法1‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‮‬‫

import turtle as t
ls = [30,-30,-150,150]#菱形各边的画笔绝对角度列表
for i in range(4):
  t.seth(ls[i])  #画笔转向相应绝对角度
  t.forward(200)
t.done()

方法2

import turtle as t
t.right(-45)  #起始顶点绝对角度设为正30度
for i in range(4):  #画4边,转向4次
  t.fd(200)  
  degree = 60*(1+i%2)  #其他3顶点右转角度分别为60、120、60度
  t.right(degree)
t.done()

效果图如下:

方法3

import turtle as t
t.circle(200,steps=4)  #circle(r,steps)函数画半径为r圆的内切steps边形
 

效果图如下:

以上这篇Python turtle库绘制菱形的3种方式小结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python寻找list中最大值、最小值并返回其所在位置的方法

实例如下所示: c = [-10,-5,0,5,3,10,15,-20,25] print c.index(min(c)) # 返回最小值 print c.index(max(c)...

Ruby元编程基础学习笔记整理

笔记一: 代码中包含变量,类和方法,统称为语言构建(language construct)。 # test.rb class Greeting def initialize(te...

python字符串str和字节数组相互转化方法

实例如下: # bytes object b = b"example" # str object s = "example" # str to bytes bytes(...

Python3 入门教程 简单但比较不错

本文适合有Java编程经验的程序员快速熟悉Python 本文程序在windows xp+python3.1a1 测试通过. 本文提到的idle指python shell,即安装pytho...

Python制作CSDN免积分下载器

Python制作CSDN免积分下载器

CSDN免积分下载 你懂的。 1、输入资源地址如:http://download.csdn.net/download/gengqkun/4127808 2、输入验证码 3、点击下载,会...