#include "Graphic_fun.h" /* 功能:输出为 # # # # # # # # # # # # */ UINT32 Graphic_prismatic1( UINT32 u32_line, CHAR i8_m ) { UINT32 u32_i = 0u, u32_j = 0u; /* 上半部分 */ for ( u32_i = 1u; u32_i <= u32_line; u32_i++) { for (u32_j = 1u; u32_j <= (u32_line + u32_i); u32_j++) { if ((u32_j== ((u32_line + 1u) -u32_i))|| (u32_j == ((u32_line - 1u) + u32_i))) { if ( NULL != i8_m) { (void)OSM_Printf("%c", i8_m); } } else { (void)OSM_Printf(" "); } } (void)OSM_Printf("\n"); } /* 下半部分 */ for ( u32_i = 1u; u32_i < u32_line; u32_i++) { for (u32_j = 1u; u32_j < ((2u * u32_line) - 1u); u32_j++) { if ( (u32_j == (u32_i + 1u)) ||( u32_j == ((2u * u32_line) - 1u -u32_i))) { if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } else { (void)OSM_Printf(" "); } } (void)OSM_Printf("\n"); } return 0u; } /* 打印出实心的棱形 */ UINT32 Graphic_prismatic2( UINT32 u32_line, CHAR i8_m ) { UINT32 u32_i = 0u; UINT32 u32_j = 0u; /* 上半部分 */ for ( u32_i = 1u; u32_i <= u32_line; u32_i++) { for (u32_j = 1u; u32_j < (u32_line + u32_i); u32_j++) { if ( (u32_j >= ((u32_line + 1u) -u32_i))&&(u32_j <= ((u32_line - 1u) + u32_i))) { if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } else { (void)OSM_Printf(" "); } } (void)OSM_Printf("\n"); } /* 下半部分 */ for ( u32_i = 1u; u32_i < u32_line; u32_i++) { for (u32_j = 1u; u32_j < ((2u *u32_line) - 1u) ; u32_j++) { if ( (u32_j >= (u32_i + 1u)) && ( u32_j <= ((2u * u32_line) - 1u -u32_i))) { if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } else { (void)OSM_Printf(" "); } } (void)OSM_Printf("\n"); } return 0u; } /* 十字架 */ UINT32 Graphic_prismatic3( UINT32 u32_line, CHAR i8_m ) { UINT32 u32_i = 0u; UINT32 u32_j = 0u; /* 上半部分 */ for ( u32_i = 1u; u32_i <= u32_line; u32_i++) { for (u32_j = 1u; u32_j < (u32_line + u32_i); u32_j++) { if ( (u32_j == u32_line) || (u32_i == u32_line)) { if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } else { (void)OSM_Printf(" "); } } (void)OSM_Printf("\n"); } /* 下半部分 */ for ( u32_i = 1u; u32_i < u32_line; u32_i++) { for (u32_j = 1u; u32_j < ((2u * u32_line) - 1u) ; u32_j++) { if ( u32_j == u32_line) { if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } else { (void)OSM_Printf(" "); } } (void)OSM_Printf("\n"); } return 0u; } /* 正弦波 */ UINT32 Graphic_prismatic4( UINT32 u32_Max, UINT32 u32_Time, CHAR i8_m ) { INT32 i32_x = 0; INT32 i32_y = 0; DOUBLE tmp =((DOUBLE)2) * PI / (INT32)u32_Time; for ( i32_x = 0; i32_x <= (INT32)u32_Time; i32_x++) { if ( sin(tmp * i32_x) >= 0.00000) { for ( i32_y = 0; i32_y <= (INT32)u32_Max + (INT32)u32_Max * sin(tmp * i32_x);i32_y++ ) { (void)OSM_Printf(" "); } if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } if ((DOUBLE)sin((DOUBLE)tmp * i32_x) < 0.0000) { for ( i32_y = 0; i32_y <= ( u32_Max + (u32_Max * sin(tmp * i32_x)) ); i32_y++) { (void)OSM_Printf(" "); } if ( NULL != i8_m) { (void)OSM_Printf("%c",i8_m); } } (void)OSM_Printf("\n"); } return 0u; } /* 功能:输出相间的实心菱形,根据函数参数变化大小、行数和列数 */ UINT32 Graphic_prismatic5( UINT32 u32_line, UINT32 row, UINT32 column ) { UINT32 u32_i = 0u; UINT32 u32_k = 0u; UINT32 u32_t = 0u; UINT32 u32_j = 0u; /* 上半部分 */ for (u32_k = 0u; u32_k < row; u32_k++) { for ( u32_i = 1u; u32_i <= u32_line; u32_i++) { for (u32_t = 1u; u32_t <= column; u32_t++) { for (u32_j = 1u; u32_j < ((2u * u32_line) -1u); u32_j++) { if ( (u32_j >= ((u32_line + 1u) -u32_i))&&(u32_j <= ((u32_line - 1u) + u32_i))) { (void)OSM_Printf("#"); } else { (void)OSM_Printf(" "); } } } (void)OSM_Printf("\n"); } /* 下半部分 */ for ( u32_i = 1u; u32_i < (u32_line - 1u); u32_i++) { for (u32_t = 0u; u32_t < column; u32_t++) { for (u32_j = 1u; u32_j < ((2u *u32_line) - 1u) ; u32_j++) { if ( (u32_j >= (u32_i + 1u)) && ( u32_j <= ((2u * u32_line) - 1u -u32_i))) { (void)OSM_Printf("#"); } else { (void)OSM_Printf(" "); } } } (void)OSM_Printf("\n"); } } for ( u32_i = 1u; u32_i <= column; u32_i++) { for (u32_j = 1u; u32_j <= ((2u * u32_line) - 1u) ; u32_j++) { if ((u32_j == ((u32_line + 1u) -u32_i)) ) { (void)OSM_Printf("#"); } else { (void)OSM_Printf(" "); } } } return 0u; }
主函数
#include "Graphic_fun.h" UINT32 main( void ) { UINT32 line = 0u; CHAR simble; Graphic_prismatic1(7, '#'); OSM_Printf("\n"); Graphic_prismatic2(7, '#'); OSM_Printf("\n"); Graphic_prismatic3(10, '#'); OSM_Printf("\n"); Graphic_prismatic4(10,12, '#'); OSM_Printf("\n"); Graphic_prismatic5(4,4,4); return 0; }
输出的图案:
这个对我们的控制循环有很大的帮助
时间: 2024-10-22 13:09:47