VC有直接可以畫正弦波的函式嗎?應該沒有吧,雖然我沒學過VC..^^"
畫出正弦波重點應該在於正弦波公式,我用BCB寫了一個可調振幅的,供你參考,
希望對你有幫助
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
#include <math.h> //必要的檔頭
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//振幅
void TForm1::drawSinWave(int Amplify,TImage *Image)
{
const float PI = 3.1415926;
TRect Rect;
Rect = Image->ClientRect;
int PositionZero = Rect.Height()/2; Image->Canvas->Brush->Color = (TColor)RGB(255,255,255);
Image->Canvas->FillRect(Rect); Image->Canvas->PenPos = TPoint(0,PositionZero);
Image->Canvas->LineTo(Rect.Width(),PositionZero); Image->Canvas->PenPos = TPoint(0,PositionZero);//畫筆的位址歸0
//----- 畫出正弦波 -----
for(int x = 0;x < 360;x++)//0~360度
{
int y = PositionZero-(Amplify*Rect.Height()/2/100)*sin(x*PI/180);//正弦偏移量
Image->Canvas->LineTo(x,y);
Image->Canvas->PenPos = TPoint(x,y);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
Label1->Caption =IntToStr(TrackBar1->Position) + String("%");
drawSinWave(TrackBar1->Position,Image1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
drawSinWave(TrackBar1->Position,Image1);
Label1->Caption = TrackBar1->Position;
}
拍謝^^哇係新手若問題很笨,請多多見諒 發表人 - taishyang 於 2003/10/30 15:27:59