黑客
登录
客服
网络安全
帖子详情

pycharm

pycharm如何作图啊,网上下载了一个樱花树代码,但是运行不了,还有我看到有些代码为什么要空格啊
288次浏览
2020/10/4 15:55:06发布
1个月前xf1234567890xf12345678906级
空格有的是缩进(tab)或者有的必须像for i in range这样的,运行不了是不是你复制错误或者是拓展库不存在?
1个月前黑客m黑客m9级
from turtle import Turtle, mainloop
class Designer(Turtle):
    def design(self, homePos, scale):
        self.up()
        a=5
        arr=["lightskyblue","cyan","orange","coral","palegreen"]
        for i in range(5):
            self.color(arr[i])
            if 0<i:
                print("  "*a,"❤"*(4*i-1))
                a=a-1
            self.forward(64.65 * scale)
            self.down()
            self.wheel(self.position(), scale)
            self.up()
            self.backward(64.65 * scale)
            self.right(72)
        self.up()
        self.goto(homePos)
        self.right(36)
        self.forward(24.5 * scale)
        self.right(198)
        self.down()
        self.centerpiece(46 * scale, 143.4, scale)
        self.getscreen().tracer(True)

    def wheel(self, initpos, scale):
        
       
1个月前黑客m黑客m9级
 self.right(54)
        for i in range(4):
            self.pentpiece(initpos, scale)
        self.down()
        self.left(36)
        for i in range(5):
            self.tripiece(initpos, scale)
        self.left(36)
        for i in range(5):
            self.down()
            self.right(72)
            self.forward(28 * scale)
            self.up()
            self.backward(28 * scale)
        self.left(54)
        self.getscreen().update()

    def tripiece(self, initpos, scale):
        oldh = self.heading()
        self.down()
        self.backward(2.5 * scale)
        self.tripolyr(31.5 * scale, scale)
        self.up()
        self.goto(initpos)
        self.setheading(oldh)
        self.down()
        self.backward(2.5 * scale)
        self.tripolyl(31.5 * scale, scale)
        self.up()
        self.goto(initpos)
        self.setheading(oldh)
        self.left(72)
        self.getscreen().update()

    def pentpiece(self, initpos, scale):
        oldh = self.heading()
        self.up()
        self.forward(29 * scale)
        self.down()
        for i in range(5):
            self.forward(18 * scale)
            self.right(72)
        self.pentr(18 * scale, 75, scale)
        self.up()
        self.goto(initpos)
        self.setheading(oldh)
        self.forward(29 * scale)
        self.down()
        for i in range(5):
            self.forward(18 * scale)
            self.right(72)
        self.pentl(18 * scale, 75, scale)
        self.up()
        self.goto(initpos)
        self.setheading(oldh)
        self.left(72)
        self.getscreen().update()

    def pentl(self, side, ang, scale):
        if side < (2 * scale): return
        self.forward(side)
        self.left(ang)
        self.pentl(side - (.38 * scale), ang, scale)

    def pentr(self, side, ang, scale):
        if side < (2 * scale): return
        self.forward(side)
        self.right(ang)
        self.pentr(side - (.38 * scale), ang, scale)

    def tripolyr(self, side, scale):
        if side < (4 * scale): return
        self.forward(side)
        self.right(111)
        self.forward(side / 1.78)
        self.right(111)
        self.forward(side / 1.3)
        self.right(146)
        self.tripolyr(side * .75, scale)

    def tripolyl(self, side, scale):
        if side < (4 * scale): return
        self.forward(side)
        self.left(111)
        self.forward(side / 1.78)
        self.left(111)
        self.forward(side / 1.3)
        self.left(146)
        self.tripolyl(side * .75, scale)

    def centerpiece(self, s, a, scale):
        self.color("lightpink")
        self.forward(s); self.left(a)
        if s < (7.5 * scale):
            return
        self.centerpiece(s - (1.2 * scale), a, scale)

def main():
    t = Designer()
    t.hideturtle()
    t.getscreen().delay(0)
    t.getscreen().tracer(150)
    t.design(t.position(), 2)

if __name__ == ''__main__'':
    msg = main()
    mainloop()
1个月前黑客m黑客m9级
试试这个,我试过没问题
1个月前黑客m黑客m9级
还有这个

from turtle import *
from random import *
from math import *
import time
print("hello hello hello,大家好~")
time.sleep(1)
print("有以下场景,请您观赏")
time.sleep(1)
print("1:春 2:夏 3:秋 4:冬 ")
time.sleep(1.5)
print("----------------")
bg=input("您选择的数字是:")
while bg!="1" and  bg!="2" and  bg!="3" and  bg!="4":
    bg=input("输入有误,请输入正确内容(1~4):")
if bg=="1":
    color1=["tan","mediumseagreen"]
elif bg=="2":
    color1=["burlywood","lightpink"]
elif bg=="3":
    color1=["darkgoldenrod","gold"]
else:
    color1=["olive","azure"]
def tree(n, l):
    pd() 
    color(color1[0])
    pensize(n / 3)
    forward(l)
    if n > 0:
        b = random() * 15 + 10 
        c = random() * 15 + 10 
        d = l * (random() * 0.25 + 0.7) 
        right(b)
        tree(n - 1, d)
        left(b + c)
        tree(n - 1, d)
        right(c)
    else:
        right(90)
        color(color1[1])
        circle(3)
        left(90)
        if(random() > 0.7):
            pu()
            t = heading()
            an = -40 + random()*40
            setheading(an)
            dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2)
            forward(dis)
            setheading(t)
            pd()
            right(90)
            color(color1[1])
            circle(2)
            left(90)
            pu()
            t = heading()
            setheading(an)
            backward(dis)
            setheading(t)
    pu()
    backward(l)
print("\n 小饼干❥(^_-) 🌲")
ht() 
getscreen().tracer(1000)
pu() 
backward(100)
left(90) 
pu() 
backward(300) 
tree(12, 100) 
done()
1个月前黑客m黑客m9级
还有网上的这个:
import turtle
 
# 设置初始位置
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
 
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10,180)
turtle.circle(25,110)
turtle.left(50)
turtle.circle(60,45)
turtle.circle(20,170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30,110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90,70)
turtle.circle(30,150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80,90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150,80)
turtle.left(50)
turtle.circle(150,90)
turtle.end_fill()
 
# 花瓣1
turtle.left(150)
turtle.circle(-90,70)
turtle.left(20)
turtle.circle(75,105)
turtle.setheading(60)
turtle.circle(80,98)
turtle.circle(-90,40)
 
# 花瓣2
turtle.left(180)
turtle.circle(90,40)
turtle.circle(-80,98)
turtle.setheading(-83)
 
# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80,90)
turtle.right(90)
turtle.circle(-80,90)
turtle.end_fill()
 
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
 
# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80,90)
turtle.left(90)
turtle.circle(80,90)
turtle.end_fill()
 
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200,60)
1个月前黑客m黑客m9级
画图的话,
https://blog.csdn.net/leechow007/article/details/74537123
1个月前13097302309130973023093级
我是直接在IDE运行,不知道啥原因
我来回答
pycharm

    取消

问答活动
最新帖子
推荐帖子

黑客技术 黑客软件 黑客教程 黑客书籍

关于我们 | 免责声明 | 学员守则 | 广告服务 | 联系我们

©2013-2020 xf1433.com 版权所有

本站资源仅供用于学习和交流,请遵循相关法律法规