C++乌龟画图
- 输入命令并进行绘图
题目:Turtle Graphics
The Logo language, which is popular among elementary school children,made the concept of turtle graphics famous. Imagine a mechanical turtle that walks around the roomunder the control of a C++ program. The turtle holds a pen in one of two positions, up or down.While the pen is down, the turtle traces out shapes as it moves; while the pen is up, the turtle moves about freely without writing anything. In this problem, you’ll simulate the operation of the turtle and create a computerized sketchpad as well.Use a 20-by-20 array floor that is initialized to false. Read commands from an array that contains them. Keep track of the current position of the turtle at all times and whether the pen is currently up or down. Assume that the turtle always starts at position (0, 0) of the floor with its pen up. The set of turtle commands your program must process are shown in Fig.
简单翻译过来,大意是一个拿着笔的乌龟,笔放下时,画出移动的路径;当笔向上时,乌龟自由地四处移动,不画任何东西。记录乌龟的操作命令和创建一个画板(使用一个20*20的数组),并随时记录海龟的当前位置,以及笔是否处于上升或下降状态。假设乌龟总是用它的笔从(0, 0)开始。
命令表
例如:
假设乌龟在靠近地板中心的某个地方。下面的命令将绘制和打印12*12的方形路径并且最后笔尖向上。
输入
2
5,12
3
5,12
3
5,12
3
5,12
1
6
9
输出
代码块
#include <iostream>
using namespace std;
const int COMMANDS = 100, SIZE = 40; //这里SIZE为展示画板大小,由于原本行列间隔不一样,为美观我将行