• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python可以画什么

python 搞java代码 3年前 (2022-05-21) 27次浏览 已收录 0个评论

python的turtle模块提供了绘制图像的功能,简单易懂,下面来介绍一下。

一、turtle其实就是一个画图板,给你提供了一个画笔。我们先设置一下基本的属性: 

1,运动属性 

forward(d) 向前移动距离d代表距离
backward(d) 向后移动距离d代表距离
right(degree) 向右转动多少度
left(degree) 向左转动多少度
goto(x,y) 将画笔移动到坐标为(x,y)的位置
stamp() 绘制当前图形
speed(speed) 画笔绘制的速度范围[0,10]整数

www#gaodaima.com来源gaodai#ma#com搞*!代#%^码网搞代码

搞代码网,大量的免费python学习资料,欢迎在线学习!

2,画笔属性 

down()画笔落下,移动时绘制图形
up()画笔抬起,移动时不绘制图形
reset()恢复所有设置
pensize(width)画笔的宽度
pencolor(colorstring)画笔的颜色
fillcolor(colorstring)绘制图形的填充颜色
fill(Ture)开始
fill(False)结束 
也<a href="https://www.gaodaima.com/tag/%e5%8f%af%e4%bb%a5" title="查看更多关于可以的文章" target="_blank">可以</a>color(‘color,’color’)
circle(radius, extent)

绘制一个圆形,其中radius为半径,extent为度数,例如若extent为180,则画一个半圆;如要画一个圆形,可不必写第二个参数

3,例子

下面一箭穿心的图像

from turtle import *
from time import sleep
def go_to(x, y):
   up()
   goto(x, y)
   down()
def big_Circle(size):  #函数用于绘制心的大圆
   speed(1)
   for i in range(150):
       forward(size)
       right(0.3)
def small_Circle(size):  #函数用于绘制心的小圆
   speed(1)
   for i in range(210):
       forward(size)
       right(0.786) 
def line(size):
   speed(1)
   forward(51*size)
def heart( x, y, size):
   go_to(x, y)
   left(150)
   begin_fill()
   line(size)
   big_Circle(size)
   small_Circle(size)
   left(120)
   small_Circle(size)
   big_Circle(size)
   line(size)
   end_fill()
def arrow():
   pensize(10)
   setheading(0)
   go_to(-400, 0)
   left(15)
   forward(150)
   go_to(339, 178)
   forward(150)
def arrowHead():
   pensize()
   speed(1)
   color('red', 'red')
   begin_fill()
   left(120)
   forward(20)
   right(150)
   forward(35)
   right(120)
   forward(35)
   right(150)
   forward(20)
   end_fill()
def main():
   pensize(2)
   color('red', 'pink')
   #getscreen().tracer(30, 0) #取消注释后,快速显示图案
   heart(200, 0, 1)          #画出第一颗心,前面两个参数控制心的位置,函数最后一个参数可控制心的大小
   setheading(0)             #使画笔的方向朝向x轴正方向
   heart(-80, -100, 1.5)     #画出第二颗心
   arrow()                   #画出穿过两颗心的直线
   arrowHead()               #画出箭的箭头
   go_to(400, -300)
   write("author:超哥", move=True, align="left", font=("宋体", 30, "normal"))
   done()
main()

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python可以画什么

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址