diff --git a/go.mod b/go.mod index d4f01fc..4c37d2a 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module app +module magnets go 1.20 diff --git a/main.go b/main.go index bcdab61..3253b62 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,11 @@ package main +// veja: +// The relationship between chaos, fractal and physics +// https://www.youtube.com/watch?v=C5Jkgvw-Z6E + import ( + // "fmt" "fmt" "math" "math/rand" @@ -21,19 +26,26 @@ type ball struct { originGrid rl.Vector2 radius float32 speed rl.Vector2 + steps int } -// parametros -const windowWidth = 800 -const windowHeight = 450 -const magnetRadius = 15 -const magnetForce = 8 +// parâmetros +const windowWidth = 700 +const windowHeight = 700 +const magnetRadius = 8 +const magnetForce = 10 const magnetsDistance float32 = 80 -const verticalGrids = 100 -const horizontalGrids = 100 -const ballMass float32 = 2 -const gravConst float32 = 8 -const magnetsAngle = 45 +const gridDivision = 10 +const verticalGrids = windowHeight/gridDivision +const horizontalGrids = windowWidth/gridDivision +const ballMass float32 = 1 // sensivel +const gravConst float32 = 1 // sensivel +const magnetsAngle = 0 +const luminance = false +const hideBalls = false +const hideMagnets = false +var startingBallSpeed = rl.Vector2{X: -0.5, Y: 0.5} // joga a bola em alguma diração +// antes que ela comece a ser atraida pelos ímãs func (ball *ball) update(magnets []magnet) (bool, rl.Color) { @@ -57,6 +69,7 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) { for _, magnet := range magnets { distance := rl.Vector2Distance(ball.pos, magnet.pos) if distance < magnet.radius + ball.radius { + if luminance { magnet.color.A = uint8(ball.steps) } return true, magnet.color } } @@ -64,11 +77,7 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) { } - - func main() { - - rl.InitWindow( windowWidth, windowHeight, "raylib [core] example - basic window", @@ -146,7 +155,7 @@ func main() { y := randomGrid.Y * gridSize.Y + gridSize.Y/2 fallingBall = append(fallingBall, &ball{ pos: rl.Vector2{X: x, Y: y}, - speed: rl.Vector2{}, + speed: startingBallSpeed, radius: magnetRadius/2, originGrid: randomGrid, }) @@ -165,9 +174,11 @@ func main() { rl.DrawRectangleV(pos, gridSize, grid[y][x]) } } - for i := range magnets { - rl.DrawCircleV(magnets[i].pos, magnetRadius+2, rl.Black) - rl.DrawCircleV(magnets[i].pos, magnetRadius, magnets[i].color) + if !hideMagnets { + for i := range magnets { + rl.DrawCircleV(magnets[i].pos, magnetRadius+2, rl.Black) + rl.DrawCircleV(magnets[i].pos, magnetRadius, magnets[i].color) + } } if len(fallingBall) == 0 { @@ -179,22 +190,25 @@ func main() { for i := 0; i < len(fallingBall); i++ { ball := fallingBall[i] - // rl.DrawCircleV( - // ball.pos, ball.radius/2+1, rl.Black, - // ) - // rl.DrawCircleV( - // ball.pos, ball.radius/2, - // rl.NewColor(100, 100, 100, 255), - // ) - rl.DrawRectangleV( - rl.Vector2{X: ball.pos.X-1, Y: ball.pos.Y-1 }, - rl.Vector2{X: ball.radius+1, Y: ball.radius+1}, - rl.Black, - ) - rl.DrawRectangleV( - ball.pos, rl.Vector2{X: ball.radius, Y: ball.radius}, - rl.NewColor(100, 100, 100, 255), - ) + if !hideBalls { + // rl.DrawCircleV( + // ball.pos, ball.radius/2+1, rl.Black, + // ) + // rl.DrawCircleV( + // ball.pos, ball.radius/2, + // rl.NewColor(100, 100, 100, 255), + // ) + // bolas são difíceis de se calcular =/ + rl.DrawRectangleV( + rl.Vector2{X: ball.pos.X-1, Y: ball.pos.Y-1 }, + rl.Vector2{X: ball.radius+1, Y: ball.radius+1}, + rl.Black, + ) + rl.DrawRectangleV( + ball.pos, rl.Vector2{X: ball.radius, Y: ball.radius}, + rl.NewColor(100, 100, 100, 255), + ) + } if hit, color := ball.update(magnets); hit { x := ball.originGrid.X y := ball.originGrid.Y @@ -203,22 +217,14 @@ func main() { fallingBall[i] = fallingBall[len(fallingBall)-1] fallingBall = fallingBall[:len(fallingBall)-1] } + ball.steps += 1 } + // fmt.Println("foo") rl.EndDrawing() } - stat := make(map[rl.Color]int) - stat[rl.Red] = 0 - stat[rl.Green] = 0 - stat[rl.Blue] = 0 + fmt.Println("hello world") - for y := range grid { - for x := range grid[y] { - stat[grid[y][x]] += 1 - } - } - - fmt.Println(stat) }