使用python绘制城堡

使用python绘制城堡,第1张

import turtle as t
def triangle(a,b,c):
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor('purple')
    t.begin_fill()
    t.forward(c)
    t.left(120)
    t.forward(c)
    t.left(120)
    t.forward(c)
    t.left(120)
    t.end_fill()
def square(a,b,c,d):
    #a,b为坐标;c为底部宽,d为长
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("#cec2d6")
    t.begin_fill()
    t.forward(c)
    t.left(90)
    t.forward(d)
    t.left(90)
    t.forward(c)
    t.left(90)
    t.forward(d)
    t.left(90)
    t.end_fill()
def wall(a,b,c,d):
    #a,b为坐标;c为底部宽,d为长
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("#cec2d6")
    t.begin_fill()
    t.forward(c)
    t.left(90)
    t.forward(d)
    for i in range(0,4,1):
        t.left(90)
        t.forward(10)
        t.left(90)
        t.forward(10)
        t.right(90)
        t.forward(10)
        t.right(90)
        t.forward(10)
    t.left(90)
    t.forward(10)
    t.left(90)
    t.forward(d)
    t.left(90)
    t.end_fill()
def downwall(a,b,c,d):
        #a,b为坐标;c为底部宽,d为长
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("#cec2d6")
    t.begin_fill()
    t.forward(c)
    t.left(90)
    t.forward(d)
    for i in range(0,5,1):
        t.left(90)
        t.forward(10)
        t.left(90)
        t.forward(10)
        t.right(90)
        t.forward(10)
        t.right(90)
        t.forward(10)
    t.left(90)
    t.forward(10)
    t.left(90)
    t.forward(d)
    t.left(90)
    t.end_fill()
def floor(a,b):
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("purple")
    t.begin_fill()
    t.forward(50)
    t.left(90)
    t.forward(20)
    for i in range(0,2,1):
        t.left(90)
        t.forward(10)
        t.left(90)
        t.forward(10)
        t.right(90)
        t.forward(10)
        t.right(90)
        t.forward(10)
    t.left(90)
    t.forward(10)
    t.left(90)
    t.forward(20)
    t.left(90)
    t.end_fill()
def decoration(a,b):
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("black")
    t.begin_fill()
    t.forward(10)
    t.left(90)
    t.forward(10)
    t.circle(5,180)
    t.forward(10)
    t.end_fill()
    t.left(90)
def decoration1(a,b):
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("black")
    t.begin_fill()
    t.forward(8)
    t.left(90)
    t.forward(8)
    t.circle(4,180)
    t.forward(8)
    t.end_fill()
    t.left(90)
def door(a,b):
    t.penup()
    t.goto(a,b)
    t.pendown()
    t.fillcolor("black")
    t.begin_fill()
    t.forward(20)
    t.left(90)
    t.forward(20)
    t.circle(10,180)
    t.forward(20)
    t.end_fill()
    t.left(90)
t.pensize(3)
t.pencolor("black")
square(-30,90,20,40)
square(10,90,20,30)

wall(-45,0,90,100)
square(-85,-60,30,30)
square(55,-60,30,30)
square(-75,-20,30,50)
square(45,-20,30,50)
door(0,0)
downwall(-55,-60,110,70)
floor(-105,-30)
floor(55,-30)
triangle(-75,30,30)
triangle(45,30,30)
triangle(-30,130,20)
triangle(10,120,20)
decoration(10,70)
decoration(10,40)
decoration(-20,60)
decoration1(-64,10)
decoration1(60,10)
decoration1(-22.5,110)
decoration1(14.5,100)
door(-10,-60)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/789285.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-05
下一篇 2022-05-05

发表评论

登录后才能评论

评论列表(0条)

保存