sinus.cpp
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "sinus.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define aantalperioden 4
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
X=1;
Y=30;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
float H;
int pixelperperiode=Form1->Width/aantalperioden;
H=2*M_PI*(float)X/(float)pixelperperiode;
Canvas->MoveTo(X,Y-floor(sin(H)*30+0.5));
X++;
H=2*M_PI*(float)X/(float)pixelperperiode;
Canvas->LineTo(X,Y-floor(sin(H)*30+0.5));
X++;
if (X>=Form1->Width)X=1;
}
//---------------------------------------------------------------------------
sinus.h
Code:
//---------------------------------------------------------------------------
#ifndef sinusH
#define sinusH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTimer *Timer1;
void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
public: // User declarations
int X;
int Y;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
En zet de timer-interval op 250, werkt prima
(maak een leeg projectje aan, met de unit sinus.cpp.. de header maakt ie autmatisch aan, en noem het project zelf anders dan 'sinus'.. zet een timer op je form, kopieer dan de inhoud).