Browse Source

Add example for draw ellipse

pull/4450/head
cmanlh 2 months ago
parent
commit
ffdce81678
3 changed files with 86 additions and 1 deletions
  1. +2
    -1
      examples/Makefile
  2. +84
    -0
      examples/shapes/shapes_draw_ellipse.c
  3. BIN
      examples/shapes/shapes_draw_ellipse.png

+ 2
- 1
examples/Makefile View File

@ -533,7 +533,8 @@ SHAPES = \
shapes/shapes_rectangle_scaling \
shapes/shapes_splines_drawing \
shapes/shapes_top_down_lights \
shapes/shapes_rectangle_advanced
shapes/shapes_rectangle_advanced \
shapes/shapes_draw_ellipse
TEXTURES = \
textures/textures_background_scrolling \

+ 84
- 0
examples/shapes/shapes_draw_ellipse.c View File

@ -0,0 +1,84 @@
/*******************************************************************************************
*
* raylib [shapes] example - draw ellipse
*
* Example originally created with raylib 4.2, last time updated with raylib 5.5
*
* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2022-2024 Lu Hong (@CManLH)
*
********************************************************************************************/
#include "raylib.h"
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw ellipse");
float radiusH = 70.0f;
float radiusV = 100.0f;
Vector2 ellipseCenter = (Vector2){200, 100};
Color ellipseColor = SKYBLUE;
Vector2 ellipseLineCenter = (Vector2){200, 325};
Color ellipseLineColor = DARKGREEN;
Vector2 rotationEllipseCenter = (Vector2){460, 100};
Color rotationEllipseColor = GREEN;
Vector2 rotationEllipseLineCenter = (Vector2){460, 325};
Color rotationEllipseLineColor = RED;
float angle = PI / 6.0f;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw ellipse
DrawEllipse(ellipseCenter.x, ellipseCenter.y, radiusH, radiusV, ellipseColor);
DrawText("Ellipse!", ellipseCenter.x - 35, ellipseCenter.y, 20, BLACK);
// Draw ellipse outline
DrawEllipseLines(ellipseLineCenter.x, ellipseLineCenter.y, radiusH, radiusV, ellipseLineColor);
DrawText("Ellipse Outline", ellipseLineCenter.x - radiusH, ellipseLineCenter.y, 20, BLACK);
// Draw ellipse with rotation
DrawEllipseRotation(rotationEllipseCenter.x, rotationEllipseCenter.y, radiusH, radiusV, rotationEllipseColor, angle);
DrawText("Rotation Ellipse", rotationEllipseCenter.x - radiusH - 35, rotationEllipseCenter.y, 20, BLACK);
// Draw ellipse outline with rotation
DrawEllipseLinesRotation(rotationEllipseLineCenter.x, rotationEllipseLineCenter.y, radiusH, radiusV, rotationEllipseLineColor, angle);
DrawText("Rotation Ellipse outline", rotationEllipseLineCenter.x - radiusH - 35, rotationEllipseLineCenter.y, 20, BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
}
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

BIN
examples/shapes/shapes_draw_ellipse.png View File

Before After
Width: 762  |  Height: 447  |  Size: 8.8 KiB

Loading…
Cancel
Save