hicolor.pp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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;
  15. surface : TPTCSurface;
  16. format : TPTCFormat;
  17. pixels : Pshort16;
  18. width, height : Integer;
  19. i : Integer;
  20. x, y, r, g, b : Integer;
  21. Begin
  22. format := Nil;
  23. surface := Nil;
  24. console := Nil;
  25. Try
  26. Try
  27. { create console }
  28. console := TPTCConsole.Create;
  29. { create format }
  30. format := TPTCFormat.Create(16, $F800, $07E0, $001F);
  31. { open the console }
  32. console.open('HiColor example', format);
  33. { create surface matching console dimensions }
  34. surface := TPTCSurface.Create(console.width, console.height, format);
  35. { loop until a key is pressed }
  36. While Not console.KeyPressed Do
  37. Begin
  38. { lock surface }
  39. pixels := surface.lock;
  40. Try
  41. { get surface dimensions }
  42. width := surface.width;
  43. height := surface.height;
  44. { draw random pixels }
  45. For i := 1 To 100 Do
  46. Begin
  47. { get random position }
  48. x := Random(width);
  49. y := Random(height);
  50. { get random color }
  51. r := Random(256);
  52. g := Random(256);
  53. b := Random(256);
  54. { draw color [r,g,b] at position [x,y] }
  55. pixels[x + y * width] := ((r And $00F8) Shl 8) Or
  56. ((g And $00FC) Shl 3) Or
  57. ((b And $00F8) Shr 3);
  58. End;
  59. Finally
  60. { unlock surface }
  61. surface.unlock;
  62. End;
  63. { copy to console }
  64. surface.copy(console);
  65. { update console }
  66. console.update;
  67. End;
  68. Finally
  69. console.close;
  70. console.Free;
  71. surface.Free;
  72. format.Free;
  73. End;
  74. Except
  75. On error : TPTCError Do
  76. { report error }
  77. error.report;
  78. End;
  79. End.