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

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

解决方案goocz2025-03-14 15:44:1640A+A-

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 t

def 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()

运行效果

点击这里复制本文地址 以上内容由goocz整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

果子教程网 © All Rights Reserved.  蜀ICP备2024111239号-5