shapes_basic_shapes.c 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...) (adapted for HTML5 platform)
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. //----------------------------------------------------------------------------------
  21. // Module Functions Declaration
  22. //----------------------------------------------------------------------------------
  23. void UpdateDrawFrame(void); // Update and Draw one frame
  24. //----------------------------------------------------------------------------------
  25. // Main Enry Point
  26. //----------------------------------------------------------------------------------
  27. int main()
  28. {
  29. // Initialization
  30. //--------------------------------------------------------------------------------------
  31. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
  32. #if defined(PLATFORM_WEB)
  33. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  34. #else
  35. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  36. //--------------------------------------------------------------------------------------
  37. // Main game loop
  38. while (!WindowShouldClose()) // Detect window close button or ESC key
  39. {
  40. UpdateDrawFrame();
  41. }
  42. #endif
  43. // De-Initialization
  44. //--------------------------------------------------------------------------------------
  45. CloseWindow(); // Close window and OpenGL context
  46. //--------------------------------------------------------------------------------------
  47. return 0;
  48. }
  49. //----------------------------------------------------------------------------------
  50. // Module Functions Definition
  51. //----------------------------------------------------------------------------------
  52. void UpdateDrawFrame(void)
  53. {
  54. // Update
  55. //----------------------------------------------------------------------------------
  56. // TODO: Update your variables here
  57. //----------------------------------------------------------------------------------
  58. // Draw
  59. //----------------------------------------------------------------------------------
  60. BeginDrawing();
  61. ClearBackground(RAYWHITE);
  62. DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
  63. DrawLine(18, 42, screenWidth - 18, 42, BLACK);
  64. DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
  65. DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE);
  66. DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE);
  67. DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
  68. DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
  69. DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);
  70. DrawTriangle((Vector2){screenWidth/4*3, 80},
  71. (Vector2){screenWidth/4*3 - 60, 150},
  72. (Vector2){screenWidth/4*3 + 60, 150}, VIOLET);
  73. DrawTriangleLines((Vector2){screenWidth/4*3, 160},
  74. (Vector2){screenWidth/4*3 - 20, 230},
  75. (Vector2){screenWidth/4*3 + 20, 230}, DARKBLUE);
  76. DrawPoly((Vector2){screenWidth/4*3, 320}, 6, 80, 0, BROWN);
  77. EndDrawing();
  78. //----------------------------------------------------------------------------------
  79. }