用easyx和类画一面盾牌
时间: 2023-12-14 20:02:40 浏览: 103
以下是用EasyX图形库和C++类来画一面盾牌的示例代码:
```cpp
#include <graphics.h>
#include <conio.h>
class Shield {
public:
Shield(int x, int y, int r, COLORREF color) : m_x(x), m_y(y), m_r(r), m_color(color) {}
void Draw() {
setfillcolor(m_color);
setlinecolor(WHITE);
fillellipse(m_x, m_y, m_r, m_r);
setfillcolor(WHITE);
int inner_r = m_r / 2;
fillellipse(m_x, m_y, inner_r, inner_r);
setfillcolor(m_color);
int shape[8] = { m_x - m_r / 2, m_y, m_x - m_r / 3, m_y - m_r / 2, m_x, m_y - m_r / 3, m_x + m_r / 3, m_y - m_r / 2 };
fillpolygon(shape, 4);
int shape2[8] = { m_x - m_r / 2, m_y, m_x - m_r / 3, m_y + m_r / 2, m_x, m_y + m_r / 3, m_x + m_r / 3, m_y + m_r / 2 };
fillpolygon(shape2, 4);
}
private:
int m_x, m_y, m_r;
COLORREF m_color;
};
int main() {
initgraph(640, 480);
Shield shield(320, 240, 100, RED);
shield.Draw();
getch();
closegraph();
return 0;
}
```
运行以上代码后,会在屏幕上显示一面红色的盾牌。
阅读全文