demo05.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. library demo05;
  2. {$I zgl_config.cfg}
  3. {$I zglCustomConfig.cfg}
  4. uses
  5. zgl_application,
  6. zgl_screen,
  7. zgl_window,
  8. zgl_timers,
  9. zgl_fx,
  10. zgl_render_2d,
  11. zgl_primitives_2d,
  12. zgl_primitives_2dEX,
  13. zgl_types,
  14. zgl_math_2d,
  15. gegl_color,
  16. zgl_utils;
  17. var
  18. calc : Integer;
  19. points : array[ 0..359 ] of zglTPoint2D;
  20. //dirRes : UTF8String {$IFNDEF MACOSX} = '../data/' {$ENDIF}; // определится с дирректориями для Android
  21. newColor: array[0..1] of LongWord;
  22. // RU: это для создания ломанных линий. Можно создать динамический массив и делать
  23. // линии с произвольным количеством точек.
  24. // EN: this is for creating broken lines. You can create a dynamic array and draw
  25. // lines with an arbitrary number of points.
  26. myPointArray: array[0..3] of zglTPoint2DColor;
  27. deltaX, deltaY: array [0..3] of Integer;
  28. procedure Init;
  29. var
  30. i : Integer;
  31. begin
  32. zgl_Enable( CORRECT_RESOLUTION );
  33. scr_CorrectResolution( 800, 600 );
  34. for i := 0 to 359 do
  35. begin
  36. points[ i ].X := 400 + m_Cos( i ) * ( 96 + random( 32 ) );
  37. points[ i ].Y := 300 + m_Sin( i ) * ( 96 + random( 32 ) );
  38. end;
  39. // Rus: устанавливаем новый цвет. Которого нет в списке стандартных. Все константы в gegl_color.
  40. // Eng: set a new color. Which is not in the standard list. All constants in gegl_color.
  41. newColor[0] := Color_FindOrAdd($0000009B);
  42. newColor[1] := Color_FindOrAdd($FFFFFF4B);
  43. myPointArray[0].X := 20;
  44. myPointArray[0].Y := 20;
  45. myPointArray[0].Color := cl_Red;
  46. myPointArray[1].X := wndWidth - 20;
  47. myPointArray[1].Y := 20;
  48. myPointArray[1].Color := cl_Blue;
  49. myPointArray[3].X := wndWidth - 80;
  50. myPointArray[3].Y := wndHeight - 20;
  51. myPointArray[3].Color := cl_Green;
  52. myPointArray[2].X := 80;
  53. myPointArray[2].Y := wndHeight - 20;
  54. myPointArray[2].Color := cl_Yellow;
  55. deltaX[0] := 1; deltaY[0] := 1;
  56. deltaX[1] := - 1; deltaY[1] := 1;
  57. deltaX[2] := - 1; deltaY[2] := - 1;
  58. deltaX[3] := 1; deltaY[3] := - 1;
  59. end;
  60. procedure Draw;
  61. var
  62. i : Integer;
  63. begin
  64. batch2d_Begin;
  65. // RU: Устанавливаем цвет и альфу для каждой вершины.
  66. // EN: Set color and alpha for each vertex.
  67. fx2d_SetVCA( $FF0000, $00FF00, $0000FF, $FFFFFF, 255, 255, 255, 255 );
  68. // RU: Рисуем прямоугольник с заливкой(флаг PR2D_FILL) с использованием отдельных цветов для каждой вершины(флаг FX2D_VCA).
  69. // EN: Render filled rectangle(flag PR2D_FILL) and use different colors for each vertex(flag FX2D_VCA).
  70. pr2d_Rect( 0, 0, 800, 600, cl_Black, FX2D_VCA or PR2D_FILL );
  71. // RU: рисуем широкую ломанную линию. Каждая точка имеет свой цвет, ширина линии 10 пикселей.
  72. // EN: draw a wide broken line. Each point has its own color, the line width is 10 pixels.
  73. pr2d_LineStripEX(@myPointArray, 4, 0, 10, LINE_RGBA);
  74. // RU: пока мы можем производить вычисления для Android здесь, но это временно. Для Android будут свои таймера.
  75. // EN: for now we can do android calculations here, but it's temporary. Android will have its own timers.
  76. for i := 0 to 3 do
  77. begin
  78. if (myPointArray[i].X > wndWidth - 20) or (myPointArray[i].X < 20) then
  79. deltaX[i] := - deltaX[i];
  80. if (myPointArray[i].Y > wndHeight - 20) or (myPointArray[i].Y < 20) then
  81. deltaY[i] := - deltaY[i];
  82. myPointArray[i].X := myPointArray[i].X + deltaX[i];
  83. myPointArray[i].Y := myPointArray[i].Y + deltaY[i];
  84. end;
  85. // RU: Рисуем в центре экрана круг с радиусом 128 пиксела.
  86. // EN: Render circle in the center of screen with radius 128 pixels.
  87. pr2d_Circle( 400, 300, 128, newColor[0], 32, PR2D_FILL );
  88. INC( calc );
  89. if calc > 359 Then calc := 0;
  90. points[ calc ].X := 400 + m_Cos( calc ) * ( 96 + random( 32 ) );
  91. points[ calc ].Y := 300 + m_Sin( calc ) * ( 96 + random( 32 ) );
  92. // RU: Рисуем линии внутри круга.
  93. // EN: Render lines inside the circle.
  94. for i := 0 to 359 do
  95. pr2d_Line( 400, 300, points[ i ].X, points[ i ].Y, cl_White );
  96. // RU: Рисуем эллипсы с заливкой и без, со сглаженными контурами(флаг PR2D_SMOOTH).
  97. // EN: Render filled ellipses with smoothed edges(flag PR2D_SMOOTH).
  98. pr2d_Ellipse( 400 + 300, 300, 64, 256, newColor[1], 64, PR2D_FILL or PR2D_SMOOTH );
  99. pr2d_Ellipse( 400 + 300, 300, 64, 256, cl_Black, 32, PR2D_SMOOTH );
  100. pr2d_Ellipse( 400 - 300, 300, 64, 256, newColor[1], 64, PR2D_FILL{ or PR2D_SMOOTH });
  101. pr2d_Ellipse( 400 - 300, 300, 64, 256, cl_Black, 32, PR2D_SMOOTH );
  102. batch2d_End;
  103. end;
  104. procedure Java_zengl_android_ZenGL_Main( var env; var thiz ); cdecl;
  105. begin
  106. zgl_Reg( SYS_LOAD, @Init );
  107. zgl_Reg( SYS_DRAW, @Draw );
  108. scr_SetOptions();
  109. end;
  110. exports
  111. Java_zengl_android_ZenGL_Main,
  112. {$I android_export.inc}
  113. End.