#include <graphics.h>
#include <bios.h>
#include <math.h>
#include <dos.h>
#include <conio.h>
//------------------------------------------------------------------------//
//***** Prototype of functions *****//
int print(float yb,int color);
int screensaver();
//change of argument
float x1 = 0,
x2 = 12*M_PI;
float x,y,dx = 0.1;
int w = 10,
h = 10;
//inititoal value
int x0 = 300,
y0 = 30;
//------------------------------------------------------------------------//
//***** Main function *****//
int main() {
double A,t,T,yb,k,m;
// initialisation graphics mode
int gdriver = DETECT, gmode;
initgraph(&gdriver,&gmode,"D:\\BC\\BGI");
// time
t = 0;
// coordinate of change
yb = 0;
// amplitude
A = 140;
// koeficient deflection rate
k = 2;
// mass
m = 100;
screensaver();
getch();
cleardevice();
settextstyle(2,HORIZ_DIR,4);
setcolor(7);
outtextxy(10,50,"RGR by Sergey Buchchenko");
setcolor(4);
rectangle(8,61,200,72);
outtextxy(10,60,"Formule: y = A cos(sqrt(k/m) t)");
setcolor(7);
outtextxy(10,70,"where A - amplitude");
outtextxy(10,80," k - koeficient deflection rate");
outtextxy(10,90," m - mass of ball");
outtextxy(10,100," t - time");
setfillstyle(8,7);
bar(0,0,getmaxx(),30);
rectangle(0,0,getmaxx(),30);
while(!bioskey(1))
{
yb = A * cos(sqrt(k/m) * t);
print(yb, 7);
delay(10);
print(yb, 0);
t++;
(A > 0) ? (A -=0.5) : (A = 0);
}
closegraph();
return 0;
}
//------------------------------------------------------------------------//
//***** Print *****//
int print(float yb, int color)
{
setcolor(color);
setfillstyle(1,color);
pieslice(x0,yb+200,0,360,20);
y =x1;
h = yb + 200 - 20;
do {
x = sin(y);
putpixel(x0-x*w,y0 + y*h*0.024,color);
y += dx;
} while(y <= x2);
return 0;
}
//------------------------------------------------------------------------//
//***** Print screensaver *****//
int screensaver()
{
int x=160,y=100;
setcolor(WHITE);
settextstyle(2,HORIZ_DIR,6);
outtextxy(x-5,y, " Rozrahunkovo-grafichna robota");
outtextxy(x,y+20,"studenta I kursu TEF grupy TV-81");
outtextxy(x,y+40," Krasnogolovcja A.M.");
settextstyle(2,HORIZ_DIR,4);
outtextxy(x+60,y+300," press any key to continue");
while(bioskey(1)==0);
return 0;
}