您当前的位置: 首页 >  Python

彭世瑜

暂无认证

  • 2浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

python编程:读取文件动态绘制图形-6_彭世瑜_新浪博客

彭世瑜 发布时间:2017-06-18 00:22:03 ,浏览量:2

python编程:读取文件动态绘制图形-6
源码:
  1. #根据数据文件在窗口中动态路径绘制
  2. import turtle 
  3.  
  4. def main():
  5.     #设置窗口信息
  6.     turtle.title('数据驱动的动态路径绘制')
  7.     turtle.setup(800, 600, 0, 0)
  8.     #设置画笔
  9.     pen = turtle.Turtle()
  10.     pen.color("red")
  11.     pen.width(5)
  12.     pen.shape("turtle")
  13.     pen.speed(5)
  14.     #读取文件
  15.     result=[]
  16.     file = open("data.txt","r")
  17.     for line in file:
  18.         result.append(list(map(float, line.split(','))))
  19.     print(result)
  20.     #动态绘制
  21.     for i in range(len(result)):
  22.         pen.color((result[i][3],result[i][4],result[i][5]))
  23.         pen.forward(result[i][0])
  24.         if result[i][1]:
  25.             pen.rt(result[i][2])
  26.         else:
  27.             pen.lt(result[i][2])
  28.     pen.goto(0,0)
  29.  
  30.  
  31. if __name__ == '__main__':
  32.     main()
data.txt文件,放在脚本同一路径下即可
300,0,144,1,0,0 300,0,144,0,1,0
300,0,144,0,0,1
300,0,144,1,1,0
300,0,108,0,1,1 184,0,72,1,0,1
184,0,72,0,0,0
184,0,72,0,0,0
184,0,72,0,0,0 184,1,72,1,0,1
184,1,72,0,0,0
184,1,72,0,0,0
184,1,72,0,0,0 184,1,72,0,0,0
184,1,720,0,0,0
原文地址: http://www.icourse163.org/learn/BIT-268001?tid=1002001005#/learn/content?type=detail&id=1002613035&cid=1002856098
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0588s