如果你想用Python画一个美丽的楼阁,那么你来对地方了。下面是其中一种方法:
from turtle import * # 设置画布大小 setup(600, 600) # 画第一个方块 fillcolor("white") begin_fill() pendown() forward(100) left(90) forward(100) left(90) forward(100) left(90) forward(100) left(90) penup() end_fill() # 画第二个方块 goto(110, 110) fillcolor("white") begin_fill() pendown() forward(80) left(90) forward(80) left(90) forward(80) left(90) forward(80) left(90) penup() end_fill() # 画第三个方块 goto(150, 150) fillcolor("white") begin_fill() pendown() forward(50) left(90) forward(50) left(90) forward(50) left(90) forward(50) left(90) penup() end_fill() # 画屋顶 goto(50, 200) pendown() fillcolor("red") begin_fill() goto(150, 200) goto(100, 250) goto(50, 200) end_fill() # 画门 goto(85, 0) fillcolor("brown") begin_fill() pendown() forward(30) left(90) forward(60) left(90) forward(30) left(90) forward(60) left(90) penup() end_fill() hideturtle() done()
以上代码可以让turtle库根据指定的顺序自动绘制一个楼阁。你可以根据需要调整各个位置和颜色,让它变得更加个性化。祝你编程愉快!