hicolor.pp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {
  2. Ported to FPC by Nikolay Nikolov ([email protected])
  3. }
  4. {
  5. HiColor 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 HiColorExample;
  10. {$MODE objfpc}
  11. uses
  12. ptc;
  13. var
  14. console: TPTCConsole = nil;
  15. surface: TPTCSurface = nil;
  16. format: TPTCFormat = nil;
  17. pixels: PUint16;
  18. width, height: Integer;
  19. i: Integer;
  20. x, y, r, g, b: Integer;
  21. begin
  22. try
  23. try
  24. { create console }
  25. console := TPTCConsole.Create;
  26. { create format }
  27. format := TPTCFormat.Create(16, $F800, $07E0, $001F);
  28. { open the console }
  29. console.open('HiColor 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. { lock surface }
  36. pixels := surface.lock;
  37. try
  38. { get surface dimensions }
  39. width := surface.width;
  40. height := surface.height;
  41. { draw random pixels }
  42. for i := 1 to 100 do
  43. begin
  44. { get random position }
  45. x := Random(width);
  46. y := Random(height);
  47. { get random color }
  48. r := Random(256);
  49. g := Random(256);
  50. b := Random(256);
  51. { draw color [r,g,b] at position [x,y] }
  52. pixels[x + y * width] := ((r and $00F8) shl 8) or
  53. ((g and $00FC) shl 3) or
  54. ((b and $00F8) shr 3);
  55. end;
  56. finally
  57. { unlock surface }
  58. surface.unlock;
  59. end;
  60. { copy to console }
  61. surface.copy(console);
  62. { update console }
  63. console.update;
  64. end;
  65. finally
  66. console.close;
  67. console.Free;
  68. surface.Free;
  69. format.Free;
  70. end;
  71. except
  72. on error: TPTCError do
  73. { report error }
  74. error.report;
  75. end;
  76. end.