rectangle++c
时间: 2024-01-10 22:20:32 浏览: 28
以下是一个使用C语言绘制矩形的示例程序:
```c
#include <graphics.h>
void main() {
int x0, y0, y1, x1, driver, mode, i;
driver = VGA;
mode = VGAHI;
initgraph(&driver, &mode, "");
setbkcolor(YELLOW);
x0 = 263;
y0 = 263;
y1 = 275;
x1 = 275;
for (i = 0; i <= 18; i++) {
setcolor(1);
rectangle(x0, y0, x1, y1);
x0 = x0 - 5;
y0 = y0 - 5;
x1 = x1 + 5;
y1 = y1 + 5;
}
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
outtextxy(150, 40, "How beautiful it is!");
line(130, 60, 480, 60);
setcolor(2);
circle(269, 269, 137);
}
```
这个程序使用了`graphics.h`库来绘制图形。它首先初始化图形驱动和显示模式,然后设置背景颜色为黄色。接下来,使用循环绘制了一系列矩形,每次循环都会调整矩形的位置和大小。然后,设置文本样式并输出一段文字,绘制一条直线,最后绘制一个圆形。