使用Excel VBA
1. 打开Excel,进入VBA编辑器(VBE)。
2. 插入一个模块,在模块中声明4个函数和一个结构。
3. 编写一个显示窗体的程序,例如“画”。
4. 插入一个窗体,并编写窗体单击事件触发的程序,调用模块中声明的结构和函数来绘制房子。
5. 关闭VBE窗口,在Excel界面启动宏,执行宏“画”,即可在表格上显示房子图形。
使用Python和turtle模块
```python
import turtle
设置画布大小
turtle.setup(800, 600)
创建画笔
pen = turtle.Turtle()
绘制房子主体
pen.penup()
pen.goto(-200, -200)
pen.pendown()
pen.fillcolor("pink")
pen.begin_fill()
pen.forward(400)
pen.left(90)
pen.forward(300)
pen.left(90)
pen.forward(400)
pen.left(90)
pen.forward(300)
pen.left(90)
pen.end_fill()
绘制房顶
pen.penup()
pen.goto(-200, 100)
pen.pendown()
pen.fillcolor("red")
pen.begin_fill()
pen.goto(0, 300)
pen.goto(200, 100)
pen.goto(-200, 100)
pen.end_fill()
绘制窗户
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.goto(-100, 0)
pen.goto(0, 0)
pen.goto(0, -100)
pen.end_fill()
turtle.done()
```
使用OpenCV