注册 登录
编程论坛 C图形专区

[求助] 实心小球沿正弦曲线运动

动来动去 发布于 2007-07-02 12:52, 1202 次点击
要求画出一个实心小球,并让小球沿着正弦曲线运动.
我还不太会用图形函数 希望 大家能帮帮我
9 回复
#2
cdmalcl2007-07-03 21:40
#3
动来动去2007-07-03 21:56

#4
动来动去2007-07-03 21:58

谢谢~ 其实不想谢你!!

#5
cdmalcl2007-07-03 22:14

不用谢 不用谢 多请我几顿饭就行

#6
动来动去2007-07-03 22:17

我看这个机会还是留给别人吧~~

#7
cdmalcl2007-07-04 00:47
随意随意 能有饭吃就行
#8
动来动去2007-07-04 12:39
那你就等等吧`
#9
cdmalcl2007-07-04 17:55

晕了
另一个程序我怎么也粘贴不上来

你上QQ了管我要吧

#10
cdmalcl2007-07-05 08:38

还是把程序贴出来吧 要不 苍穹大哥会怒的


#include <graphics.h>
#include <math.h>
#include <stdlib.h>

#define PI 3.14
#define LINECOLOR 7
#define ESC 283

typedef struct
{
int x ;
int y ;
}SITE;

typedef struct
{
SITE s0 ;
SITE s1 ;
SITE s2 ;
SITE s3 ;
}RECTSITE;

int Init() ;
int drawProcess() ;
int moveRectangle(RECTSITE rectSite) ;
int End() ;

int screenMaxx2, screenMaxy2 ;

main()
{
Init();
drawProcess();
End();
}

int Init()
{
int gd = DETECT, gm = 0 ;

initgraph(&gd, &gm, "") ;

screenMaxx2 = getmaxx()/2 ;
screenMaxy2 = getmaxy()/2 ;

}
/*
Len0
s0-------s1
| |
| |Len1
| |
| |
s3-------s2

*/
int drawProcess()
{
RECTSITE rectSite ;
int moveCenterX, moveCenterY ;
int i ;
float LenR, Len0, Len1 ;
float startr, r ;

Len0 = 50 ;
Len1 = 80 ;
LenR = sqrt(Len0*Len0+Len1*Len1) ;
startr = atan(Len1/Len0) ;

moveCenterX = screenMaxx2 ;
moveCenterY = screenMaxy2 ;

rectSite.s0.x = moveCenterX ;
rectSite.s0.y = moveCenterY ;

while(!kbhit())
{
for(r = 0;r <= PI*2;r+=0.0314)
{
rectSite.s1.x = Len0*sin(r)+moveCenterX ;
rectSite.s2.x = LenR*sin(r-startr)+moveCenterX ;
rectSite.s3.x = Len1*sin(r-PI/2)+moveCenterX ;
rectSite.s1.y = Len0*cos(r)+moveCenterY ;
rectSite.s2.y = LenR*cos(r-startr)+moveCenterY ;
rectSite.s3.y = Len1*cos(r-PI/2)+moveCenterY ;

setcolor(LINECOLOR) ;
moveRectangle(rectSite) ;

delay(1000) ;

setcolor(0) ;
moveRectangle(rectSite) ;

if(kbhit())
{
if(bioskey(0) == ESC)
return 0 ;
}
}

}
}

int moveRectangle(RECTSITE rectSite)
{
line(rectSite.s0.x, rectSite.s0.y, rectSite.s1.x, rectSite.s1.y) ;
line(rectSite.s1.x, rectSite.s1.y, rectSite.s2.x, rectSite.s2.y) ;
line(rectSite.s2.x, rectSite.s2.y, rectSite.s3.x, rectSite.s3.y) ;
line(rectSite.s3.x, rectSite.s3.y, rectSite.s0.x, rectSite.s0.y) ;

}

int End()
{
setcolor(4) ;
outtextxy(screenMaxx2, screenMaxy2, "END!") ;
getch() ;
closegraph() ;
}

1