clear.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {
  2. Ported to FPC by Nikolay Nikolov ([email protected])
  3. }
  4. {
  5. Clear example for OpenPTC 1.0 C++ Implementation
  6. Copyright (c) Glenn Fiedler ([email protected])
  7. This source code is in the public domain
  8. }
  9. Program ClearExample;
  10. {$MODE objfpc}
  11. Uses
  12. ptc;
  13. Var
  14. console : TPTCConsole;
  15. format : TPTCFormat;
  16. surface : TPTCSurface;
  17. width, height : Integer;
  18. x, y : Integer;
  19. size : Integer;
  20. area : TPTCArea;
  21. color : TPTCColor;
  22. Begin
  23. Try
  24. { create console }
  25. console := TPTCConsole.Create;
  26. { create format }
  27. format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
  28. { open the console }
  29. console.open('Clear example', format);
  30. { create surface matching console dimensions }
  31. surface := TPTCSurface.Create(console.width, console.height, format);
  32. { loop until a key is pressed }
  33. While Not console.KeyPressed Do
  34. Begin
  35. { get surface dimensions }
  36. width := surface.width;
  37. height := surface.height;
  38. { get random position }
  39. x := Random(width);
  40. y := Random(height);
  41. { get random area size }
  42. size := Random(width Div 8);
  43. { setup clear area }
  44. area := TPTCArea.Create(x-size, y-size, x+size, y+size);
  45. { create random color }
  46. color := TPTCColor.Create(Random, Random, Random);
  47. { clear surface area with color }
  48. surface.clear(color, area);
  49. { copy to console }
  50. surface.copy(console);
  51. { update console }
  52. console.update;
  53. area.Free;
  54. color.Free;
  55. End;
  56. console.close;
  57. console.Free;
  58. surface.Free;
  59. Except
  60. On error : TPTCError Do
  61. { report error }
  62. error.report;
  63. End;
  64. End.