Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.18 KB | None | 0 0
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. //  масштаб для большей наглядности
  3. const ms = 50;
  4. var
  5.   a: Integer;
  6.   x0, y0: Integer;
  7.   x, y : Real;
  8. begin
  9.   // очищаем полотно
  10.   image1.Canvas.Pen.Color := clWhite;
  11.   image1.Canvas.Rectangle(0,0,ClientWidth, ClientHeight);
  12.   // получаем значение а из поля для ввода
  13.   a:= StrToInt(Edit1.Text);
  14.  
  15.   //  рисуем оси координат
  16.   x0 := image1.Width div 2;
  17.   y0 := image1.Height div 2;
  18.  
  19.   image1.Canvas.Pen.Color := clBlack;
  20.   image1.Canvas.MoveTo(x0, 0);
  21.   image1.Canvas.LineTo(x0, ClientHeight);
  22.   image1.Canvas.MoveTo(0, y0);
  23.   image1.Canvas.LineTo(ClientWidth, y0);
  24.  
  25.   //  рисуем график
  26.   image1.Canvas.Pen.Color := clBlue;
  27.   x:=-10;
  28.   image1.Canvas.MoveTo(Trunc(x*ms+x0),Trunc(y*ms+y0));
  29.   repeat
  30.     x:=x+0.1;
  31.     if x = 0 then
  32.       y:=1
  33.     else
  34.       //  минус у нас т.к. оси координат компьютерные перевёрнуты и мы хотим избавиться от этого
  35.       y:=-sin(a*x)/x;
  36.     image1.Canvas.LineTo(Trunc(x*ms+x0),Trunc(y*ms+y0));
  37.   until x >= 10;
  38. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement