This commit is contained in:
Konstantin8105 2022-11-22 18:50:35 +03:00
parent 0bec81c656
commit fe6d2c0ed3
190 changed files with 104835 additions and 5 deletions

View file

@ -0,0 +1,45 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing")
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("some basic shapes available on raylib", 20, 20, 20, rl.DarkGray)
rl.DrawLine(18, 42, screenWidth-18, 42, rl.Black)
rl.DrawCircle(screenWidth/4, 120, 35, rl.DarkBlue)
rl.DrawCircleGradient(screenWidth/4, 220, 60, rl.Green, rl.SkyBlue)
rl.DrawCircleLines(screenWidth/4, 340, 80, rl.DarkBlue)
rl.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, rl.Red)
rl.DrawRectangleGradientH(screenWidth/4*2-90, 170, 180, 130, rl.Maroon, rl.Gold)
rl.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, rl.Orange)
rl.DrawTriangle(rl.NewVector2(float32(screenWidth)/4*3, 80),
rl.NewVector2(float32(screenWidth)/4*3-60, 150),
rl.NewVector2(float32(screenWidth)/4*3+60, 150), rl.Violet)
rl.DrawTriangleLines(rl.NewVector2(float32(screenWidth)/4*3, 160),
rl.NewVector2(float32(screenWidth)/4*3-20, 230),
rl.NewVector2(float32(screenWidth)/4*3+20, 230), rl.DarkBlue)
rl.DrawPoly(rl.NewVector2(float32(screenWidth)/4*3, 320), 6, 80, 0, rl.Brown)
rl.EndDrawing()
}
rl.CloseWindow()
}

View file

@ -0,0 +1,66 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
rl.InitWindow(800, 450, "raylib [shapes] example - raylib color palette")
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("raylib color palette", 28, 42, 20, rl.Black)
rl.DrawRectangle(26, 80, 100, 100, rl.DarkGray)
rl.DrawRectangle(26, 188, 100, 100, rl.Gray)
rl.DrawRectangle(26, 296, 100, 100, rl.LightGray)
rl.DrawRectangle(134, 80, 100, 100, rl.Maroon)
rl.DrawRectangle(134, 188, 100, 100, rl.Red)
rl.DrawRectangle(134, 296, 100, 100, rl.Pink)
rl.DrawRectangle(242, 80, 100, 100, rl.Orange)
rl.DrawRectangle(242, 188, 100, 100, rl.Gold)
rl.DrawRectangle(242, 296, 100, 100, rl.Yellow)
rl.DrawRectangle(350, 80, 100, 100, rl.DarkGreen)
rl.DrawRectangle(350, 188, 100, 100, rl.Lime)
rl.DrawRectangle(350, 296, 100, 100, rl.Green)
rl.DrawRectangle(458, 80, 100, 100, rl.DarkBlue)
rl.DrawRectangle(458, 188, 100, 100, rl.Blue)
rl.DrawRectangle(458, 296, 100, 100, rl.SkyBlue)
rl.DrawRectangle(566, 80, 100, 100, rl.DarkPurple)
rl.DrawRectangle(566, 188, 100, 100, rl.Violet)
rl.DrawRectangle(566, 296, 100, 100, rl.Purple)
rl.DrawRectangle(674, 80, 100, 100, rl.DarkBrown)
rl.DrawRectangle(674, 188, 100, 100, rl.Brown)
rl.DrawRectangle(674, 296, 100, 100, rl.Beige)
rl.DrawText("DARKGRAY", 65, 166, 10, rl.Black)
rl.DrawText("GRAY", 93, 274, 10, rl.Black)
rl.DrawText("LIGHTGRAY", 61, 382, 10, rl.Black)
rl.DrawText("MAROON", 186, 166, 10, rl.Black)
rl.DrawText("RED", 208, 274, 10, rl.Black)
rl.DrawText("PINK", 204, 382, 10, rl.Black)
rl.DrawText("ORANGE", 295, 166, 10, rl.Black)
rl.DrawText("GOLD", 310, 274, 10, rl.Black)
rl.DrawText("YELLOW", 300, 382, 10, rl.Black)
rl.DrawText("DARKGREEN", 382, 166, 10, rl.Black)
rl.DrawText("LIME", 420, 274, 10, rl.Black)
rl.DrawText("GREEN", 410, 382, 10, rl.Black)
rl.DrawText("DARKBLUE", 498, 166, 10, rl.Black)
rl.DrawText("BLUE", 526, 274, 10, rl.Black)
rl.DrawText("SKYBLUE", 505, 382, 10, rl.Black)
rl.DrawText("DARKPURPLE", 592, 166, 10, rl.Black)
rl.DrawText("VIOLET", 621, 274, 10, rl.Black)
rl.DrawText("PURPLE", 620, 382, 10, rl.Black)
rl.DrawText("DARKBROWN", 705, 166, 10, rl.Black)
rl.DrawText("BROWN", 733, 274, 10, rl.Black)
rl.DrawText("BEIGE", 737, 382, 10, rl.Black)
rl.EndDrawing()
}
rl.CloseWindow()
}

View file

@ -0,0 +1,36 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
start := rl.NewVector2(0, 0)
end := rl.NewVector2(float32(screenWidth), float32(screenHeight))
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
start = rl.GetMousePosition()
} else if rl.IsMouseButtonDown(rl.MouseRightButton) {
end = rl.GetMousePosition()
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, rl.Gray)
rl.DrawLineBezier(start, end, 2.0, rl.Red)
rl.EndDrawing()
}
rl.CloseWindow()
}

View file

@ -0,0 +1,29 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawRectangle(screenWidth/2-128, screenHeight/2-128, 256, 256, rl.Black)
rl.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, rl.RayWhite)
rl.DrawText("raylib", screenWidth/2-44, screenHeight/2+48, 50, rl.Black)
rl.DrawText("this is NOT a texture!", 350, 370, 10, rl.Gray)
rl.EndDrawing()
}
rl.CloseWindow()
}

View file

@ -0,0 +1,124 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
logoPositionX := screenWidth/2 - 128
logoPositionY := screenHeight/2 - 128
framesCounter := 0
lettersCount := int32(0)
topSideRecWidth := int32(16)
leftSideRecHeight := int32(16)
bottomSideRecWidth := int32(16)
rightSideRecHeight := int32(16)
state := 0 // Tracking animation states (State Machine)
alpha := float32(1.0) // Useful for fading
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
if state == 0 { // State 0: Small box blinking
framesCounter++
if framesCounter == 120 {
state = 1
framesCounter = 0 // Reset counter... will be used later...
}
} else if state == 1 { // State 1: Top and left bars growing
topSideRecWidth += 4
leftSideRecHeight += 4
if topSideRecWidth == 256 {
state = 2
}
} else if state == 2 { // State 2: Bottom and right bars growing
bottomSideRecWidth += 4
rightSideRecHeight += 4
if bottomSideRecWidth == 256 {
state = 3
}
} else if state == 3 { // State 3: Letters appearing (one by one)
framesCounter++
if framesCounter%12 == 0 { // Every 12 frames, one more letter!
lettersCount++
framesCounter = 0
}
if lettersCount >= 6 { // When all letters have appeared, just fade out everything
alpha -= 0.02
if alpha <= 0.0 {
alpha = 0.0
state = 4
}
}
} else if state == 4 { // State 4: Reset and Replay
if rl.IsKeyPressed(rl.KeyR) {
framesCounter = 0
lettersCount = 0
topSideRecWidth = 16
leftSideRecHeight = 16
bottomSideRecWidth = 16
rightSideRecHeight = 16
alpha = 1.0
state = 0 // Return to State 0
}
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
if state == 0 {
if (framesCounter/15)%2 == 0 {
rl.DrawRectangle(logoPositionX, logoPositionY, 16, 16, rl.Black)
}
} else if state == 1 {
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Black)
rl.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, rl.Black)
} else if state == 2 {
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Black)
rl.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, rl.Black)
rl.DrawRectangle(logoPositionX+240, logoPositionY, 16, rightSideRecHeight, rl.Black)
rl.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, rl.Black)
} else if state == 3 {
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Fade(rl.Black, alpha))
rl.DrawRectangle(logoPositionX, logoPositionY+16, 16, leftSideRecHeight-32, rl.Fade(rl.Black, alpha))
rl.DrawRectangle(logoPositionX+240, logoPositionY+16, 16, rightSideRecHeight-32, rl.Fade(rl.Black, alpha))
rl.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, rl.Fade(rl.Black, alpha))
rl.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, rl.Fade(rl.RayWhite, alpha))
text := "raylib"
length := int32(len(text))
if lettersCount > length {
lettersCount = length
}
rl.DrawText(text[0:lettersCount], screenWidth/2-44, screenHeight/2+48, 50, rl.Fade(rl.Black, alpha))
} else if state == 4 {
rl.DrawText("[R] REPLAY", 340, 200, 20, rl.Gray)
}
rl.EndDrawing()
}
rl.CloseWindow()
}