include graphics include bios include math include dos include conio -

  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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#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;
}