//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "Unit1.h" #include #include #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------GLOBAL VARIABLES int X, Y; POINT point; POINT nextpoint; POINT endpoint[32]; POINT midpoint[31]; POINT compass; double radians[31]; double degrees[31]; double degreesDifference[31]; double amplitude[31]; double realWindDirection; double windDegrees; double compassDirection; double oldCompassDirection; double theta; double maxamp; double waveheight; int down; //--------------------------------------------------------------------COLOR RAMP int colorRamp (int range, int value) { if (range==0) range=1; int pixelDistanceAlongPath = (value*1792)/range; int red, green, blue; if (pixelDistanceAlongPath < 256) { red=0; green=0; blue=pixelDistanceAlongPath; } else if (pixelDistanceAlongPath < 512) { red=0; green=pixelDistanceAlongPath-256; blue=255; } else if (pixelDistanceAlongPath < 768) { red=0; green=255; blue=255-(pixelDistanceAlongPath-512); } else if (pixelDistanceAlongPath < 1024) { red=(pixelDistanceAlongPath-768); green=255; blue=0; } else if (pixelDistanceAlongPath < 1280) { red= 255; green= 255-(pixelDistanceAlongPath-1024); blue=0; } else if (pixelDistanceAlongPath < 1536) { red=255; green=0; blue=pixelDistanceAlongPath-1280; } else { red=255; green=pixelDistanceAlongPath-1536; blue=255; } return (RGB(red,green,blue)); } //----------------------------------------------------- PLOT STATIC INFORMATION void plotStaticInformation () { // connect all the endpoints... Form1->Canvas->Pen->Color=clBlack; Form1->Canvas->MoveTo(endpoint[0].x, endpoint[0].y+down); for (int i=1; i<32; i++) { Form1->Canvas->LineTo(endpoint[i].x, endpoint[i].y+down); } // put a red dot on all the midpoints... for (int i=0; i<31; i++) { Form1->Canvas->Pen->Color=clBlack; Form1->Canvas->Brush->Color=clRed; Form1->Canvas->Ellipse(midpoint[i].x-2, midpoint[i].y-2+down, midpoint[i].x+2, midpoint[i].y+2+down); } // put a white dot on all the endpoints... for (int i=0; i<32; i++) { Form1->Canvas->Pen->Color=clWhite; Form1->Canvas->Brush->Color=clWhite; Form1->Canvas->Ellipse(endpoint[i].x-1, endpoint[i].y-1+down, endpoint[i].x+1, endpoint[i].y+1+down); } // 1st write the bearing in radians to the right of the midpoints... for (int i=0; i<31; i++) { Form1->Canvas->Pen->Color=clBlack; Form1->Canvas->Brush->Color=clRed; Form1->Canvas->TextOut(midpoint[i].x+20, midpoint[i].y-5+down, radians[i]); } Form1->Canvas->TextOut(midpoint[30].x+20, midpoint[30].y-5+down+25,"Radians"); // 2nd write the bearing in degrees to the right of the bearing in radians for (int i=0; i<31; i++) { Form1->Canvas->Pen->Color=clBlack; Form1->Canvas->Brush->Color=clLime; Form1->Canvas->TextOut(midpoint[i].x+130, midpoint[i].y-5+down, degrees[i]); } Form1->Canvas->TextOut(midpoint[30].x+130, midpoint[30].y-5+down+25,"Degrees"); } //-----------------------------------------------------------------COMPUTE void compute(void) { Application->ProcessMessages(); // calculate wave amplitude maxamp=0; // 3rd write difference to the right of the angle in degrees for (int i=0; i<31; i++) { degreesDifference[i] = (windDegrees-degrees[i]); Form1->Canvas->Pen->Color=clRed; Form1->Canvas->Brush->Color=clYellow; Form1->Canvas->TextOut(midpoint[i].x+235, midpoint[i].y-5+down, degreesDifference[i]); theta = (degreesDifference[i] * M_PI)/80; amplitude[i]=(.5*waveheight*(cos(theta/2.25))); if (maxampCanvas->TextOut(midpoint[30].x+235, midpoint[30].y-5+down+25,"Difference"); Form1->EditBoxMaxAmp->Text=maxamp; // render line segments Form1->Canvas->Pen->Width=5; for (int i=0; i<31; i++) { Form1->Canvas->MoveTo(endpoint[i].x, endpoint[i].y+down); Form1->Canvas->Pen->Color=static_cast (colorRamp(int(maxamp),int(amplitude[i]))); Form1->Canvas->LineTo(endpoint[i+1].x, endpoint[i+1].y+down); } Form1->Canvas->Pen->Width=1; // 4th write the amplitude to the right of the angle in degees for (int i=0; i<31; i++) { Form1->Canvas->Pen->Color=clRed; Form1->Canvas->Brush->Color=clAqua; Form1->Canvas->TextOut(midpoint[i].x+345, midpoint[i].y-5+down, amplitude[i]); } Form1->Canvas->TextOut(midpoint[30].x+345, midpoint[30].y-5+down+25,"Wave Height"); } //----------------------------------------------------------------------------- void __fastcall TForm1::ButtonPlotBeachAnglesClick(TObject *Sender) { plotStaticInformation(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormShow(TObject *Sender) { // sets the coordinates of each end of each line segment endpoint[0].x=60; endpoint[0].y=0; endpoint[1].x=65; endpoint[1].y=3; endpoint[2].x=92; endpoint[2].y=36; endpoint[3].x=103; endpoint[3].y=38; endpoint[4].x=114; endpoint[4].y=50; endpoint[5].x=149; endpoint[5].y=99; endpoint[5].x=172; endpoint[5].y=140; endpoint[6].x=171; endpoint[6].y=145; endpoint[7].x=178; endpoint[7].y=147; endpoint[8].x=196; endpoint[8].y=173; endpoint[9].x=211; endpoint[9].y=197; endpoint[10].x=224; endpoint[10].y=219; endpoint[11].x=237; endpoint[11].y=248; endpoint[12].x=240; endpoint[12].y=265; endpoint[13].x=244; endpoint[13].y=276; endpoint[14].x=252; endpoint[14].y=308; endpoint[15].x=256; endpoint[15].y=311; endpoint[16].x=264; endpoint[16].y=341; endpoint[17].x=275; endpoint[17].y=391; endpoint[18].x=278; endpoint[18].y=414; endpoint[19].x=281; endpoint[19].y=426; endpoint[20].x=283; endpoint[20].y=456; endpoint[21].x=277; endpoint[21].y=471; endpoint[22].x=270; endpoint[22].y=472; endpoint[23].x=260; endpoint[23].y=480; endpoint[24].x=263; endpoint[24].y=492; endpoint[25].x=264; endpoint[25].y=502; endpoint[26].x=273; endpoint[26].y=512; endpoint[27].x=279; endpoint[27].y=526; endpoint[28].x=282; endpoint[28].y=557; endpoint[29].x=284; endpoint[29].y=561; endpoint[30].x=282; endpoint[30].y=570; endpoint[31].x=285; endpoint[31].y=575; // finds the midpoint of each line segment for (int i=0; i<31; i++) { midpoint[i].x=(endpoint[i].x+endpoint[i+1].x)/2; midpoint[i].y=(endpoint[i].y+endpoint[i+1].y)/2; } // finds the bearing of each line segment in radians // zero radians points right and increases clockwise for (int i=0; i<31; i++) { radians[i]=(atan2((endpoint[i+1].y-endpoint[i].y), (endpoint[i+1].x-endpoint[i].x))); } // finds the bearing of each line segment in degrees for (int i=0; i<31; i++) { degrees[i]=RadToDeg(radians[i]); } // sets the position of the compass on the screen compass.x=90; compass.y=260; // sets the Y offset down down = 20; } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBarWaveHeightChange(TObject *Sender) { waveheight=Form1->TrackBarWaveHeight->Position; Form1->EditBoxWaveHeight->Text=waveheight; compute(); } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBarWindDirectionChange(TObject *Sender) { // write information in edit boxes windDegrees = Form1->TrackBarWindDirection->Position; Form1->EditBoxWindDirectionRadians->Text = float(DegToRad(windDegrees)); Form1->EditBoxWindDirectionDegrees->Text= windDegrees; compassDirection=DegToRad(360-windDegrees); // COMPASS display direction Form1->Canvas->Brush->Color=clBlue; Form1->Canvas->Pen->Color=clBlue; // COMPASS erase old needle head Form1->Canvas->Pen->Color=clSilver; Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->LineTo (compass.x-50*sin(oldCompassDirection),compass.y-50*cos(oldCompassDirection)); Form1->Canvas->Pen->Width = 3; Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->LineTo (compass.x-35*sin(oldCompassDirection),compass.y-35*cos(oldCompassDirection)); Form1->Canvas->Pen->Width = 1; // COMPASS erase old needle tail Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->LineTo (compass.x+50*sin(oldCompassDirection),compass.y+50*cos(oldCompassDirection)); Form1->Canvas->Pen->Width = 3; Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->LineTo (compass.x+35*sin(oldCompassDirection),compass.y+35*cos(oldCompassDirection)); Form1->Canvas->Pen->Width = 1; // COMPASS render new needle HEAD RED Form1->Canvas->Pen->Color=clRed; Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->LineTo (compass.x-50*sin(compassDirection), compass.y-50*cos(compassDirection)); Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->Pen->Width = 3; Form1->Canvas->LineTo (compass.x-35*sin(compassDirection), compass.y-35*cos(compassDirection)); Form1->Canvas->Pen->Width = 1; // COMPASS render new needle TAIL BLACK Form1->Canvas->Pen->Color=clBlack; Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->LineTo (compass.x+50*sin(compassDirection), compass.y+50*cos(compassDirection)); Form1->Canvas->MoveTo(compass.x, compass.y); Form1->Canvas->Pen->Width = 3; Form1->Canvas->LineTo (compass.x+35*sin(compassDirection), compass.y+35*cos(compassDirection)); Form1->Canvas->Pen->Width = 1; // COMPASS render new needle pivot BLACK AND WHITE Form1->Canvas->Pen->Color=clBlack; Form1->Canvas->Brush->Color=clWhite; Form1->Canvas->Ellipse (compass.x-6, compass.y-6, compass.x+6, compass.y+6); oldCompassDirection=compassDirection; // compute compute(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonClearClick(TObject *Sender) { Refresh(); } //---------------------------------------------------------------------------