用Python中的Turtle编程画房子 您所在的位置:网站首页 房子三维简笔画 用Python中的Turtle编程画房子

用Python中的Turtle编程画房子

2024-07-13 23:30| 来源: 网络整理| 查看: 265

用Python中的Turtle编程画房子

“Turtle “是一个类似于画板的Python功能,它可以让我们指挥Turtle在上面画个不停”Turtle “与标准的Python包打包在一起,不需要在外部安装。

第1步:在Python中导入turtle和math模块。

import turtle import math

第二步:为你的输出屏幕选择一个背景颜色。你可以选择任何颜色,我们将使用黄色,只是为了使它具有吸引力。

screen = turtle.Screen() screen.bgcolor("yellow")

第3步:选择你的Turtle(笔)的颜色和速度,他将在屏幕上画房子。

t.color("black") t.shape("turtle") t.speed(1)

第四步:现在,我们需要画出你的房子的底座,为此,你需要画一个矩形。

你可以通过改变t.fillcolor(‘ ‘)命令中的颜色名称,在你的选择中填充任何颜色。

t.fillcolor('cyan') t.begin_fill( ) t.right(90) t.forward(250) t.left(90) t.forward(400) t.left(90) t.forward(250) t.left(90) t.forward(400) t.right(90) t.end_fill()

第5步:现在你创建了基地,下一步是创建房子的顶部。为上面的部分画一个三角形,只是为了保持简单。

# for creating triangle # i.e top of the house t.fillcolor('brown') t.begin_fill() t.right(45) t.forward(200) t.right(90) t.forward(200) t.left(180) t.forward(200) t.right(135) t.forward(259) t.right(90) t.forward(142) t.end_fill()

第6步:我们必须通过设置门和窗户来保护我们的房子,以便通风。以下是这方面的代码

# for windows and # for creating door t.right(90) t.forward(400) t.left(90) t.forward(50) t.left(90) t.forward(150) t.right(90) t.forward(200) t.right(180) t.forward(200) t.right(90) t.forward(200) t.right(90) t.forward(150) t.right(90) t.forward(200) t.right(90) t.forward(150) t.right(90) t.forward(100) t.right(90) t.forward(150) t.right(90) t.forward(100) t.right(90) t.forward(75) t.right(90) t.forward(200)

Complete 代码:

import turtle       t = turtle.Turtle()    # for background screen = turtle.Screen() screen.bgcolor("yellow")    #color and speed # of turtle # creating the house t.color("black") t.shape("turtle") t.speed(1)    # for creating base of # the house t.fillcolor('cyan') t.begin_fill() t.right(90) t.forward(250) t.left(90) t.forward(400) t.left(90) t.forward(250) t.left(90) t.forward(400) t.right(90) t.end_fill()    # for top of # the house t.fillcolor('brown') t.begin_fill() t.right(45) t.forward(200) t.right(90) t.forward(200) t.left(180) t.forward(200) t.right(135) t.forward(259) t.right(90) t.forward(142) t.end_fill()    # for door and # windows t.right(90) t.forward(400) t.left(90) t.forward(50) t.left(90) t.forward(150) t.right(90) t.forward(200) t.right(180) t.forward(200) t.right(90) t.forward(200) t.right(90) t.forward(150) t.right(90) t.forward(200) t.right(90) t.forward(150) t.right(90) t.forward(100) t.right(90) t.forward(150) t.right(90) t.forward(100) t.right(90) t.forward(75) t.right(90) t.forward(200) t.right(180) t.forward(200) t.right(90) t.forward(75) t.left(90) t.forward(15) t.left(90) t.forward(200) t.right(90) t.forward(15) t.right(90) t.forward(75)


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有