我正在尝试制作六边形瓷砖。我有形状,但我在打印时做错了。
这是我的代码和我尝试的内容:
Effective Spread = 2*(935049.7-935049.5).abs()
我需要它们水平而不是垂直。
我知道我做错了什么,即在六角形“m,n”下面打印十六进制形状“m,n + 1”,而不是在右侧。 但我不知道如何解决它。谢谢!
固定!
更新: 结果现在
#include <stdio.h>
int main() {
int i, x;
for (i = 1; i <= 2; i++) {
for (x = 1; x <= 2; x++) {
printf(" %d,%d\t \n", i, x);
printf(" / \t \\\n");
printf("| \t |\n");
printf("| \t |\n");
printf(" \\ \t /\n");
}
printf("\n\n");
}
}
我需要的更多解释和艺术:
#include <stdio.h>
#define COLS 4
#define ROWS 3
void subrow(char* pcWhat, char* pcEndWhat)
{ int col;
for (col = 0; col < COLS; col++) {
printf("%s", pcWhat);
}
printf("%s\n", pcEndWhat);
}
void indexedSubrow(char* pcWhat, char* pcEndWhat, int row, int offset)
{ int col;
for (col = 0; col < COLS; col++) {
printf(pcWhat, row, col+offset);
}
printf("%s\n", pcEndWhat);
}
int main(void) {
int i, x;
subrow(" ___ ","");
for (i = 0; i < ROWS; i++) {
if(i==0){
subrow(" / \\ "," ");
indexedSubrow("/ %d,%d \\___"," ", i, 0);
subrow("\\ / ","\\");
indexedSubrow(" \\___/ %d,%d"," \\", i, 1);
}
//else if(i==ROWS-1){}
else{
subrow(" / \\ "," /");
indexedSubrow("/ %d,%d \\___","/", i, 0);
subrow("\\ / ","\\");
indexedSubrow(" \\___/ %d,%d"," \\", i, 1);
}
}
return 0;
}
另外我很好奇如何添加数字(“假设所有六边形网格中的第二个数字为1”)示例:
现有艺术:
The last subrow is:
\ / \ / \ / \ / \
\___/ 2,1 \___/ 2,3 \___/ 2,5 \___/ 2,7 \
Which should be
\ / \ / \ / \ / \
\___/ 2,1 \___/ 2,3 \___/ 2,5 \___/ 2,7 \
\ / \ / \ / \ /
\___/ \___/ \___/ \___/
So the missing part is:
\ / \ / \ / \ /
\___/ \___/ \___/ \___/
期待:(总体上作为最终结果)
___ ___ ___ ___
/ \ / \ / \ / \
/ 0,0 \___/ 0,1 \___/ 0,2 \___/ 0,3 \___
\ / \ / \ / \ / \
\___/ 0,1 \___/ 0,2 \___/ 0,3 \___/ 0,4 \
/ \ / \ / \ / \ /
/ 1,0 \___/ 1,1 \___/ 1,2 \___/ 1,3 \___/
\ / \ / \ / \ / \
\___/ 1,1 \___/ 1,2 \___/ 1,3 \___/ 1,4 \
/ \ / \ / \ / \ /
/ 2,0 \___/ 2,1 \___/ 2,2 \___/ 2,3 \___/
\ / \ / \ / \ / \
\___/ 2,1 \___/ 2,2 \___/ 2,3 \___/ 2,4 \
谢谢!
答案 0 :(得分:6)
您希望每行创建两个(可能更多)六角形的行 为此,您不得在一个十六进制形状的子行之后打印换行符 而是打印所有(两个)十六进制形状的子行,使用适当的空格来对齐它们。为此,远离标签可能会有所帮助 所以基本上你应该改变
Type.GetType
到
for (x = 1; x <= 2; x++) {
printf(" %d,%d\t \n", i, x);
printf(" / \t \\\n");
printf("| \t |\n");
printf("| \t |\n");
printf(" \\ \t /\n");
}
注1,我没有微调一行中六角形之间的空白。你必须自己做。所以下面的输出可能不会直接满足你,但应该看到核心问题已经解决了。
注2,即使这样,你也会得到一个六角形的正方形网格
如果您确实需要十六进制形状的十六进制网格,则必须在每隔一个十六进制行中更改 for (i = 1; i <= 2; i++) {
for (x = 1; x <= 2; x++) {
printf(" %d,%d ", i, x);
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf(" / \\ ");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf("| |");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf("| |");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf(" \\ / ");
}
printf("\n");
}
的位置。
输出:
|
根据Note2,我在四处玩,试图制作一个十六进制网格。
我还尝试了你的像素图片的ascii艺术, 1,1 1,2
/ \ / \
| || |
| || |
\ / \ /
2,1 2,2
/ \ / \
| || |
| || |
\ / \ /
输出垂直十六进制:
#include <stdio.h>
#define COLS 4
#define ROWS 3
void subrow(char* pcWhat, char* pcEndWhat)
{ int col;
for (col = 0; col < COLS; col++) {
printf("%s", pcWhat);
}
printf("%s\n", pcEndWhat);
}
void indexedSubrow(char* pcWhat, char* pcEndWhat, int row, int offset)
{ int col;
for (col = 0; col < COLS; col++) {
printf(pcWhat, row, col*2+offset);
}
printf("%s\n", pcEndWhat);
}
int main(void) {
int i, x;
for (i = 1; i <= 2; i++) {
for (x = 1; x <= 2; x++) {
printf(" %d,%d ", i, x);
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf(" / \\ ");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf("| |");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf("| |");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf(" \\ / ");
}
printf("\n");
}
printf("\n");
printf("\n");
printf("\n");
for (i = 0; i < ROWS; i++) {
subrow(" / \\ ","");
subrow(" / \\ ","");
subrow(" / \\","");
subrow("| ","|");
subrow("| ","|");
subrow(" \\ /","");
subrow(" \\ / ","");
subrow(" \\ / ","");
subrow(" | ","");
subrow(" | ","");
}
subrow(" / \\ ","");
subrow(" / \\ ","");
subrow(" / \\","");
subrow("| ","|");
subrow("| ","|");
subrow(" \\ /","");
subrow(" \\ / ","");
subrow(" \\ / ","");
printf("\n");
printf("\n");
subrow(" ___ ","");
for (i = 0; i < ROWS; i++) {
subrow(" / \\ "," /");
indexedSubrow("/ %d,%d \\___","/", i, 0);
subrow("\\ / ","\\");
indexedSubrow(" \\___/ %d,%d"," \\", i, 1);
}
return 0;
}
输出水平十六进制:
/ \ / \ / \ / \
/ \ / \ / \ / \
/ \ / \ / \ / \
| | | | |
| | | | |
\ / \ / \ / \ /
\ / \ / \ / \ /
\ / \ / \ / \ /
| | | |
| | | |
/ \ / \ / \ / \
/ \ / \ / \ / \
/ \ / \ / \ / \
| | | | |
| | | | |
\ / \ / \ / \ /
\ / \ / \ / \ /
\ / \ / \ / \ /
我确信你不会喜欢边缘上的部分和数字的位置,
但这是为了让自己适应自己的口味。
答案 1 :(得分:0)
也许试试这个:
split
结果将是:
#include <stdio.h>
int main()
{
int i, x;
for (i = 1; i <= 2; i++) {
for (x = 1; x <= 2; x++) {
printf(" %d,%d ", i, x);
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf(" / \\ ");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf("| | ");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf("| | ");
}
printf("\n");
for (x = 1; x <= 2; x++) {
printf(" \\ / ");
}
printf("\n");
}
}
我刚用C:
创建的简单程序 1,1 1,2
/ \ / \
| | | |
| | | |
\ / \ /
2,1 2,2
/ \ / \
| | | |
| | | |
\ / \ /