summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorRay <[email protected]>2023-11-09 09:53:25 +0100
committerRay <[email protected]>2023-11-09 09:53:25 +0100
commit21dc42d2ad02cafed83cd39afd7305212787c114 (patch)
tree205d9c9d9e094898b6be692e676f0f5ae6653cf6 /examples
parentc69b89cc42747d5bb3e7dd7c0088a229820e75ae (diff)
downloadraylib-21dc42d2ad02cafed83cd39afd7305212787c114.tar.gz
raylib-21dc42d2ad02cafed83cd39afd7305212787c114.zip
Updated examples
Diffstat (limited to 'examples')
-rw-r--r--examples/shapes/shapes_lines_bezier.c41
-rw-r--r--examples/shapes/shapes_lines_bezier.pngbin17537 -> 17953 bytes
-rw-r--r--examples/shapes/shapes_splines_drawing.c12
3 files changed, 27 insertions, 26 deletions
diff --git a/examples/shapes/shapes_lines_bezier.c b/examples/shapes/shapes_lines_bezier.c
index 785d73a6..aaad6804 100644
--- a/examples/shapes/shapes_lines_bezier.c
+++ b/examples/shapes/shapes_lines_bezier.c
@@ -26,11 +26,10 @@ int main(void)
SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
- Vector2 start = { 0, 0 };
- Vector2 end = { (float)screenWidth, (float)screenHeight };
-
- Vector2 startControl = { 100, 0 };
- Vector2 endControl = { GetScreenWidth() - 100, GetScreenHeight() };
+ Vector2 startPoint = { 30, 30 };
+ Vector2 endPoint = { (float)screenWidth - 30, (float)screenHeight - 30 };
+ bool moveStartPoint = false;
+ bool moveEndPoint = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -40,15 +39,21 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- if (IsKeyDown(KEY_LEFT_CONTROL))
+ Vector2 mouse = GetMousePosition();
+
+ if (CheckCollisionPointCircle(mouse, startPoint, 10.0f) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) moveStartPoint = true;
+ else if (CheckCollisionPointCircle(mouse, endPoint, 10.0f) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) moveEndPoint = true;
+
+ if (moveStartPoint)
{
- if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) startControl = GetMousePosition();
- else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) endControl = GetMousePosition();
+ startPoint = mouse;
+ if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveStartPoint = false;
}
- else
+
+ if (moveEndPoint)
{
- if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) start = GetMousePosition();
- else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) end = GetMousePosition();
+ endPoint = mouse;
+ if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) moveEndPoint = false;
}
//----------------------------------------------------------------------------------
@@ -58,18 +63,14 @@ int main(void)
ClearBackground(RAYWHITE);
- DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY);
+ DrawText("MOVE START-END POINTS WITH MOUSE", 15, 20, 20, GRAY);
// Draw line Cubic Bezier, in-out interpolation (easing), no control points
- DrawLineBezier(start, end, 3.0f, BLUE);
-
- // Draw spline Cubic Bezier with control points
- DrawSplineSegmentBezierCubic(start, startControl, endControl, end, 2.0f, RED);
+ DrawLineBezier(startPoint, endPoint, 4.0f, BLUE);
- DrawLineEx(start, startControl, 1.0, LIGHTGRAY);
- DrawLineEx(end, endControl, 1.0, LIGHTGRAY);
- DrawCircleV(startControl, 10, RED);
- DrawCircleV(endControl, 10, RED);
+ // Draw start-end spline circles with some details
+ DrawCircleV(startPoint, CheckCollisionPointCircle(mouse, startPoint, 10.0f)? 14 : 8, moveStartPoint? RED : BLUE);
+ DrawCircleV(endPoint, CheckCollisionPointCircle(mouse, endPoint, 10.0f)? 14 : 8, moveEndPoint? RED : BLUE);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/shapes/shapes_lines_bezier.png b/examples/shapes/shapes_lines_bezier.png
index 390a49ad..aa5edf31 100644
--- a/examples/shapes/shapes_lines_bezier.png
+++ b/examples/shapes/shapes_lines_bezier.png
Binary files differ
diff --git a/examples/shapes/shapes_splines_drawing.c b/examples/shapes/shapes_splines_drawing.c
index 435ff79b..8df5f09f 100644
--- a/examples/shapes/shapes_splines_drawing.c
+++ b/examples/shapes/shapes_splines_drawing.c
@@ -192,12 +192,12 @@ int main(void)
DrawSplineSegmentBezierCubic(points[i], control[i].start, control[i].end, points[i + 1], splineThickness, RED);
// Every cubic bezier point should have two control points
- DrawCircleV(control[i].start, 4, GOLD);
- DrawCircleV(control[i].end, 4, GOLD);
- if (focusedControlPoint == &control[i].start) DrawCircleV(control[i].start, 6, GREEN);
- else if (focusedControlPoint == &control[i].end) DrawCircleV(control[i].end, 6, GREEN);
- DrawLineEx(points[i], control[i].start, 1.0, LIGHTGRAY);
- DrawLineEx(points[i + 1], control[i].end, 1.0, LIGHTGRAY);
+ DrawCircleV(control[i].start, 6, GOLD);
+ DrawCircleV(control[i].end, 6, GOLD);
+ if (focusedControlPoint == &control[i].start) DrawCircleV(control[i].start, 8, GREEN);
+ else if (focusedControlPoint == &control[i].end) DrawCircleV(control[i].end, 8, GREEN);
+ DrawLineEx(points[i], control[i].start, 1.0f, LIGHTGRAY);
+ DrawLineEx(points[i + 1], control[i].end, 1.0f, LIGHTGRAY);
// Draw spline control lines
DrawLineV(points[i], control[i].start, GRAY);