1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream.h>
#include <math.h>
#include <graphics.h>
int main()
{
system("CLS");
//Initialize graphics
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
int x,y,x0,y0,r,x1,y1;
//Options of big circle
x1=300; y1=200; r=15;
//Options of small circle
x0=1; y0=1; x=300; y=200;
//Drawing big circle
circle(x1,y1,r); y=y-r-20;
//Animation of small circle
do{
setcolor(15);
circle(x,y,3);
delay(10);
setcolor(0);
circle(x,y,3);
//Providing an oscillatory motion of the electron along the X axis
x=x+x0;
if (x>=x1+35 or x<=x1-35) {
x0=-x0; y=200;
};
//Finding the second coordinate on the equation of the circle
if (x0==1) y=(int)round(y1-sqrt(1225-(x-x1)*(x-x1)));
if (x0==-1) y=(int)round(y1+sqrt(1225-(x-x1)*(x-x1)));
} while (r<20);
return 0;
}
|