目录
【程序56】题目:画图,学用circle画圆形
【程序57】题目:画图,学用line画直线。
【程序58】题目:画图,学用rectangle画方形。
【程序59】题目:画图,综合例子。
【程序60】题目:画图,综合例子。
#include "graphics.h"
#include
int main()
{
int i;
float j = 1, k = 1;
initgraph(640, 480);
setbkcolor(YELLOW);
cleardevice();
for (i = 0;i <= 25;i++)
{
setlinestyle(PS_SOLID, 4);
setlinecolor(BLUE);
circle(310, 250, k);
k = k + j;
j = j + 0.3;
}
_getch();
closegraph();//关闭窗口
}
#include "graphics.h"
#include
int main()
{
int i;
float x0, y0, y1, x1;
float j = 12, k;
initgraph(640, 480);
setbkcolor(GREEN);
cleardevice();
x0 = 263;y0 = 263;y1 = 275;x1 = 275;
for (i = 0;i <= 18;i++)
{
setlinestyle(PS_SOLID, 4);
setlinecolor(BLUE);
line(x0, y0, x0, y1);
x0 = x0 - 5;
y0 = y0 - 5;
x1 = x1 + 5;
y1 = y1 + 5;
j = j + 10;
}
x0 = 263;y1 = 275;y0 = 263;
for (i = 0;i <= 20;i++)
{
setlinestyle(PS_SOLID, 4);
setlinecolor(BLUE);
line(x0, y0, x0, y1);
x0 = x0 + 5;
y0 = y0 + 5;
y1 = y1 - 5;
}
_getch();
closegraph();//关闭窗口
}
程序分析:利用for循环控制100 - 999个数,每个数分解出个位,十位,百位。
#include
#include
int main()
{
int x0, y0, y1, x1, i;
initgraph(640, 480);
setbkcolor(YELLOW);
cleardevice();
x0 = 263;y0 = 263;y1 = 275;x1 = 275;
for (i = 0;i <= 18;i++)
{
setlinestyle(PS_SOLID, 4);
setlinecolor(BLUE);
rectangle(x0, y0, x1, y1);
x0 = x0 - 5;
y0 = y0 - 5;
x1 = x1 + 5;
y1 = y1 + 5;
}
setcolor(2);
circle(269, 269, 137);
_getch();
closegraph();//关闭窗口
}
# define PAI 3.1415926
# define B 0.809
# include "graphics.h"
#include "math.h"
#include
int main()
{
int i, j, k, x0, y0, x, y;
float a;
initgraph(640, 480);
setlinestyle(PS_SOLID, 3);
setlinecolor(BLUE);
setbkcolor(GREEN);
cleardevice();
x0 = 150;y0 = 100;
circle(x0, y0, 10);
circle(x0, y0, 20);
circle(x0, y0, 50);
for (i = 0;i < 16;i++)
{
a = (2 * PAI / 16) * i;
x = ceil(x0 + 48 * cos(a));
y = ceil(y0 + 48 * sin(a) * B);
setlinestyle(PS_SOLID, 3);
setlinecolor(BLUE);
line(x0, y0, x, y);
}
setcolor(3);circle(x0, y0, 60);
/* Make 0 time normal size letters */
_getch();
setfillstyle(10, YELLOW);
floodfill(202, 100, WHITE);
_getch();
for (k = 0;k <= 500;k++)
{
setlinestyle(PS_SOLID, 4);
setlinecolor(BLUE);
for (i = 0;i <= 16;i++)
{
a = (2 * PAI / 16) * i + (2 * PAI / 180) * k;
x = ceil(x0 + 48 * cos(a));
y = ceil(y0 + 48 + sin(a) * B);
setlinestyle(PS_SOLID, 3);
setlinecolor(BLUE);
line(x0, y0, x, y);
}
for (j = 1;j <= 50;j++)
{
a = (2 * PAI / 16) * i + (2 * PAI / 180) * k - 1;
x = ceil(x0 + 48 * cos(a));
y = ceil(y0 + 48 * sin(a) * B);
line(x0, y0, x, y);
}
}
restorecrtmode();
_getch();
closegraph();//关闭窗口
}
#include "graphics.h"
#include
#define LEFT 0
#define TOP 0
#define RIGHT 639
#define BOTTOM 479
#define LINES 400
#define MAXCOLOR 15
int main()
{
int error=0;
int x1, y1;
int x2, y2;
int dx1, dy1, dx2, dy2, i = 1;
int count = 0;
int color = 0;
initgraph(640, 480);
x1 = x2 = y1 = y2 = 10;
dx1 = dy1 = 2;
dx2 = dy2 = 3;
while (!_kbhit())
{
line(x1, y1, x2, y2);
x1 += dx1;y1 += dy1;
x2 += dx2;y2 + dy2;
if (x1 <= LEFT || x1 >= RIGHT)
dx1 = -dx1;
if (y1 <= TOP || y1 >= BOTTOM)
dy1 = -dy1;
if (x2 <= LEFT || x2 >= RIGHT)
dx2 = -dx2;
if (y2 <= TOP || y2 >= BOTTOM)
dy2 = -dy2;
if (++count > LINES)
{
setlinestyle(PS_SOLID, 0);
setlinecolor(BLUE);
color = (color >= MAXCOLOR) ? 0 : ++color;
}
}
closegraph();
_getch();
closegraph();//关闭窗口
}