火热的Visual studio code 编译器配置python编译环境,绘制分形图

1 安装Visual studio code 和python IDE,这两个都是开源的,官 下载安装就好。Visual studio code 编译器挺火热,刚根据 上的教程,配置好了ESP32的编译环境,确实比Arduino的编译器方便。看到Visual studio code也可以配置python IDE,赶紧配置起来。

2 python的pip安装

pin install flake8

3 pip install yapf

4 VS Code 新建settings.json文件,并将右面的代码写到里面

最后一行代码,需要根据自己安装python的路径进行更新

5 写个python hello 语句,确认运行成功

6 用python turtle画一个分形图

程序

import turtle as tdef main():    t.color('red')
    t.hideturtle()
    t.speed(0)
    level=10
    fract(-80,60,80,60,level)
    t.done()def fract(x1,y1,x2,y2,level):
    newX=0
    newy=0
    if level==0:
        drawline(x1,y1,x2,y2)
    else:
        newX=(x1+x2)/2+(y2-y1)/2
        newY=(y1+y2)/2-(x2-x1)/2
        fract(x1,y1,newX,newY,level-1)
        fract(newX,newY,x2,y2,level-1)
def drawline(x1,y1,x2,y2):
    t.up()
    t.goto(x1,y1)
    t.down()
    t.goto(x2,y2)
main()

运行效果

声明:本站部分文章内容及图片转载于互联 、内容不代表本站观点,如有内容涉及侵权,请您立即联系本站处理,非常感谢!

(0)
上一篇 2022年6月2日
下一篇 2022年6月2日

相关推荐