WRITEFUN.PAS 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Uses CRT,GRAPH,Strcalc;
  2. Const
  3. Eps = 0.001;
  4. Del = 5000;
  5. Frames = 1000;
  6. Var
  7. Fn:string;
  8. LeftGr : real;
  9. RightGr : real;
  10. Procedure InitG;
  11. Var
  12. grDriver: Integer;
  13. grMode: Integer;
  14. i : integer;
  15. Begin
  16. grDriver := Detect;
  17. InitGraph(grDriver, grMode,'');
  18. { SetWriteMode(XORPut);}
  19. SetFillStyle(XHatchFill,Green);
  20. Bar(0,0,GetMaxX,GetMaxY);
  21. SetFillStyle(SolidFill,Black);
  22. Bar(100,50,540,450);
  23. SetColor(Red);
  24. Line(100,250,540,250);
  25. End;{InitG}
  26. {--------------------------------}
  27. Function Func(x: real): real;
  28. Var
  29. ret: real;
  30. Begin
  31. ret := StrFunc(fn,x);
  32. Func := ret;
  33. End;
  34. {-----------------------------}
  35. Procedure WriteGraph(l,r:real;Color:Integer);
  36. Var
  37. x,y : Integer;
  38. razmx,razmy,max,min: real;
  39. Begin
  40. Razmx := r-l;
  41. SetColor(Color);
  42. min := maxint;
  43. min := -maxint;
  44. for x := 1 to Frames do
  45. begin
  46. y := round(Func(l+(x/Frames)*razmx)*10);
  47. if y < min then min := y;
  48. if y > max then max := y
  49. end;
  50. razmy := max-min;
  51. MoveTo(100,250-Round(-200+((Func(l)-min)/razmy*400)));
  52. for x := 1 to Frames do
  53. begin
  54. Y:=Round(-200+((Func(l+(x/Frames)*razmx)-min)/razmy*400));
  55. LineTo(100+round(x/Frames*440),250-y);
  56. end;
  57. End;{WriteGraph}
  58. {---------------------------------}
  59. Begin
  60. Write('Enter function: ');
  61. ReadLn(fn);
  62. Read(LeftGr,RightGr);
  63. InitG;
  64. WriteGraph(leftGr,RightGR,Blue);
  65. ReadKey;
  66. CloseGraph;
  67. End.