From bbc8e558a5e8e5c97d2cfa1881dd7aad6727af61 Mon Sep 17 00:00:00 2001 From: unklnik Date: Wed, 4 Oct 2023 17:10:01 +0200 Subject: [PATCH] shapes examples --- examples/shapes/draw_circle_sector/main.go | 50 ++++++++++++++++++++++ examples/shapes/draw_ring/main.go | 49 +++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 examples/shapes/draw_circle_sector/main.go create mode 100644 examples/shapes/draw_ring/main.go diff --git a/examples/shapes/draw_circle_sector/main.go b/examples/shapes/draw_circle_sector/main.go new file mode 100644 index 0000000..bf4ea18 --- /dev/null +++ b/examples/shapes/draw_circle_sector/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "math" + + rg "github.com/gen2brain/raylib-go/raygui" + rl "github.com/gen2brain/raylib-go/raylib" +) + +func main() { + screenWidth := int32(800) + screenHeight := int32(450) + + rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw circle sector") + + cntr := rl.NewVector2(float32(rl.GetScreenWidth()-300)/2, float32(rl.GetScreenHeight())/2) + + outerRad, startAngle, endAngle, segments := float32(180), float32(0), float32(180), float32(10) + minSegments := 4 + + rl.SetTargetFPS(60) + + for !rl.WindowShouldClose() { + rl.BeginDrawing() + rl.ClearBackground(rl.RayWhite) + + rl.DrawLine(500, 0, 500, int32(rl.GetScreenHeight()), rl.Fade(rl.LightGray, 0.5)) + rl.DrawRectangle(500, 0, int32(rl.GetScreenWidth()-500), int32(rl.GetScreenHeight()), rl.Fade(rl.LightGray, 0.3)) + + rl.DrawCircleSector(cntr, outerRad, startAngle, endAngle, int32(segments), rl.Fade(rl.Maroon, 0.5)) + rl.DrawCircleSectorLines(cntr, outerRad, startAngle, endAngle, int32(segments), rl.Fade(rl.Maroon, 0.8)) + + startAngle = rg.SliderBar(rl.NewRectangle(600, 40, 120, 20), "Start Angle", "", startAngle, 0, 720) + endAngle = rg.SliderBar(rl.NewRectangle(600, 70, 120, 20), "End Angle", "", endAngle, 0, 720) + outerRad = rg.SliderBar(rl.NewRectangle(600, 140, 120, 20), "Radius", "", outerRad, 0, 200) + segments = rg.SliderBar(rl.NewRectangle(600, 170, 120, 20), "Segments", "", segments, 0, 100) + + minSegments = int(math.Ceil(float64(endAngle-startAngle) / 90)) + + if segments >= float32(minSegments) { + rl.DrawText("MODE: MANUAL", 600, 200, 10, rl.Maroon) + } else { + rl.DrawText("MODE: AUTO", 600, 200, 10, rl.DarkGray) + } + + rl.EndDrawing() + } + + rl.CloseWindow() +} diff --git a/examples/shapes/draw_ring/main.go b/examples/shapes/draw_ring/main.go new file mode 100644 index 0000000..8d8b8ba --- /dev/null +++ b/examples/shapes/draw_ring/main.go @@ -0,0 +1,49 @@ +package main + +import ( + rg "github.com/gen2brain/raylib-go/raygui" + rl "github.com/gen2brain/raylib-go/raylib" +) + +func main() { + screenWidth := int32(800) + screenHeight := int32(450) + + rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw ring") + + cntr := rl.NewVector2(float32(rl.GetScreenWidth()-300)/2, float32(rl.GetScreenHeight())/2) + innerRad, outerRad := float32(80), float32(190) + startAngle, endAngle, segments := float32(0), float32(360), float32(0) + drawRing, drawRingLines, drawCircLines := true, false, false + + rl.SetTargetFPS(60) + + for !rl.WindowShouldClose() { + rl.BeginDrawing() + rl.ClearBackground(rl.RayWhite) + + rl.DrawLine(500, 0, 500, int32(rl.GetScreenHeight()), rl.Fade(rl.LightGray, 0.3)) + + if drawRing { + rl.DrawRing(cntr, innerRad, outerRad, startAngle, endAngle, int32(segments), rl.Fade(rl.Maroon, 0.7)) + } + if drawRingLines { + rl.DrawRingLines(cntr, innerRad, outerRad, startAngle, endAngle, int32(segments), rl.Fade(rl.Black, 0.7)) + } + if drawCircLines { + rl.DrawCircleSectorLines(cntr, outerRad, startAngle, endAngle, int32(segments), rl.Fade(rl.Black, 0.7)) + } + + startAngle = rg.SliderBar(rl.NewRectangle(600, 40, 120, 20), "Start Angle", "", startAngle, -450, 450) + endAngle = rg.SliderBar(rl.NewRectangle(600, 70, 120, 20), "End Angle", "", endAngle, -450, 450) + innerRad = rg.SliderBar(rl.NewRectangle(600, 140, 120, 20), "Inner Radius", "", innerRad, -450, 450) + outerRad = rg.SliderBar(rl.NewRectangle(600, 170, 120, 20), "Outer Radius", "", outerRad, -450, 450) + drawRing = rg.CheckBox(rl.NewRectangle(600, 320, 20, 20), "Draw Ring", drawRing) + drawRingLines = rg.CheckBox(rl.NewRectangle(600, 350, 20, 20), "Draw Ring Lines", drawRingLines) + drawCircLines = rg.CheckBox(rl.NewRectangle(600, 380, 20, 20), "Draw Ring", drawCircLines) + + rl.EndDrawing() + } + + rl.CloseWindow() +}