shapes_lines_bezier.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - Cubic-bezier lines
  4. *
  5. * Example originally created with raylib 1.7, last time updated with raylib 1.7
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2017-2023 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. SetConfigFlags(FLAG_MSAA_4X_HINT);
  24. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
  25. Vector2 start = { 0, 0 };
  26. Vector2 end = { (float)screenWidth, (float)screenHeight };
  27. Vector2 startControl = { 100, 0 };
  28. Vector2 endControl = { GetScreenWidth() - 100, GetScreenHeight() };
  29. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. if (IsKeyDown(KEY_LEFT_CONTROL))
  37. {
  38. if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) startControl = GetMousePosition();
  39. else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) endControl = GetMousePosition();
  40. }
  41. else
  42. {
  43. if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) start = GetMousePosition();
  44. else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) end = GetMousePosition();
  45. }
  46. //----------------------------------------------------------------------------------
  47. // Draw
  48. //----------------------------------------------------------------------------------
  49. BeginDrawing();
  50. ClearBackground(RAYWHITE);
  51. DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY);
  52. //DrawLineBezier(start, end, 2.0f, RED);
  53. DrawLineBezierCubic(start, end, startControl, endControl, 2.0f, RED);
  54. DrawLineEx(start, startControl, 1.0, LIGHTGRAY);
  55. DrawLineEx(end, endControl, 1.0, LIGHTGRAY);
  56. DrawCircleV(startControl, 10, RED);
  57. DrawCircleV(endControl, 10, RED);
  58. EndDrawing();
  59. //----------------------------------------------------------------------------------
  60. }
  61. // De-Initialization
  62. //--------------------------------------------------------------------------------------
  63. CloseWindow(); // Close window and OpenGL context
  64. //--------------------------------------------------------------------------------------
  65. return 0;
  66. }