}

Delphi.int.ru

| ?

: 672e4156 : : 6 2010, 13:57 (bizon_all)

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10. TFunc = function (x:real): real; //Ñîçäàåì òèï-ôóíêöèþ, äëÿ òîãî
  11. öè//÷òîáû èìÿ ôóíêöèè ìîæíî áûëî ïåðåäàâàòü â ïðîöåäóðó
  12. èè ìîæíî áûëî ïåðåäàâàòü â ïðîöåäóðó
  13. ïîñòðîåíèÿ ãðàôèêà.
  14.  
  15. TForm1 = class(TForm)
  16. Image1: TImage;
  17. Button1: TButton;
  18. Button2: TButton;
  19. Button3: TButton;
  20. procedure Button1Click(Sender: TObject);
  21. procedure Butto{ Private declarations };
  22. procedur{ Public declarations }TObject);
  23. private
  24. { Private declarations {$R *.dfm}
  25. { Public declarations }
  26. end;
  27.  
  28. var
  29. Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.dfm}
  34.  
  35. Function f(x:real):real;
  36. begin
  37. if x<>-3 then result:=(x+1)/(x+3);
  38. end;
  39.  
  40. Function f1(x:real):real;
  41. begin
  42. Result:=sin(x);
  43. end;
  44.  
  45. Function f2(x:real):real;
  46. begin
  47. res//Ïàðàìåòðû: f - ôóíêöèÿ, ãðàôèê êîòîðîé áóäåì ñòðîèòü.
  48. //a - íà÷àëüíîå çíà÷åíèå ïåðåìåííîé "x", b - êîíå÷íîå çíà÷åíèå
  49. öèÿ, ãðàô//Ñ - êàíâà, íà êîòîðîé áóäåì ðèñîâàòü.
  50. òü.
  51. //a - íà÷àëüíîå çíà÷åíèå ïåðåìåííîé "x", b - êîí{Ñ÷èòàåì ìàñøòàáû ïî îñÿì êîîðäèíàò, è ñðåäíåå çíà÷åíèå âûñîòû è
  52. øèðèíû êàíâû, ÷òîáû îòîáðàçèòü îñè êîîðäèíàò.}âàòü.
  53. var x,y,h,t: real;
  54. //øàã ïî x
  55. eal;
  56. sx,s// êîîðäèíàòû íà÷àëà êîîðäèíàòíûõ îñåé
  57. Ñ÷èòàåì ìàñøòàáû ïî îñÿì êîîðäèíàò, è ñðåäíåå çíà÷åíèå âûñîòû è
  58. øèðèíû êàíâû, ÷òîáû îòîáðàçèòü îñè êîîðäèíàò.}
  59. sx:= (c.ClipRect.Right)/(b-a); ////øàã ïî y
  60. x
  61. {çàëèâàåì âñþ êàíâó ñåðåáðÿíûì öâåòîì}à÷àëà êîîðäèíàòíûõ îñåé
  62. x0:=c.ClipRect.Right div 2;
  63. y0:=c.ClipRect{ðèñóåì ñåòêó}
  64. x:=a;
  65. max:=f(x);
  66. min:=max;
  67. while x<=b do
  68. begin
  69. y:=f(x);
  70. if y<min then min:=y;
  71. if y>max then max:=y;
  72. x:=x+h;
  73. end;
  74. sy:=c.ClipRect.Bottom/(max-min); //øàã ïî y
  75.  
  76. {çàëèâàåì âñþ êàíâó ñåðåáðÿíûì öâåòîì}
  77.  
  78. c.Brush.Color:=clSilver;
  79. c.FillRect(Re{ðèñóåì æåëòûì öâåòîì îñè êîîðäèíàò}ottom));
  80.  
  81. {ðèñóåì ñåòêó}
  82.  
  83. c.Pen.Style:=psdot;
  84. c.Pen.Color:=clblue;
  85. for i:=a to c.ClipRect.Right do
  86. begin
  87. c.MoveTo(round(i*sx),{ðèñóåì ñòðåëî÷êè}(round(i*sx),c.ClipRect.Right);
  88. end;
  89. for i:=a to c.ClipRect.Bottom do
  90. begin
  91. c.MoveTo(0,Round(i*sy));
  92. c.LineTo(c.ClipRect.Right,round(i*sy));
  93. end;
  94. {ðèñóåì æåëòûì öâåòîì îñ{íàäïèñè íà îñÿõ êîîðäèíàò}en.Style:=psSolid;
  95. c.Pen.Color:=clYellow;
  96. c.MoveTo(0,y0);
  97. c.LineTo(c{ðèñóåì ãðàôèê ôóíêöèè}c.MoveTo(x0,0);
  98. c.LineTo(x0,c.ClipRect.Bottom);
  99. {ðèñóåì ñòðåëî÷êè}
  100. c.MoveTo(x0,0); c.LineTo(x0-10,10);
  101. c.MoveTo(x0,0); c.LineTo(x0+10,10);
  102. c.MoveTo(c.ClipRect.Right,y0); c.LineTo(c.ClipRect.Right-10,y0-10);
  103. c.MoveTo(c.ClipRect.Right,y0); c.LineTo(c.ClipRect.Right-10,y0+10);
  104. {íàäïèñè íà îñÿõ êîîðäèíàò}
  105. c.TextOut(x0-10,10,'y');
  106. c.TextOut(c.ClipRect.Right-10,y0+10,'x');
  107. {ðèñó

:

»