R
rus
Код:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <STDLIB.H>
#include <dos.h>
#define K 0.45
void open_graph(void);
void zicloida(int R1,int R2,int R3,float T );
char* s1_s2(char *s1,char *s2);
int main(){
int R1,R2,R3;
printf("Enter R1,R2,R3 :\n");
scanf("%d%d%d",&R1,&R2,&R3);
open_graph();
zicloida(R1,R2,R3,0.0);
getch();
closegraph();
return 0;
}
void open_graph(void){
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
// int x, y;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
}
void zicloida(int r1,int r2,int r3,float t )
{
int X,Y,xo,yo,R1,R2,R3,col;
float T;
char str1[20],str2[8],str3[8];
randomize();
xo = getmaxx()/2;
yo = getmaxy()/2;
for(R1 = r1; R1 <= 187; R1 += 5)
for(R2 = r2; R2 <= 240; R2 += 5)
for(R3 = r3; R3 <= 240; R3 += 5)
{
outtextxy(1,1,"R1 R2 R3 ");
col =rand()%16;
itoa(R1, str1,10);
itoa(R2, str2,10);
itoa(R3, str3,10);
s1_s2(str1," ");
s1_s2(str1,str2);
s1_s2(str1," ");
s1_s2(str1,str3);
outtextxy(1,12,str1);
for(T = t;T <= 600.0 ; T += 0.1){
X = (R1 + R2) * cos(R2 * T / R1) - R3 * cos((R1 + R2) / R1 * T);
Y = (R1 + R2) * sin(R2 * T / R1) - R3 * sin((R1 + R2) / R1 * T);
putpixel(X*K+xo,Y*K+yo,col);
if ( kbhit()) exit(1);
}
delay(50);
/* clear the screen */
cleardevice();
}
}
char* s1_s2(char *s1,char *s2){
int i,j;
/**/
i=j=0;
while (s1[i]!='\0')
i++;
while( (s1[i++]=s2[j++]) !='\0');
// printf("\n< s1= %s s2=%s >",s1,s2 );
return s1;
}