package main import ( "math" rl "github.com/gen2brain/raylib-go/raylib" ) type magnet struct { pos rl.Vector2 color rl.Color } type state struct { windowHeight int32 windowWidth int32 magnetsDistance float32 } func main() { state := state{ windowWidth: 800, windowHeight: 450, } rl.InitWindow( state.windowWidth, state.windowHeight, "raylib [core] example - basic window", ) defer rl.CloseWindow() rl.SetTargetFPS(60) const RADIUS = 10 magnets := []magnet{ { // pos: rl.Vector2{X: 100, Y: 100}, color: rl.NewColor(255, 0, 0, 255), }, { // pos: rl.Vector2{X: 200, Y: 200}, color: rl.NewColor(0, 255, 0, 255), }, { // pos: rl.Vector2{X: 200, Y: 100}, color: rl.NewColor(0, 0, 255, 255), }, } // pocisionar imas no meio da tela xCenter := float32(state.windowWidth / 2) yCenter := float32(state.windowHeight / 2) magnetsDistance := float32(100) for i := range magnets { angle := 2.0 * math.Pi * float64(i) / float64(len(magnets)) magnets[i].pos = rl.Vector2{ X: float32(math.Cos(angle)) * magnetsDistance + xCenter, Y: float32(math.Sin(angle)) * magnetsDistance + yCenter, } } verticalGrids := 10 horizontalGrids := 10 grid := make([][]rl.Color, verticalGrids) for i := range grid { grid[i] = make([]rl.Color, horizontalGrids) for j := range grid[i] { grid[i][j] = rl.NewColor(10, 10, 10, 255) } } ball := rl.Vector2{0, 0} gridSize := rl.Vector2{ X: float32(state.windowWidth / int32(verticalGrids)), Y: float32(state.windowHeight / int32(horizontalGrids)), } for !rl.WindowShouldClose() { rl.BeginDrawing() rl.ClearBackground(rl.Black) for y := range grid { for x := range grid[y] { pos := rl.Vector2{ X: gridSize.X * float32(x), Y: gridSize.Y * float32(y), } rl.DrawRectangleV(pos, gridSize, grid[y][x]) } } for i := range magnets { rl.DrawCircleV(magnets[i].pos, RADIUS, magnets[i].color) } rl.DrawCircleV(ball, RADIUS/2, rl.NewColor(100, 100, 100, 255)) rl.EndDrawing() } }