hicolor.pp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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: IPTCConsole;
  15. surface: IPTCSurface;
  16. format: IPTCFormat;
  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 := TPTCConsoleFactory.CreateNew;
  26. { create format }
  27. format := TPTCFormatFactory.CreateNew(16, $F800, $07E0, $001F);
  28. { open the console }
  29. console.open('HiColor example', format);
  30. { create surface matching console dimensions }
  31. surface := TPTCSurfaceFactory.CreateNew(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. if Assigned(console) then
  67. console.close;
  68. end;
  69. except
  70. on error: TPTCError do
  71. { report error }
  72. error.report;
  73. end;
  74. end.