clear.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. SysUtils, ptc;
  13. var
  14. console: TPTCConsole = nil;
  15. format: TPTCFormat = nil;
  16. surface: TPTCSurface = nil;
  17. width, height: Integer;
  18. x, y: Integer;
  19. size: Integer;
  20. area: TPTCArea = nil;
  21. color: TPTCColor = nil;
  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. try
  44. { setup clear area }
  45. area := TPTCArea.Create(x-size, y-size, x+size, y+size);
  46. { create random color }
  47. color := TPTCColor.Create(Random, Random, Random);
  48. { clear surface area with color }
  49. surface.clear(color, area);
  50. { copy to console }
  51. surface.copy(console);
  52. { update console }
  53. console.update;
  54. finally
  55. FreeAndNil(area);
  56. FreeAndNil(color);
  57. end;
  58. end;
  59. console.close;
  60. console.Free;
  61. surface.Free;
  62. format.Free;
  63. except
  64. on error: TPTCError do
  65. { report error }
  66. error.report;
  67. end;
  68. end.