
各位高手好,请求大家帮忙释疑,下面这个程序是用C语言在屏幕上画自由的曲线的程序,请大家帮忙,感激不尽 50
这个函数的基本思想是,首先选择两个点,然后随机的选择第三个点,第三个点就在第二个点的周围,因为一个点有八个方位。然后,连接第二个点和第三个点,因为像素点之间的距离很小,连...
这个函数的基本思想是,首先选择两个点,然后随机的选择第三个点,第三个点就在第二个点的周围,因为一个点有八个方位。然后,连接第二个点和第三个点,因为像素点之间的距离很小,连接起来就像是平滑的曲线一样!!注释写的不好,所以在这里补充了!
#include"graphics.h"
#include"time.h"
#include"conio.h"
#include"stdio.h"
#define N 200
struct point
{ int x[N];
int y[N];
}dot;
int a=1;
/*initation the graphics screen*/
void init()
{
int mode,driver;
driver=DETECT;
initgraph(&driver,&mode,"c:\\tc\\bgi\\");
cleardevice();
}
/*set a random value for the curve*/
int randomvalue()
{
int value;
srand((unsigned)time(NULL));
value=rand()%8;
return value;
}
/*set eight option for the choose
一个点周围有八个像素点,然后随机的选择一个点当做方向*/
void choose_direction(int direction)
{
line(dot.x[a-1],dot.y[a-1],dot.x[a],dot.y[a]);
switch(direction){
case 0:dot.x[a+1]++;break;
case 1:dot.x[a+1]++;dot.y[a+1]++;break;
case 2:dot.y[a+1]++;break;
case 3:dot.x[a+1]--;dot.y[a+1]++;break;
case 4:dot.x[a+1]--;break;
case 5:dot.x[a+1]--;dot.y[a+1]--;break;
case 6:dot.y[a+1]--;break;
case 7:dot.x[a+1]++;dot.y[a+1]--;break;
}
}
void main()
{
init();
while(!kbhit){
dot.x[1]=200;dot.y[1]=200;dot.x[0]=199;dot.y[0]=199;
for(a;;a++)
{
/*randomvalue();*/
choose_direction(randomvalue());
}
getch();
closegraph();
exit(1);
}
} 展开
#include"graphics.h"
#include"time.h"
#include"conio.h"
#include"stdio.h"
#define N 200
struct point
{ int x[N];
int y[N];
}dot;
int a=1;
/*initation the graphics screen*/
void init()
{
int mode,driver;
driver=DETECT;
initgraph(&driver,&mode,"c:\\tc\\bgi\\");
cleardevice();
}
/*set a random value for the curve*/
int randomvalue()
{
int value;
srand((unsigned)time(NULL));
value=rand()%8;
return value;
}
/*set eight option for the choose
一个点周围有八个像素点,然后随机的选择一个点当做方向*/
void choose_direction(int direction)
{
line(dot.x[a-1],dot.y[a-1],dot.x[a],dot.y[a]);
switch(direction){
case 0:dot.x[a+1]++;break;
case 1:dot.x[a+1]++;dot.y[a+1]++;break;
case 2:dot.y[a+1]++;break;
case 3:dot.x[a+1]--;dot.y[a+1]++;break;
case 4:dot.x[a+1]--;break;
case 5:dot.x[a+1]--;dot.y[a+1]--;break;
case 6:dot.y[a+1]--;break;
case 7:dot.x[a+1]++;dot.y[a+1]--;break;
}
}
void main()
{
init();
while(!kbhit){
dot.x[1]=200;dot.y[1]=200;dot.x[0]=199;dot.y[0]=199;
for(a;;a++)
{
/*randomvalue();*/
choose_direction(randomvalue());
}
getch();
closegraph();
exit(1);
}
} 展开
2个回答
展开全部
首先,你的问题忘说了。
其次,你这个问题与 迷宫路径生成 这个例子很像。
如果你需要问题的解答,或者什么的话,说下。
如果只是单纯的需要 相似问题的探讨 可以搜下“迷宫路径” 这个关键词。
希望以上对你有帮助
其次,你这个问题与 迷宫路径生成 这个例子很像。
如果你需要问题的解答,或者什么的话,说下。
如果只是单纯的需要 相似问题的探讨 可以搜下“迷宫路径” 这个关键词。
希望以上对你有帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询