可以将一个五角星看成长点和短点的五个组合。在设置好五角星的长边和短边后,便可以画出对应的长边和短边。之后就可以将角度不断增加来完成五角星了。同时可以设置好五角星相对于y轴的偏移

void wujiaoxing(int x, int y, int a, int b, double degree) {
    double change = PI/180 ;
    POINT star[] = {
        // 顶上那个点
        {x - sin(degree* change) * a, y - cos(degree * change) * a},
        // 左侧短边
        {x - sin((31+degree)*change) * b, y -cos((31+degree)*change) * b},
        // 左侧长边
        {x - sin((degree+72)*change) * a, y - cos((degree+72)*change) * a},
        // 左侧短边
        {x - sin((31+degree+72)*change) * b, y -cos((31+degree+72)*change) * b},
        // 左下长边
        {x - sin((degree+72+72)*change) * a, y - cos((degree+72+72)*change) * a},
        // 左下短边
        {x - sin((31+degree+72+72)*change) * b, y -cos((31+degree+72+72)*change) * b},
        //  右下长边
        {x - sin((degree+72*3.0)*change) * a, y - cos((degree+72*3.0)*change) * a},
        //  右下短边
        {x - sin((31+degree+72*3.0)*change) * b, y -cos((31+degree+72*3.0)*change) * b},
        //  右侧长边
        {x - sin((degree+72*4.0)*change) * a, y -cos((degree+72*4.0)*change) * a},
        //  右侧短边
        {x - sin((31+degree+72*4.0)*change) * b, y -cos((31+degree+72*4)*change) * b}
    } ;
    setfillcolor(YELLOW) ;
    solidpolygon(star, 10) ;
}
posted on 2023-05-07 22:38  Fúsi  阅读(187)  评论(0编辑  收藏  举报