打印图形

来源:互联网 发布:python 图片处理 编辑:程序博客网 时间:2024/05/01 16:11




char g_print_array[20][20] = {{0}};struct my_point{    int i;    int j;};- (int)print_array_init:(char)c{    int i = 0;    int j = 0;    for (i = 0; i < 20; i++)    {        for (j = 0; j < 20; j++)        {            g_print_array[i][j] = c;        }    }    return 0;}- (int)print_array_show{    int i = 0;    int j = 0;    for (i = 0; i < 20; i++)    {        for (j = 0; j < 20; j++)        {            printf("%c", g_print_array[i][j]);        }        printf("\n");    }    return 0;}- (int)print_array_assign_with:(struct my_point)point{    g_print_array[point.i][point.j] = '-';    return 0;}- (int)print_point_to_point:(struct my_point)from to:(struct my_point)to{    int line_step = to.i - from.i;    int col_step = to.j - from.j;    int cur_line = from.i;    int cur_col = from.j;    if (line_step > 0)    {        line_step = 1;    }    else if (line_step < 0)    {        line_step = -1;    }    else    {        line_step = 0;    }    if (col_step > 0)    {        col_step = 1;    }    else if (col_step < 0)    {        col_step = -1;    }    else    {        col_step = 0;    }    for (int step = 0; step < 20; step++)    {        g_print_array[cur_line][cur_col] = '.';                if (cur_line != to.i)        {            cur_line = cur_line + line_step;        }                if (cur_col != to.j)        {            cur_col = cur_col + col_step;        }                if ((cur_line == to.i)&&(cur_col == to.j))            break;            }        return 0;}


调用

    struct my_point from_point = {19,19};    struct my_point to_point = {3,7};    struct my_point next_from_point = {3,13};    struct my_point next_to_point = {27,13};    [self print_array_init:' '];    [self print_point_to_point:from_point to:to_point];    [self print_point_to_point:next_from_point to:next_to_point];    //[self print_array_assign_with:point];    [self print_array_show];


0 0
原创粉丝点击