二层小楼楼阁
import turtle as t
import time
def go(x,y):
t.penup()
t.goto(x,y)
t.pendown()
def rangle(h,w):
t.left(180)
t.forward(h)
t.right(90)
t.forward(w)
t.left(-90)
t.forward(h)
def leftf(a,l):
t.left(a)
t.forward(l)
def rightr(a,l):
t.right(a)
t.forward(l)
def square(w,h):
t.forward(h)
t.right(90)
t.forward(w)
t.right(90)
t.forward(h)
t.right(90)
t.forward(w)
t.pencolor("#2F4F4F")
t.hideturtle()
t.speed(100)
t.bgcolor("#48D1CC")
t.penup()
t.goto(-600,-250)
t.pendown()
t.forward(950)
t.goto(-400,-250)
t.fillcolor("#B0E0E6")
t.begin_fill()
t.left(90)
t.forward(15)
t.right(90)
t.forward(225)
t.left(-90)
t.forward(15)
# 门子
rangle(22,150)
rangle(15,225)
# 柱子
go(-385,-235)
rangle(15,23)
go(-383,-220)
rangle(100,18)
go(-385,-120)
t.left(90)
t.forward(23)
go(-385,-120)
t.right(90)
rangle(15,23)
go(-280,-235)
rangle(15,23)
go(-278,-220)
rangle(100,18)
go(-280,-120)
t.left(90)
t.forward(23)
go(-280,-120)
t.right(90)
rangle(15,23)
go(-160,-228)
rangle(15,23)
go(-158,-213)
rangle(93,18)
go(-160,-120)
t.left(90)
t.forward(23)
go(-160,-120)
t.right(90)
rangle(15,23)
go(-63,-228)
rangle(15,23)
go(-61,-213)
rangle(93,18)
go(-63,-120)
t.left(90)
t.forward(23)
go(-63,-120)
t.right(90)
rangle(15,23)
go(60,-235)
rangle(15,23)
go(62,-220)
rangle(100,18)
go(60,-120)
t.left(90)
t.forward(23)
go(60,-120)
t.right(90)
rangle(15,23)
go(162,-235)
rangle(15,23)
go(164,-220)
rangle(100,18)
go(162,-120)
t.left(90)
t.forward(23)
go(162,-120)
t.right(90)
rangle(15,23)
t.end_fill()
#顶部分
t.fillcolor("#F0E68C")
t.begin_fill()
go(-400,-105)
leftf(90,600)
leftf(90,10)
leftf(35,50)
leftf(55,538)
leftf(55,55)
leftf(35,6.5)
t.end_fill()
#三角形部分
t.fillcolor("#B0E0E6")
t.begin_fill()
go(-149,5)
leftf(150,103)
rightr(120,100)
rightr(90,10)
rightr(90,81)
leftf(120,85)
rightr(90,11.5)
go(-137,8)
leftf(120,76)
leftf(90,78)
leftf(90,76)
leftf(30,75.9)
leftf(120,81.2)
t.end_fill()
go(-120,-52)
leftf(120,45)
leftf(90,15)
leftf(90,45)
leftf(90,15)
t.fillcolor("#5F9EA0")
t.begin_fill()
go(-115,-37)
leftf(180,30)
rightr(90,30)
rightr(90,30)
rightr(90,30)
t.end_fill()
#窗子部分
go(-85,-7)
t.right(90)
t.circle(15,180)
leftf(90,30)
t.fillcolor("#B0E0E6")
t.begin_fill()
go(-320,-45)
t.left(90)
square(150,15)
t.end_fill()
t.fillcolor("#5F9EA0")
t.begin_fill()
go(-305,-30)
t.right(90)
square(120,25)
t.end_fill()
t.fillcolor("#5F9EA0")
t.begin_fill()
go(-305,-5)
t.right(90)
square(120,25)
t.end_fill()
go(-245,20)
t.left(90)
t.forward(50)
#窗子
go(-20,-45)
t.fillcolor("#B0E0E6")
t.begin_fill()
t.left(180)
square(150,15)
t.end_fill()
t.fillcolor("#5F9EA0")
t.begin_fill()
go(-5,-30)
t.right(90)
square(120,25)
t.end_fill()
t.fillcolor("#5F9EA0")
t.begin_fill()
go(-5,-5)
t.right(90)
square(120,25)
t.end_fill()
go(55,20)
t.left(90)
t.forward(50)
go(150,39)
t.forward(100)
#烟筒
go(-275,130)
t.left(180)
t.fillcolor("#B0E0E6")
t.begin_fill()
square(20,40)
go(-280,170)
t.right(90)
square(30,20)
t.end_fill()
go(-370,55)
rightr(180,110)
go(-250,55)
t.forward(35)
go(-205,55)
t.forward(80)
go(-67,55)
t.forward(120)
go(60,55)
t.forward(35)
go(100,53)
t.forward(60)
go(-395,-95)
t.forward(300)
go(-90,-95)
t.forward(35)
go(-40,-95)
t.forward(55)
go(25,-95)
t.forward(175)
#门
go(-70,-229)
leftf(90,90)
t.circle(30,180)
t.forward(90)
go(-80,-180)
t.fillcolor("#5F9EA0")
t.begin_fill()
t.circle(5,360)
t.end_fill()
动态小房子
import turtle as t
t.pensize(2)
t.speed(1) #设置画画的速率
t.colormode(255)
t.pencolor("black")
t.begin_fill()
#房顶
t.fillcolor(0,245,255)
for i in range(3):
t.forward(240)
t.left(120)
t.end_fill()
#房顶阁楼窗户外框
t.penup()
t.goto(80,20)
t.pendown()
t.begin_fill()
t.fillcolor("white")
for i in range(4):
t.forward(80)
t.left(90)
t.end_fill()
#阁楼窗户内部的横线
t.penup()
t.goto(80,60)
t.pendown()
t.forward(80)
#阁楼窗户内部的竖线
t.penup()
t.goto(120,100)
t.pendown()
t.right(90)
t.forward(80)
t.right(90)
t.forward(80)
#房屋主体
t.left(90)
t.penup()
t.goto(0,0)
t.pendown()
t.begin_fill()
t.fillcolor(255,165,0)
for i in range(2):
t.forward(240)
t.left(90)
t.forward(240)
t.left(90)
t.end_fill()
#屋门
t.penup()
t.goto(30,-180)
t.pendown()
t.begin_fill()
t.fillcolor("blue")
for i in range(2):
t.forward(50)
t.left(90)
t.forward(100)
t.left(90)
t.end_fill()
#窗框
t.penup()
t.goto(140,-90)
t.pendown()
t.begin_fill()
t.fillcolor("white")
for i in range(4):
t.forward(70)
t.left(90)
t.end_fill()
#窗户上的竖线
t.penup()
t.goto(175,-90)
t.pendown()
t.left(90)
t.forward(70)
t.hideturtle()
简易房子
import turtle as t
t.pensize(2)
t.speed(1) #设置画画的速率
t.colormode(255)
t.pencolor("black")
t.begin_fill()#房顶
t.fillcolor(0,245,255)
for i in range(3):
t.forward(240)
t.left(120)
t.end_fill()#房顶阁楼窗户外框
t.penup()
t.goto(80,20)
t.pendown()
t.begin_fill()
t.fillcolor("white")
for i in range(4):
t.forward(80)
t.left(90)
t.end_fill()#阁楼窗户内部的横线
t.penup()
t.goto(80,60)
t.pendown()
t.forward(80)#阁楼窗户内部的竖线
t.penup()
t.goto(120,100)
t.pendown()
t.right(90)
t.forward(80)
t.right(90)
t.forward(80)#房屋主体
t.left(90)
t.penup()
t.goto(0,0)
t.pendown()
t.begin_fill()
t.fillcolor(255,165,0)
for i in range(2):
t.forward(240)
t.left(90)
t.forward(240)
t.left(90)
t.end_fill()#屋门
t.penup()
t.goto(30,-180)
t.pendown()
t.begin_fill()
t.fillcolor("blue")
for i in range(2):
t.forward(50)
t.left(90)
t.forward(100)
t.left(90)
t.end_fill()#窗框
t.penup()
t.goto(140,-90)
t.pendown()
t.begin_fill()
t.fillcolor("white")
for i in range(4):
t.forward(70)
t.left(90)
t.end_fill()#窗户上的竖线
t.penup()
t.goto(175,-90)
t.pendown()
t.left(90)
t.forward(70)
t.hideturtle()
…
from turtle import *
import random
def drawTree(length):
if length>1:
if length<30 and length>14:#缩小一下树干
pensize(4)
elif length<15 and length>5:#长度这个范围内那么就是绿叶
color('#04B486')#
pensize(3)
elif length<5 and length>1:#红花
color('#FE2E9A')
pensize(2)
else:
color('#5E5E5E')#其他范围就是正常的树干
pensize(5)
#随机角度与长度
randangle=2*random.random()
randlen=2*random.random()
#每次使用函数先绘制线段,再调整角度,这里是向右的角度转动
fd(length)
right(20*randangle)
drawTree(length - 10*randlen)
#这里是向左的角度转动
left(40 * randangle)
drawTree(length - 10*randlen)
#为什么需要再向右转20度?那是因为我一共向左转了40度,使用backward后退,必须是相同的角度,不然退回去角度就不同了位置就不会对
right(20 * randangle)
up()
backward(length)
down()
def fallingFlowers(m):
x,y=-1000,-750
for i in range(30):
up()
goto(x,y)
x+=100
down()
yval=50
for i in range(m):
a = 100*random.random()
b = 2*random.random()
print(a)
if a>59:
color('#FE2E9A')
else:
color('#04B486')
circle(5)
up()
goto(x,y+(yval*b))
fd(a)
yval+=50
down()
setworldcoordinates(-1000,-750,1000,750)
tracer(False)
fallingFlowers(10)#绘制落叶
bgcolor("#F5F6CE")
color('#5E5E5E')
pensize(5)
up()
goto(0,-700)#跳到绘制起始点
down()
left(80)
fd(140)
drawTree(120)
input()