[求助] 实心小球沿正弦曲线运动
要求画出一个实心小球,并让小球沿着正弦曲线运动.[em06][em06]<BR>我还不太会用图形函数 希望 大家能帮帮我<P>还是把程序贴出来吧 要不 苍穹大哥会怒的[em02]<BR><BR><BR>#include <graphics.h><BR>#include <math.h><BR>#include <stdlib.h></P>
<P>#define PI 3.14<BR>#define LINECOLOR 7<BR>#define ESC 283</P>
<P>typedef struct<BR>{<BR> int x ;<BR> int y ;<BR>}SITE;</P>
<P>typedef struct<BR>{<BR> SITE s0 ;<BR> SITE s1 ;<BR> SITE s2 ;<BR> SITE s3 ;<BR>}RECTSITE;</P>
<P>int Init() ;<BR>int drawProcess() ;<BR>int moveRectangle(RECTSITE rectSite) ;<BR>int End() ;</P>
<P>int screenMaxx2, screenMaxy2 ;</P>
<P>main()<BR>{<BR> Init();<BR> drawProcess();<BR> End();<BR>}</P>
<P>int Init()<BR>{<BR> int gd = DETECT, gm = 0 ;</P>
<P> initgraph(&gd, &gm, "") ;</P>
<P> screenMaxx2 = getmaxx()/2 ;<BR> screenMaxy2 = getmaxy()/2 ;</P>
<P>}<BR>/*<BR> Len0<BR> s0-------s1<BR> | |<BR> | |Len1<BR> | |<BR> | |<BR> s3-------s2</P>
<P>*/<BR>int drawProcess()<BR>{<BR> RECTSITE rectSite ;<BR> int moveCenterX, moveCenterY ;<BR> int i ;<BR> float LenR, Len0, Len1 ;<BR> float startr, r ;</P>
<P> Len0 = 50 ;<BR> Len1 = 80 ;<BR> LenR = sqrt(Len0*Len0+Len1*Len1) ;<BR> startr = atan(Len1/Len0) ;</P>
<P> moveCenterX = screenMaxx2 ;<BR> moveCenterY = screenMaxy2 ;</P>
<P> rectSite.s0.x = moveCenterX ;<BR> rectSite.s0.y = moveCenterY ;</P>
<P> while(!kbhit())<BR> {<BR> for(r = 0;r <= PI*2;r+=0.0314)<BR> {<BR> rectSite.s1.x = Len0*sin(r)+moveCenterX ;<BR> rectSite.s2.x = LenR*sin(r-startr)+moveCenterX ;<BR> rectSite.s3.x = Len1*sin(r-PI/2)+moveCenterX ;<BR> rectSite.s1.y = Len0*cos(r)+moveCenterY ;<BR> rectSite.s2.y = LenR*cos(r-startr)+moveCenterY ;<BR> rectSite.s3.y = Len1*cos(r-PI/2)+moveCenterY ;</P>
<P> setcolor(LINECOLOR) ;<BR> moveRectangle(rectSite) ;</P>
<P> delay(1000) ;</P>
<P> setcolor(0) ;<BR> moveRectangle(rectSite) ;</P>
<P> if(kbhit())<BR> {<BR> if(bioskey(0) == ESC)<BR> return 0 ;<BR> }<BR> }</P>
<P> }<BR>}</P>
<P>int moveRectangle(RECTSITE rectSite)<BR>{<BR> line(rectSite.s0.x, rectSite.s0.y, rectSite.s1.x, rectSite.s1.y) ;<BR> line(rectSite.s1.x, rectSite.s1.y, rectSite.s2.x, rectSite.s2.y) ;<BR> line(rectSite.s2.x, rectSite.s2.y, rectSite.s3.x, rectSite.s3.y) ;<BR> line(rectSite.s3.x, rectSite.s3.y, rectSite.s0.x, rectSite.s0.y) ;</P>
<P>}</P>
<P>int End()<BR>{<BR> setcolor(4) ;<BR> outtextxy(screenMaxx2, screenMaxy2, "END!") ;<BR> getch() ;<BR> closegraph() ;<BR>}</P>
页:
[1]
