.


:




:

































 

 

 

 


2




 

: : Unit1.cpp Timer.cpp, Project1.bpr Colori. bpr.

Button ( Standard), CheckBox ( Standard), ColorDialog ( Dialogs), Timer ( System) SpinEdit ( Samples).

. 1:

. 1.

 

:

 

Name
Form1 FormMain Caption Canvas
    Color clBlack
    Height  
    Width  
Button1 Button1 Caption Select Color
    Anchors ->akTop true
    Anchors ->akRight true
CheckBox1 CheckBox1 Caption Revers
    Font->Color clWhite
    Color clBlack
    Anchors ->akTop true
    Anchors ->akRight true
Timer1 Timer1 Interval  
SpinEdit1 SpinEdit1 Increment  
    MaxValue  
    MinValue  
    Value  
    Anchors ->akTop true
    Anchors ->akRight true
ColorDialog1 ColorDialog1    

 

. 2:

. 2.

 

.

Timer.h , , : //--------------------------------------------------

 

const int MaxPoints = 15;

struct TRPoint { float X, Y; };

class TFormMain: public TForm {

__published: // IDE-managed Components

private: // User declarations

TRPoint Points[MaxPoints];

float Rotation; //

int PointCount;

void __fastcall RotatePoints();

public: // User declarations

__fastcall TFormMain (TComponent* Owner);

};

//------------------------------------------------

Timer.cpp #include <math.h> : //-------------------------------------------------------

void __fastcall TFormMain::RotatePoints()

{

int RN=8; // all figures are in radians

const float M_2PI = 2 * M_PI;

float StepAngle = M_2PI / PointCount;

if (!CheckBox1->Checked) Rotation += M_PI / RN;

if (CheckBox1->Checked) Rotation -= M_PI / RN;

if (Rotation > StepAngle) Rotation -= StepAngle;

int i;

float j;

for (i = 0, j = Rotation; i < PointCount; i++, j += StepAngle)

{

Points[i].X = cos(j);

Points[i].Y = sin(j);

}

}

//------------------------------------------------------

FormMain 䳿 OnCreate: //-------------------------------------------------------

void __fastcall TFormMain::FormCreate(TObject *Sender)

{

Canvas->Pen->Color = clTeal;

Rotation = 0;

PointCount = MaxPoints;

RotatePoints();

}

//-------------------------------------------------------

FormMain 䳿 OnPaint: //------------------------------------------------------

void __fastcall TFormMain::FormPaint(TObject *Sender)

{

int radius;

int centerX = ClientWidth / 2;

int centerY = ClientHeight / 2;

if (centerX < centerY)

radius = centerX;

else radius = centerY;

Canvas->Ellipse(0, 0, radius*2, radius*2);

int i, j;

for (i = 0; i < PointCount; i++)

{

for (j = i + 1; j < PointCount; j++)

{

Canvas->MoveTo(radius + float(Points[i].X * radius), radius + float(Points[i].Y * radius));

Canvas->LineTo(radius + float(Points[j].X * radius), radius + float(Points[j].Y * radius));

}

}

}

//------------------------------------------------------

FormMain 䳿 OnResize: //--------------------------------------------------------

void __fastcall TFormMain::FormResize(TObject *Sender)

{

Invalidate();

}

//--------------------------------------------------------

Timer1 䳿 OnTimer: //-------------------------------------------------------

void __fastcall TFormMain::Timer1Timer(TObject *Sender)

{

RotatePoints();

Invalidate();

}

//-------------------------------------------------------

CSpinEdit1 䳿 OnChange: //------------------------------------------------------------

void __fastcall TFormMain::CSpinEdit1Change(TObject *Sender)

{

Timer1->Interval=CSpinEdit1->Value;

}

//-------------------------------------------------------------

Button1 䳿 OnClick: //--------------------------------------------------------

void __fastcall TFormMain::Button1Click(TObject *Sender)

{

if (ColorDialog1->Execute())

Canvas->Pen->Color = ColorDialog1->Color;

}

//--------------------------------------------------------

.

. ³ . 3:

 

. 3.

1. Canvas.

2. Canvas.

3. OnResize ?

4. ?

5. Invalidate()?





:


: 2015-10-01; !; : 323 |


:

:

, .
==> ...

1632 - | 1418 -


© 2015-2024 lektsii.org - -

: 0.014 .