mais parâmetros
This commit is contained in:
parent
c8c06724e7
commit
035770a3b6
2 changed files with 52 additions and 46 deletions
2
go.mod
2
go.mod
|
|
@ -1,4 +1,4 @@
|
||||||
module app
|
module magnets
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
|
|
|
||||||
58
main.go
58
main.go
|
|
@ -1,6 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// veja:
|
||||||
|
// The relationship between chaos, fractal and physics
|
||||||
|
// https://www.youtube.com/watch?v=C5Jkgvw-Z6E
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
// "fmt"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
@ -21,19 +26,26 @@ type ball struct {
|
||||||
originGrid rl.Vector2
|
originGrid rl.Vector2
|
||||||
radius float32
|
radius float32
|
||||||
speed rl.Vector2
|
speed rl.Vector2
|
||||||
|
steps int
|
||||||
}
|
}
|
||||||
|
|
||||||
// parametros
|
// parâmetros
|
||||||
const windowWidth = 800
|
const windowWidth = 700
|
||||||
const windowHeight = 450
|
const windowHeight = 700
|
||||||
const magnetRadius = 15
|
const magnetRadius = 8
|
||||||
const magnetForce = 8
|
const magnetForce = 10
|
||||||
const magnetsDistance float32 = 80
|
const magnetsDistance float32 = 80
|
||||||
const verticalGrids = 100
|
const gridDivision = 10
|
||||||
const horizontalGrids = 100
|
const verticalGrids = windowHeight/gridDivision
|
||||||
const ballMass float32 = 2
|
const horizontalGrids = windowWidth/gridDivision
|
||||||
const gravConst float32 = 8
|
const ballMass float32 = 1 // sensivel
|
||||||
const magnetsAngle = 45
|
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) {
|
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 {
|
for _, magnet := range magnets {
|
||||||
distance := rl.Vector2Distance(ball.pos, magnet.pos)
|
distance := rl.Vector2Distance(ball.pos, magnet.pos)
|
||||||
if distance < magnet.radius + ball.radius {
|
if distance < magnet.radius + ball.radius {
|
||||||
|
if luminance { magnet.color.A = uint8(ball.steps) }
|
||||||
return true, magnet.color
|
return true, magnet.color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,11 +77,7 @@ func (ball *ball) update(magnets []magnet) (bool, rl.Color) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
|
||||||
rl.InitWindow(
|
rl.InitWindow(
|
||||||
windowWidth, windowHeight,
|
windowWidth, windowHeight,
|
||||||
"raylib [core] example - basic window",
|
"raylib [core] example - basic window",
|
||||||
|
|
@ -146,7 +155,7 @@ func main() {
|
||||||
y := randomGrid.Y * gridSize.Y + gridSize.Y/2
|
y := randomGrid.Y * gridSize.Y + gridSize.Y/2
|
||||||
fallingBall = append(fallingBall, &ball{
|
fallingBall = append(fallingBall, &ball{
|
||||||
pos: rl.Vector2{X: x, Y: y},
|
pos: rl.Vector2{X: x, Y: y},
|
||||||
speed: rl.Vector2{},
|
speed: startingBallSpeed,
|
||||||
radius: magnetRadius/2,
|
radius: magnetRadius/2,
|
||||||
originGrid: randomGrid,
|
originGrid: randomGrid,
|
||||||
})
|
})
|
||||||
|
|
@ -165,10 +174,12 @@ func main() {
|
||||||
rl.DrawRectangleV(pos, gridSize, grid[y][x])
|
rl.DrawRectangleV(pos, gridSize, grid[y][x])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !hideMagnets {
|
||||||
for i := range magnets {
|
for i := range magnets {
|
||||||
rl.DrawCircleV(magnets[i].pos, magnetRadius+2, rl.Black)
|
rl.DrawCircleV(magnets[i].pos, magnetRadius+2, rl.Black)
|
||||||
rl.DrawCircleV(magnets[i].pos, magnetRadius, magnets[i].color)
|
rl.DrawCircleV(magnets[i].pos, magnetRadius, magnets[i].color)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(fallingBall) == 0 {
|
if len(fallingBall) == 0 {
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
|
|
@ -179,6 +190,7 @@ func main() {
|
||||||
for i := 0; i < len(fallingBall); i++ {
|
for i := 0; i < len(fallingBall); i++ {
|
||||||
ball := fallingBall[i]
|
ball := fallingBall[i]
|
||||||
|
|
||||||
|
if !hideBalls {
|
||||||
// rl.DrawCircleV(
|
// rl.DrawCircleV(
|
||||||
// ball.pos, ball.radius/2+1, rl.Black,
|
// ball.pos, ball.radius/2+1, rl.Black,
|
||||||
// )
|
// )
|
||||||
|
|
@ -186,6 +198,7 @@ func main() {
|
||||||
// ball.pos, ball.radius/2,
|
// ball.pos, ball.radius/2,
|
||||||
// rl.NewColor(100, 100, 100, 255),
|
// rl.NewColor(100, 100, 100, 255),
|
||||||
// )
|
// )
|
||||||
|
// bolas são difíceis de se calcular =/
|
||||||
rl.DrawRectangleV(
|
rl.DrawRectangleV(
|
||||||
rl.Vector2{X: ball.pos.X-1, Y: ball.pos.Y-1 },
|
rl.Vector2{X: ball.pos.X-1, Y: ball.pos.Y-1 },
|
||||||
rl.Vector2{X: ball.radius+1, Y: ball.radius+1},
|
rl.Vector2{X: ball.radius+1, Y: ball.radius+1},
|
||||||
|
|
@ -195,6 +208,7 @@ func main() {
|
||||||
ball.pos, rl.Vector2{X: ball.radius, Y: ball.radius},
|
ball.pos, rl.Vector2{X: ball.radius, Y: ball.radius},
|
||||||
rl.NewColor(100, 100, 100, 255),
|
rl.NewColor(100, 100, 100, 255),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
if hit, color := ball.update(magnets); hit {
|
if hit, color := ball.update(magnets); hit {
|
||||||
x := ball.originGrid.X
|
x := ball.originGrid.X
|
||||||
y := ball.originGrid.Y
|
y := ball.originGrid.Y
|
||||||
|
|
@ -203,22 +217,14 @@ func main() {
|
||||||
fallingBall[i] = fallingBall[len(fallingBall)-1]
|
fallingBall[i] = fallingBall[len(fallingBall)-1]
|
||||||
fallingBall = fallingBall[:len(fallingBall)-1]
|
fallingBall = fallingBall[:len(fallingBall)-1]
|
||||||
}
|
}
|
||||||
|
ball.steps += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println("foo")
|
// fmt.Println("foo")
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
stat := make(map[rl.Color]int)
|
fmt.Println("hello world")
|
||||||
stat[rl.Red] = 0
|
|
||||||
stat[rl.Green] = 0
|
|
||||||
stat[rl.Blue] = 0
|
|
||||||
|
|
||||||
for y := range grid {
|
|
||||||
for x := range grid[y] {
|
|
||||||
stat[grid[y][x]] += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(stat)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue