shapes examples
This commit is contained in:
parent
d3497d36da
commit
bbc8e558a5
2 changed files with 99 additions and 0 deletions
50
examples/shapes/draw_circle_sector/main.go
Normal file
50
examples/shapes/draw_circle_sector/main.go
Normal file
|
@ -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()
|
||||||
|
}
|
49
examples/shapes/draw_ring/main.go
Normal file
49
examples/shapes/draw_ring/main.go
Normal file
|
@ -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()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue