coding Shift_JIS; // 文字コードの明示(文字化け予防) import Math; // 数学関数の使用に必要なライブラリの読み込み import GUI; // GUI画面の構築に必要なライブラリの読み込み import tool.Graph2D; // 2次元グラフ描画に必要なライブラリの読み込み // 以下、波のパラメータを格納する変数 double amplitude = 1.0; // 波の振幅(A) double wavelength = 1.0; // 波の波長(λ) double period = 1.0; // 波の周期(T) // グラフ範囲や点数、時間刻みなどの設定変数 const int N = 1024; // グラフの点数(細かいほど滑らか) const double X_MIN = 0.0; // グラフのX軸の最小値 const double X_MAX = 4.0; // グラフのX軸の最大値 const double Y_MIN = -1.0; // グラフのY軸の最小値 const double Y_MAX = 1.0; // グラフのY軸の最大値 const double DT = 0.05; // 1ループごとの時間進行量(speed=1.0の時の値) const double DX = (X_MAX - X_MIN) / N; // 1頂点ごとのX軸進行量 // グラフに波のデータを渡すための座標値配列 double waveX[ N ]; // X座標の配列 double waveY[ N ]; // Y座標の配列 // GUI(設定画面)用の変数 int window; // ウィンドウのIDを格納する int periodSlider; // 周期設定スライダーのIDを格納する int wavelengthSlider; // 波長設定スライダーのIDを格納する int amplitudeSlider; // 振幅設定スライダーのIDを格納する int speedSlider; // アニメーション速度スライダーのIDを格納する int infoLabel; // 設定値を表示するラベルのIDを格納する int timeLabel; // 時刻表示ラベルのIDを格納する int resetButton; // 時刻リセットボタンのIDを格納する // その他の制御用変数 float speed = 1.0; // アニメーション速度 int graph; // グラフソフトのIDを格納する bool continuesLoop = true; // アニメーションON/OFF制御変数 double t; // 時刻変数 // ================================================== // 中心的な処理 - この関数は起動時に自動で実行されます // ================================================== void main( ){ // 波のパラメータの初期値を数値で入力するか尋ね、必要なら入力して設定 inputParameters(); // グラフを起動 createGraphWindow(); // GUI(設定画面)を構築 createSettingWindow(); t = 0.0; // 時刻を0に設定 // アニメーションのループ while( continuesLoop ) { // グラフのタイトルに時刻を表示する string roundedTime = round(t, 1, HALF_UP); // 時刻を小数点以下1桁に丸める setGraph2DTitle(graph, "t = " + roundedTime); // タイトルを「 t = 時刻 」に設定 // グラフソフトに渡す点列データの座標を計算 for( int i=0; i