首页 存档 技术 查看内容

Python画图

2018-3-30 13:00 |来自: 互联网 521 0

摘要: turtle是Python中内置的画图库,它语法十分简单、十分有趣 Tips:请确保Python版本为3而不是2 函数简介: turtle.pencolor(string)选择笔的颜色(颜色名) turtle.pensize(int)选择笔的大小(数字) turtle.fo ...

turtle是Python中内置的画图库,它语法十分简单、十分有趣


Tips:请确保Python版本为3而不是2


函数简介:

turtle.pencolor(string)选择笔的颜色(颜色名)

turtle.pensize(int)选择笔的大小(数字)

turtle.forward(int)向前移动(数字)

turtle.left(int)向左转(数字)

turtle.right(int)向右转(数字)

turtle.bgcolor(string)背景颜色(颜色名)

turtle.up()台笔

turtle.down()落笔(开始时默认为落笔)

(使用它们前需先使用

import turtle

语句导入turtle库)


(代码请勿随意传播,毕竟都是小编一字一字打出来的 :-D)


Hexagon.py

from turtle import *

from random import *

count = 6

count2 = 6

colors = ['blue','red','yellow','purple','pink','green','orange']

pensize(5)


while count != 0:

while count2 != 0:

pencolor(choice(colors))

forward(50)

right(60)

count2 = count2-1

right(60)

count2 = 6

count = count-1

效果:


drawTree.py

import turtle

def drawTree(length,level):

if level

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部