distancia ao quadrado
This commit is contained in:
parent
035770a3b6
commit
8411609b6a
1 changed files with 30 additions and 20 deletions
50
main.go
50
main.go
|
|
@ -8,7 +8,7 @@ import (
|
|||
// "fmt"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
// "math/rand"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
|
@ -32,20 +32,19 @@ type ball struct {
|
|||
// parâmetros
|
||||
const windowWidth = 700
|
||||
const windowHeight = 700
|
||||
const magnetRadius = 8
|
||||
const magnetForce = 10
|
||||
const magnetsDistance float32 = 80
|
||||
const gridDivision = 10
|
||||
const gridDivision = 8
|
||||
const verticalGrids = windowHeight/gridDivision
|
||||
const horizontalGrids = windowWidth/gridDivision
|
||||
const ballMass float32 = 1 // sensivel
|
||||
const gravConst float32 = 1 // sensivel
|
||||
const magnetsDistance float32 = 80
|
||||
const magnetRadius = 10
|
||||
const gravConst float32 = 200
|
||||
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
|
||||
var startingBallSpeed = rl.Vector2{X: 0, Y: 0} // joga a bola em alguma diração
|
||||
// antes que ela comece a ser atraida pelos ímãs
|
||||
var cameraOffset = rl.Vector2{X: 0, Y: 0}
|
||||
|
||||
|
||||
func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
||||
|
|
@ -56,7 +55,8 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
|||
rl.Vector2Subtract(ball.pos, magnet.pos),
|
||||
)
|
||||
distance := rl.Vector2Distance(magnet.pos, ball.pos)
|
||||
force := gravConst * (ballMass * magnet.force) / distance
|
||||
distanceSquared := float32(math.Pow(float64(distance), 2))
|
||||
force := gravConst / distanceSquared
|
||||
|
||||
acceleration := rl.Vector2Scale(direction, -force)
|
||||
|
||||
|
|
@ -77,10 +77,15 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
|||
|
||||
}
|
||||
|
||||
// var colors = []rl.Color{
|
||||
// rl.Red, rl.Green, rl.Blue, rl.Yellow, rl.NewColor(0, 255, 255, 255),
|
||||
// rl.Magenta, rl.White,
|
||||
// }
|
||||
|
||||
func main() {
|
||||
rl.InitWindow(
|
||||
windowWidth, windowHeight,
|
||||
"raylib [core] example - basic window",
|
||||
"magnets",
|
||||
)
|
||||
defer rl.CloseWindow()
|
||||
// rl.SetTargetFPS(60)
|
||||
|
|
@ -89,23 +94,28 @@ func main() {
|
|||
{
|
||||
color: rl.Red,
|
||||
radius: magnetRadius,
|
||||
force: magnetForce,
|
||||
// force: magnetForce,
|
||||
},
|
||||
{
|
||||
color: rl.Green,
|
||||
radius: magnetRadius,
|
||||
force: magnetForce,
|
||||
// force: magnetForce,
|
||||
},
|
||||
{
|
||||
color: rl.Blue,
|
||||
radius: magnetRadius,
|
||||
force: magnetForce,
|
||||
// force: magnetForce,
|
||||
},
|
||||
{
|
||||
color: rl.Yellow,
|
||||
radius: magnetRadius,
|
||||
// force: magnetForce,
|
||||
},
|
||||
}
|
||||
|
||||
// pocisionar imas no meio da tela
|
||||
xCenter := float32(windowWidth / 2)
|
||||
yCenter := float32(windowHeight / 2)
|
||||
// posiciona imas em volta de um circulo
|
||||
xCenter := float32(windowWidth / 2) + cameraOffset.X
|
||||
yCenter := float32(windowHeight / 2) + cameraOffset.Y
|
||||
for i := range magnets {
|
||||
angle := 2.0 * math.Pi * float64(i) / float64(len(magnets)) + magnetsAngle
|
||||
|
||||
|
|
@ -145,10 +155,10 @@ func main() {
|
|||
})
|
||||
}
|
||||
}
|
||||
rand.Shuffle(len(fallingBallOrder), func(i, j int) {
|
||||
fallingBallOrder[i], fallingBallOrder[j] =
|
||||
fallingBallOrder[j], fallingBallOrder[i]
|
||||
})
|
||||
// rand.Shuffle(len(fallingBallOrder), func(i, j int) {
|
||||
// fallingBallOrder[i], fallingBallOrder[j] =
|
||||
// fallingBallOrder[j], fallingBallOrder[i]
|
||||
// })
|
||||
|
||||
for _, randomGrid := range fallingBallOrder {
|
||||
x := randomGrid.X * gridSize.X + gridSize.X/2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue