在控制台上绘制带星号的五边形
我通过获取用户的坐标,在控制台上用 for 循环绘制一个带星号的三角形。但是我无法绘制五边形。五边形包括 3 个三角形,但我编写的程序无法附加这些三角形。它正在绘制 3 个不同的三角形控制台上不同位置的三角形。我该如何解决这个问题?你能帮我吗?
I am drawing a triangle with asteriks on the console with for loops by taking the coordinates from the user.but I couldn't draw pentagon.pentagon includes 3 triangle but the program i wrote couldn't attach these triangles.It is drawing 3 different triangle in different place on console.How can I solve this problem?Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种可能的方法。
要么创建输出的内部表示(如二维字符数组),在其中绘制图形。
图像完成后,您将打印整个数组。
您可以使用转义序列(特定于您的终端)将光标移动到某个位置来绘制字符。
在您的情况下,您应该清除终端一次,然后将光标移动到每个星号。
[编辑] 至于#1:
现在你可以用
screen[y][x] = '*'
绘制一些东西来打印:
There are two possible approaches for this.
Either you create an internal representation of the output (like a two-dimensional character array) in which you draw the graphics.
When the image is done, you print the whole array.
You use escape sequences (which are specific to your terminal) to move the cursor to a certain place to draw characters.
In your case, you should clear the terminal once and then move the cursor for each asterisk.
[EDIT] As for #1:
Now you can draw something with
screen[y][x] = '*'
To print: