demo05.pas 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. program demo05;
  2. {$I zglCustomConfig.cfg}
  3. uses
  4. {$IFDEF UNIX}
  5. cthreads,
  6. {$ENDIF}
  7. {$IfDef USE_ZENGL_STATIC}
  8. zgl_screen,
  9. zgl_window,
  10. zgl_timers,
  11. zgl_keyboard,
  12. zgl_fx,
  13. zgl_render_2d,
  14. zgl_primitives_2d,
  15. zgl_types,
  16. zgl_math_2d,
  17. zgl_utils
  18. {$Else}
  19. zglHeader
  20. {$EndIf}
  21. ;
  22. var
  23. calc : Integer;
  24. points : array[ 0..359 ] of zglTPoint2D;
  25. TimeStart : Byte = 0;
  26. procedure Init;
  27. var
  28. i : Integer;
  29. begin
  30. for i := 0 to 359 do
  31. begin
  32. points[ i ].X := 400 + m_Cos( i ) * ( 96 + random( 32 ) );
  33. points[ i ].Y := 300 + m_Sin( i ) * ( 96 + random( 32 ) );
  34. end;
  35. end;
  36. procedure Draw;
  37. var
  38. i : Integer;
  39. begin
  40. // RU: Устанавливаем цвет и альфу для каждой вершины.
  41. // EN: Set color and alpha for each vertex.
  42. fx2d_SetVCA( $FF0000, $00FF00, $0000FF, $FFFFFF, 255, 255, 255, 255 );
  43. // RU: Рисуем прямоугольник с заливкой(флаг PR2D_FILL) с использованием отдельных цветов для каждой вершины(флаг FX2D_VCA).
  44. // EN: Render filled rectangle(flag PR2D_FILL) and use different colors for each vertex(flag FX2D_VCA).
  45. pr2d_Rect( 0, 0, 800, 600, $000000, 255, FX2D_VCA or PR2D_FILL );
  46. // RU: Рисуем в центре экрана круг с радиусом 128 пиксела.
  47. // EN: Render circle in the center of screen with radius 128 pixels.
  48. pr2d_Circle( 400, 300, 128, $000000, 155, 32, PR2D_FILL );
  49. // RU: Рисуем линии внутри круга.
  50. // EN: Render lines inside the circle.
  51. for i := 0 to 359 do
  52. pr2d_Line( 400, 300, points[ i ].X, points[ i ].Y, $FFFFFF, 255 );
  53. // RU: Рисуем эллипсы с заливкой и без, со сглаженными контурами(флаг PR2D_SMOOTH).
  54. // EN: Render filled ellipses with smoothed edges(flag PR2D_SMOOTH).
  55. pr2d_Ellipse( 400 + 300, 300, 64, 256, $FFFFFF, 75, 64, PR2D_FILL or PR2D_SMOOTH );
  56. pr2d_Ellipse( 400 + 300, 300, 64, 256, $000000, 255, 32, PR2D_SMOOTH );
  57. pr2d_Ellipse( 400 - 300, 300, 64, 256, $FFFFFF, 75, 64, PR2D_FILL{ or PR2D_SMOOTH });
  58. pr2d_Ellipse( 400 - 300, 300, 64, 256, $000000, 255, 32, PR2D_SMOOTH );
  59. end;
  60. procedure Timer;
  61. begin
  62. INC( calc );
  63. if calc > 359 Then
  64. calc := 0;
  65. points[ calc ].X := 400 + m_Cos( calc ) * ( 96 + random( 32 ) );
  66. points[ calc ].Y := 300 + m_Sin( calc ) * ( 96 + random( 32 ) );
  67. end;
  68. Begin
  69. {$IFNDEF USE_ZENGL_STATIC}
  70. if not zglLoad( libZenGL ) Then exit;
  71. {$ENDIF}
  72. TimeStart := timer_Add( @Timer, 16, Start );
  73. zgl_Reg( SYS_LOAD, @Init );
  74. zgl_Reg( SYS_DRAW, @Draw );
  75. wnd_SetCaption(utf8_Copy('05 - Primitives'));
  76. zgl_Init();
  77. End.