commit
a8f73b764b
3 changed files with 277 additions and 0 deletions
86
examples/shapes/easings_ball_anim/main.go
Normal file
86
examples/shapes/easings_ball_anim/main.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
ez "github.com/gen2brain/raylib-go/easings"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings ball anim")
|
||||
|
||||
ballPosX := -100
|
||||
ballRadius := 20
|
||||
ballAlpha := float32(0)
|
||||
|
||||
state := 0
|
||||
frames := 0
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
if state == 0 {
|
||||
|
||||
frames++
|
||||
ballPosX = int(ez.ElasticOut(float32(frames), -100, float32(screenWidth/2)+100, 100))
|
||||
|
||||
if frames >= 100 {
|
||||
frames = 0
|
||||
state = 1
|
||||
}
|
||||
|
||||
} else if state == 1 {
|
||||
frames++
|
||||
ballRadius = int(ez.ElasticIn(float32(frames), 20, 500, 150))
|
||||
|
||||
if frames >= 150 {
|
||||
frames = 0
|
||||
state = 2
|
||||
}
|
||||
} else if state == 2 {
|
||||
frames++
|
||||
ballAlpha = ez.CubicOut(float32(frames), 0, 1, 150)
|
||||
|
||||
if frames >= 150 {
|
||||
frames = 0
|
||||
state = 3
|
||||
}
|
||||
} else if state == 3 {
|
||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||
ballPosX = -100
|
||||
ballRadius = 20
|
||||
ballAlpha = 0
|
||||
state = 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if rl.IsKeyPressed(rl.KeyR) {
|
||||
frames = 0
|
||||
}
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
if state >= 2 {
|
||||
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Green)
|
||||
}
|
||||
|
||||
rl.DrawCircle(int32(ballPosX), 200, float32(ballRadius), rl.Fade(rl.Red, 1-ballAlpha))
|
||||
|
||||
if state == 3 {
|
||||
textlen := rl.MeasureText("press ENTER to replay", 20)
|
||||
rl.DrawText("press ENTER to replay", (screenWidth/2)-textlen/2, 200, 20, rl.Black)
|
||||
}
|
||||
|
||||
rl.EndDrawing()
|
||||
|
||||
}
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
99
examples/shapes/easings_box_anim/main.go
Normal file
99
examples/shapes/easings_box_anim/main.go
Normal file
|
@ -0,0 +1,99 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
ez "github.com/gen2brain/raylib-go/easings"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
fps = int32(60)
|
||||
)
|
||||
|
||||
const (
|
||||
screenWidth = int32(800)
|
||||
screenHeight = int32(450)
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings box anim")
|
||||
|
||||
rec := rl.NewRectangle(float32(screenWidth/2), -100, 100, 100)
|
||||
rotation := float32(0)
|
||||
alpha := float32(1)
|
||||
|
||||
state := 0
|
||||
frames := 0
|
||||
|
||||
rl.SetTargetFPS(fps)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
switch state {
|
||||
case 0:
|
||||
frames++
|
||||
|
||||
rec.Y = ez.ElasticOut(float32(frames), -100, float32(screenHeight/2)+100, 120)
|
||||
|
||||
if frames >= 120 {
|
||||
frames = 0
|
||||
state = 1
|
||||
}
|
||||
|
||||
case 1:
|
||||
frames++
|
||||
rec.Height = ez.BounceOut(float32(frames), 100, -90, 120)
|
||||
rec.Width = ez.BounceOut(float32(frames), 100, float32(screenWidth), 120)
|
||||
|
||||
if frames >= 120 {
|
||||
frames++
|
||||
state = 2
|
||||
}
|
||||
case 2:
|
||||
frames++
|
||||
rotation = ez.QuadOut(float32(frames), 0, 270, 240)
|
||||
if frames >= 240 {
|
||||
frames = 0
|
||||
state = 3
|
||||
}
|
||||
case 3:
|
||||
frames++
|
||||
rec.Height = ez.CircOut(float32(frames), 10, float32(screenWidth), 120)
|
||||
if frames >= 120 {
|
||||
frames = 0
|
||||
state = 4
|
||||
}
|
||||
|
||||
case 4:
|
||||
frames++
|
||||
alpha = ez.SineOut(float32(frames), 1, -1, 160)
|
||||
if frames >= 160 {
|
||||
frames = 0
|
||||
state = 5
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if rl.IsKeyPressed(rl.KeySpace) {
|
||||
rec = rl.NewRectangle(float32(screenWidth/2), -100, 100, 100)
|
||||
rotation = 0
|
||||
alpha = 1
|
||||
state = 0
|
||||
frames = 0
|
||||
}
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
rl.DrawRectanglePro(rec, rl.NewVector2(rec.Width/2, rec.Height/2), rotation, rl.Fade(rl.Black, alpha))
|
||||
|
||||
if state == 5 {
|
||||
txtlen := rl.MeasureText("SPACE to replay", 20)
|
||||
rl.DrawText("SPACE to replay", (screenWidth/2)-txtlen/2, 200, 20, rl.Black)
|
||||
}
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
92
examples/shapes/easings_rectangle_array/main.go
Normal file
92
examples/shapes/easings_rectangle_array/main.go
Normal file
|
@ -0,0 +1,92 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
ez "github.com/gen2brain/raylib-go/easings"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
playTime = float32(240)
|
||||
fps = int32(60)
|
||||
)
|
||||
|
||||
const (
|
||||
recsW, recsH = 50, 50
|
||||
screenWidth = int32(800)
|
||||
screenHeight = int32(450)
|
||||
maxRecsX = int(screenWidth) / recsW
|
||||
maxRecsY = int(screenHeight) / recsH
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings rectangle array")
|
||||
|
||||
var recs [maxRecsX * maxRecsY]rl.Rectangle
|
||||
|
||||
for y := 0; y < maxRecsY; y++ {
|
||||
|
||||
for x := 0; x < maxRecsX; x++ {
|
||||
recs[y*maxRecsX+x].X = float32(recsW/2 + recsW*float32(x))
|
||||
recs[y*maxRecsX+x].Y = float32(recsH/2 + recsH*float32(y))
|
||||
recs[y*maxRecsX+x].Width = float32(recsW)
|
||||
recs[y*maxRecsX+x].Height = float32(recsH)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rotation := float32(0)
|
||||
frameCount := float32(0)
|
||||
state := 0
|
||||
|
||||
rl.SetTargetFPS(fps)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
if state == 0 {
|
||||
frameCount++
|
||||
|
||||
for i := 0; i < maxRecsX*maxRecsY; i++ {
|
||||
recs[i].Height = float32(ez.LinearIn(frameCount, recsH, -recsH, playTime))
|
||||
recs[i].Width = float32(ez.LinearIn(frameCount, recsW, -recsW, playTime))
|
||||
|
||||
if recs[i].Height < 0 {
|
||||
recs[i].Height = 0
|
||||
}
|
||||
|
||||
if recs[i].Width < 0 {
|
||||
recs[i].Width = 0
|
||||
}
|
||||
|
||||
if recs[i].Height == 0 && recs[i].Width == 0 {
|
||||
state = 1
|
||||
}
|
||||
rotation = float32(ez.LinearIn(frameCount, 0, 360, playTime))
|
||||
}
|
||||
} else if state == 1 && rl.IsKeyPressed(rl.KeySpace) {
|
||||
frameCount = 0
|
||||
for i := 0; i < maxRecsX*maxRecsY; i++ {
|
||||
recs[i].Height = float32(recsH)
|
||||
recs[i].Width = float32(recsW)
|
||||
}
|
||||
|
||||
state = 0
|
||||
}
|
||||
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
if state == 0 {
|
||||
for i := 0; i < maxRecsX*maxRecsY; i++ {
|
||||
rl.DrawRectanglePro(recs[i], rl.NewVector2(recs[i].Width/2, recs[i].Height/2), rotation, rl.Red)
|
||||
}
|
||||
} else if state == 1 {
|
||||
txtlen := rl.MeasureText("SPACE to replay", 20)
|
||||
rl.DrawText("SPACE to replay", (screenWidth/2)-txtlen/2, 200, 20, rl.Black)
|
||||
}
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.CloseWindow()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue