![]() Главная страница Случайная страница КАТЕГОРИИ: АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника |
Код событий в файле Unit_Graphics_Interface.cpp
//--------------------------------------------------------------------------- __fastcall TForm_Main:: TForm_Main(TComponent* Owner) : TForm(Owner) { Graphic = new GraphicsClass; } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: FormDestroy(TObject *Sender) { if(Graphic! = NULL)delete Graphic; } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Button_Draw_AxesClick(TObject *Sender) { Graphic-> DrawAxis(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: TrackBar_Scale_XChange(TObject *Sender) { Edit_Scale_X-> Text = TrackBar_Scale_X-> Position; Graphic-> SetDeltaX(TrackBar_Scale_X-> Position); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //---------------------------------------------------------------------------
void __fastcall TForm_Main:: TrackBar_Scale_YChange(TObject *Sender) { Edit_Scale_Y-> Text = TrackBar_Scale_Y-> Position; Graphic-> SetDeltaY(TrackBar_Scale_Y-> Position); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: ComboBox_Formula_Coord_XChange(TObject *Sender) { Graphic-> SetXKind(ComboBox_Formula_Coord_X-> ItemIndex); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: ComboBox_Formula_Coord_YChange(TObject *Sender) { Graphic-> SetYKind(ComboBox_Formula_Coord_Y-> ItemIndex); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Edit_Coord_X_Coeff_aChange(TObject *Sender) { if (Edit_Coord_X_Coeff_a-> Text == " ") Edit_Coord_X_Coeff_a-> Text = " 0"; Graphic-> SetAX(Edit_Coord_X_Coeff_a-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Edit_Coord_X_Coeff_bChange(TObject *Sender) { if (Edit_Coord_X_Coeff_b-> Text == " ") Edit_Coord_X_Coeff_b-> Text = " 1"; Graphic-> SetBX(Edit_Coord_X_Coeff_b-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Edit_Coord_X_Coeff_cChange(TObject *Sender) { if (Edit_Coord_X_Coeff_c-> Text == " ") Edit_Coord_X_Coeff_c-> Text = " 0"; Graphic-> SetBX(Edit_Coord_X_Coeff_c-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Edit_Coord_Y_Coeff_aChange(TObject *Sender) { if (Edit_Coord_Y_Coeff_a-> Text == " ") Edit_Coord_Y_Coeff_a-> Text = " 0"; Graphic-> SetBX(Edit_Coord_Y_Coeff_a-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Edit_Coord_Y_Coeff_bChange(TObject *Sender) { /* TEdit* edit = (TEdit*)Sender; if (edit-> Text == " ") edit-> Text = " 0"; Graphic-> SetBX(edit-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); */
if (Edit_Coord_Y_Coeff_b-> Text == " ") Edit_Coord_Y_Coeff_b-> Text = " 1"; Graphic-> SetBX(Edit_Coord_Y_Coeff_b-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //--------------------------------------------------------------------------- void __fastcall TForm_Main:: Edit_Coord_Y_Coeff_cChange(TObject *Sender) { if (Edit_Coord_Y_Coeff_c-> Text == " ") Edit_Coord_Y_Coeff_c-> Text = " 0"; Graphic-> SetBX(Edit_Coord_Y_Coeff_c-> Text.ToDouble()); Graphic-> DrawAxis(); Graphic-> DrawGraphic(); } //---------------------------------------------------------------------------
4. Дополните код Unit_graphics_interface.h объвлением класса Graphic (выделено полужирным шрифтом): //--------------------------------------------------------------------------- #ifndef Unit_graphics_interfaceH #define Unit_graphics_interfaceH //--------------------------------------------------------------------------- #include < Classes.hpp> #include < Controls.hpp> #include < StdCtrls.hpp> #include < Forms.hpp> #include < ComCtrls.hpp> #include < ExtCtrls.hpp> //--------------------------------------------------------------------------- class GraphicsClass;
class TForm_Main: public TForm { __published: // IDE-managed Components TPaintBox *PaintBox_Output; TComboBox *ComboBox_Formula_Coord_X; TStaticText *StaticText1; TEdit *Edit_Coord_X_Coeff_a; TEdit *Edit_Coord_X_Coeff_b; TStaticText *StaticText2; TStaticText *StaticText3; TStaticText *StaticText4; TComboBox *ComboBox_Formula_Coord_Y; TEdit *Edit_Coord_Y_Coeff_a; TEdit *Edit_Coord_Y_Coeff_b; TStaticText *StaticText5; TStaticText *StaticText6; TTrackBar *TrackBar_Scale_X; TTrackBar *TrackBar_Scale_Y; TButton *Button_Draw_Axes; TStaticText *StaticText7; TStaticText *StaticText8; TEdit *Edit_Scale_X; TEdit *Edit_Scale_Y; TEdit *Edit_Coord_X_Coeff_c; TStaticText *StaticText9; TStaticText *StaticText10; TEdit *Edit_Coord_Y_Coeff_c; void __fastcall Button_Draw_AxesClick(TObject *Sender); void __fastcall ComboBox_Formula_Coord_XChange(TObject *Sender); void __fastcall ComboBox_Formula_Coord_YChange(TObject *Sender); void __fastcall TrackBar_Scale_XChange(TObject *Sender); void __fastcall TrackBar_Scale_YChange(TObject *Sender); void __fastcall Edit_Coord_X_Coeff_aChange(TObject *Sender); void __fastcall Edit_Coord_X_Coeff_bChange(TObject *Sender); void __fastcall Edit_Coord_X_Coeff_cChange(TObject *Sender); void __fastcall Edit_Coord_Y_Coeff_aChange(TObject *Sender); void __fastcall Edit_Coord_Y_Coeff_bChange(TObject *Sender); void __fastcall Edit_Coord_Y_Coeff_cChange(TObject *Sender); void __fastcall FormDestroy(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm_Main(TComponent* Owner); GraphicsClass* Graphic; }; //--------------------------------------------------------------------------- extern PACKAGE TForm_Main *Form_Main; //--------------------------------------------------------------------------- #endif
5. Создайте новый файл File-> New-> Unit, сохраните его как Unit_graphics_draw.cpp, убедитесь, что файл появился в менеджере проектов View-> ProjectManager. Выполните File-> Use Unit, подключив Unit_graphics_interface.h. Переключитесь на Unit_graphics_interface.cpp и подключите аналогично Unit_graphics_draw.h
6. Заполните код Unit_graphics_draw.h. //---------------------------------------------------------------------------
#ifndef Unit_graphics_drawH #define Unit_graphics_drawH //--------------------------------------------------------------------------- class GraphicsClass; class GraphicsClass { private: int xmax, ymax; int xmid, ymid; int XKind, YKind; double X, Y; double deltaX, deltaY; double a_x, b_x, c_x, a_y, b_y, c_y; public: GraphicsClass(); void DrawAxis(); void DrawGraphic(); void SetXKind(int xkind); void SetYKind(int ykind); void SetAX(double ax); void SetBX(double bx); void SetCX(double cx); void SetAY(double ay); void SetBY(double by); void SetCY(double cy); void SetDeltaX(double dX); void SetDeltaY(double dY); };
#endif
6. Заполните код Unit_graphics_draw.cpp. //--------------------------------------------------------------------------- #pragma hdrstop
#include " Unit_graphics_draw.h" #include " Unit_draw_interface.h" #include " math.h" //---------------------------------------------------------------------------
#pragma package(smart_init)
//--------------------------------------------------------------------------- GraphicsClass:: GraphicsClass() { xmax = 681; ymax = 465; xmid = xmax / 2; ymid = ymax / 2; deltaX = 10; deltaY = 10; a_x = 1; b_x = 1; c_x = 0; a_y = 1; b_y = 1; c_y = 0; XKind = 0; YKind = 0; } //--------------------------------------------------------------------------- void GraphicsClass:: DrawAxis() { Form_Main-> PaintBox_Output-> Repaint(); Form_Main-> PaintBox_Output-> Canvas-> MoveTo(1, ymid); Form_Main-> PaintBox_Output-> Canvas-> LineTo(xmax, ymid); Form_Main-> PaintBox_Output-> Canvas-> MoveTo(xmid, 1); Form_Main-> PaintBox_Output-> Canvas-> LineTo(xmid, ymax);
for (int i = 0; i < = xmax / deltaX; i++) { Form_Main-> PaintBox_Output-> Canvas-> MoveTo(xmid + i * deltaX, ymid - 1); Form_Main-> PaintBox_Output-> Canvas-> LineTo(xmid + i * deltaX, ymid + 2); Form_Main-> PaintBox_Output-> Canvas-> MoveTo(xmid - i * deltaX, ymid - 1); Form_Main-> PaintBox_Output-> Canvas-> LineTo(xmid - i * deltaX, ymid + 2); } for (int i = 0; i < = ymax / deltaY; i++) { Form_Main-> PaintBox_Output-> Canvas-> MoveTo(xmid - 1, ymid + i * deltaY); Form_Main-> PaintBox_Output-> Canvas-> LineTo(xmid + 2, ymid + i * deltaY); Form_Main-> PaintBox_Output-> Canvas-> MoveTo(xmid - 1, ymid - i * deltaY); Form_Main-> PaintBox_Output-> Canvas-> LineTo(xmid + 2, ymid - i * deltaY); } } //--------------------------------------------------------------------------- void GraphicsClass:: DrawGraphic() { for (int t = -1000; t < = 1000; t++) { switch(XKind) { case 0: X = a_x; break; case 1: X = a_x * 0.01 * t + b_x; break; case 2: if (! (b_x < 0 & & t == 0)) X = a_x * (pow(0.01 * t, b_x) + c_x); break; case 3: X = a_x * sin(b_x * 0.01 * t + c_x); break; case 4: X = a_x * cos(b_x * 0.01 * t + c_x); break; case 5: X = a_x * tan(b_x * 0.01 * t + c_x); break; case 6: if (b_x * 0.01 * t + c_x! = 0) X = a_x / tan(b_x * 0.01 * t + c_x); break; case 7: X = a_x * exp(b_x * 0.01 * t + c_x); break; case 8: X = a_x * sin(b_x * 0.01 * t) * sin(c_x * 0.01 * t); break; case 9: X = a_x * sin(b_x * 0.01 * t) * cos(c_x * 0.01 * t); break; case 10: X = a_x * cos(b_x * 0.01 * t) * cos(c_x * 0.01 * t); break; case 11: X = a_x * exp(b_x * 0.01 * t) * sin (c_x * 0.01 * t); break; }; switch(YKind) { case 0: Y = a_y; break; case 1: Y = a_y * 0.01 * t + b_y; break; case 2: if (! (b_y < 0 & & t == 0)) Y = a_y * (pow(0.01 * t, b_y) + c_y); break; case 3: Y = a_y * sin(b_y * 0.01 * t + c_y); break; case 4: Y = a_y * cos(b_y * 0.01 * t + c_y); break; case 5: Y = a_y * tan(b_y * 0.01 * t + c_y); break; case 6: if (b_y * 0.01 * t + c_y! = 0) Y = a_y / tan(b_y * 0.01 * t + c_y); break; case 7: Y = a_y * exp(b_y * 0.01 * t + c_y); break; case 8: Y = a_y * sin(b_y * 0.01 * t) * sin(c_y * 0.01 * t); break; case 9: Y = a_y * sin(b_y * 0.01 * t) * cos(c_y * 0.01 * t); break; case 10: Y = a_y * cos(b_y * 0.01 * t) * cos(c_y * 0.01 * t); break; case 11: Y = a_y * exp(b_y * 0.01 * t) * sin (c_y * 0.01 * t); break; //https://trivialcoding.ru }; Form_Main-> PaintBox_Output-> Canvas-> Pixels[xmid + X * deltaX][ymid - Y * deltaY] = clGreen; } } //--------------------------------------------------------------------------- void GraphicsClass:: SetXKind(int xkind) { XKind = xkind; } //--------------------------------------------------------------------------- void GraphicsClass:: SetYKind(int ykind) { YKind = ykind; } //--------------------------------------------------------------------------- void GraphicsClass:: SetAX(double ax) { a_x = ax; } //--------------------------------------------------------------------------- void GraphicsClass:: SetBX(double bx) { b_x = bx; } //--------------------------------------------------------------------------- void GraphicsClass:: SetCX(double cx) { c_x = cx; } //--------------------------------------------------------------------------- void GraphicsClass:: SetAY(double ay) { a_y = ay; } //--------------------------------------------------------------------------- void GraphicsClass:: SetBY(double by) { b_y = by; } //--------------------------------------------------------------------------- void GraphicsClass:: SetCY(double cy) { c_y = cy; } //--------------------------------------------------------------------------- void GraphicsClass:: SetDeltaX(double dX) { deltaX = dX; } //--------------------------------------------------------------------------- void GraphicsClass:: SetDeltaY(double dY) { deltaY = dY; } //--------------------------------------------------------------------------- 7. Откомпилируйте проект, сохраните и запустите. 8. Выполните дополнительные задания преподавателя.
|