#include<iostream.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
float points[3][13] = {{20,20,15,20,20,40,55,100,125,100,55,40,20 },{50,40,35,30,20,30,20,20,35,50,50,40,50 },{1,1,1,1,1,1,1,1,1,1,1,1,1 }};
points1[3][16]={{20,60,100,140,180,220,260,300,340,380,420,460,500,540,580,620},{400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
points2[3][16]={{0,40,80,120,160,200,240,280,320,360,400,440,480,520,560,600},{425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
class bomb
{
private:
float pi;
public:
bomb();
void myline(float x1, float y1 , float x2 , float y2, int c);
void b_move(int a , int b);
void rotate(float an , float x, float y);
void b_draw(int c);
};
void bomb::bomb()
{
pi = 4*tan(1);
b_draw(15);
}
void bomb::myline(float x1, float y1 , float x2 , float y2, int c )
{
float y;
if ((x2-x1)==0 ||(x2<x1) ||(y2<y1)) line( x1 , y1 , x2 , y2);
else
{
float m = (y2-y1)/(x2-x1);
float b = y2-m*x2;
for (float x = x1 ; x<=x2 ; x+=0.01)
{
y = m * x +b;
putpixel(x,y,c);
}
}
}
void bomb::b_draw(int c)
{
for(float a = 0 ; a<12 ; a++)
myline(points[0][a],points[1][a],points[0][a+1],points[1][a+1], c);
}
void bomb::b_move (int a, int b)
{
float newpoints[3][13];
int t[3][3] ={{1,0,a},{0,1,b},{0,0,1}};
for (int i =0 ; i <3 ;i++)
for (int j = 0 ; j<13 ; j++)
{
newpoints[i][j] = 0;
for (int k =0 ; k<3 ; k++)
newpoints[i][j] += t[i][k]*points[k][j];
}
for(i =0 ; i<3 ; i++)
for(j =0 ; j<13; j++)
points[i][j] = newpoints[i][j];
}
void bomb::rotate(float an , float x , float y)
{
float angle , tx , ty ;
angle = an *(22.0/7.0)/180.0;
for (int i = 0 ; i<11 ; i++)
{
tx = points[0][i];
ty = points[1][i];
points[0][i] = (tx-x)*cos(angle)-(ty-y)*sin(angle)+y;
points[1][i] = (tx-x)*sin(angle)+(ty-y)*cos(angle)+x;
}
}
void w_draw(float xc , float yc , float r)
{
for (float x =-r ; x<=r ; x+=0.01)
{
float y = sqrt(r*r - x*x);
putpixel(x+xc , yc+y , 9);
}
}
void wave()
{
for(int k = 0 ; k<16 ; k++)
w_draw(points1[0][k],points1[1][k],20);
for(int j = 0 ; j<16 ; j++)
w_draw(points2[0][j],points2[1][j],20);
}
void main()
{
int gd = DETECT , gm ;
initgraph(&gd , &gm , "C:\\Red\Language\\TC\\BGI");
int ec = graphresult();
if (ec !=0)
{
cout<<"Graph Error "<<grapherrormsg(ec);
getch();
exit(0);
}
wave();
bomb act;
do
{
delay(200);
act.b_draw(15);
setcolor(0);
act.b_draw(0);
act.b_move(10,20);
act.rotate(5, points[0][5], points[1][5]);
setcolor(15);
}
while(!kbhit());
getch();
closegraph();
}