[wip] trying to make amount of goids dynamic
This commit is contained in:
parent
19d4fd0172
commit
d73f02f0c2
6
config.yaml
Normal file
6
config.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
- step: 100
|
||||||
|
amount: 100
|
||||||
|
- step: 200
|
||||||
|
amount: 150
|
||||||
|
- step: 300
|
||||||
|
amount: 40
|
1
go.mod
1
go.mod
@ -7,4 +7,5 @@ require github.com/llgcode/draw2d v0.0.0-20210904075650-80aa0a2a901d
|
|||||||
require (
|
require (
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 // indirect
|
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
)
|
)
|
||||||
|
3
go.sum
3
go.sum
@ -9,3 +9,6 @@ github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb h1:61ndUreYSlWFeCY44JxD
|
|||||||
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb/go.mod h1:1l8ky+Ew27CMX29uG+a2hNOKpeNYEQjjtiALiBlFQbY=
|
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb/go.mod h1:1l8ky+Ew27CMX29uG+a2hNOKpeNYEQjjtiALiBlFQbY=
|
||||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI=
|
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI=
|
||||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
42
main.go
42
main.go
@ -7,29 +7,53 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/llgcode/draw2d/draw2dimg"
|
"github.com/llgcode/draw2d/draw2dimg"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
var windowWidth, windowHeight = 800, 600
|
var windowWidth, windowHeight = 800, 600
|
||||||
var goidSize = 3
|
var goidSize = 3
|
||||||
var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
|
var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
|
||||||
var populationSize = 2
|
var populationSize = 10
|
||||||
var loops = 10000
|
var loops = 10000
|
||||||
var numNeighbours = 2
|
var numNeighbours = 10
|
||||||
var separationFactor = float64(goidSize * 5)
|
var separationFactor = float64(goidSize * 5)
|
||||||
var coherenceFactor = 8
|
var coherenceFactor = 8
|
||||||
|
|
||||||
|
type steps struct {
|
||||||
|
Step int `yaml:"step"`
|
||||||
|
Amount int `yaml:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func fixGoids(goids &[]*Goid, actual int, wished int) {
|
||||||
|
if actual < wished {
|
||||||
|
g := createRandomGoid()
|
||||||
|
goids = append(&goids, &g)
|
||||||
|
} else if wished < actual {
|
||||||
|
fmt.Println("it's not supported yet")
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fo, err := os.Create("/tmp/goids.txt")
|
fo, err := os.Create("/tmp/goids.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
conf, err := ioutil.ReadFile("config.yaml")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
td := []steps{}
|
||||||
|
err = yaml.Unmarshal(conf, &td)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := fo.Close(); err != nil {
|
if err := fo.Close(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -37,19 +61,26 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
clearScreen()
|
clearScreen()
|
||||||
hideCursor()
|
hideCursor()
|
||||||
|
var goids []*Goid
|
||||||
|
|
||||||
goids := make([]*Goid, 0)
|
|
||||||
for i := 0; i < populationSize; i++ {
|
for i := 0; i < populationSize; i++ {
|
||||||
g := createRandomGoid()
|
g := createRandomGoid()
|
||||||
goids = append(goids, &g)
|
goids = append(goids, &g)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_stage := 0
|
||||||
|
|
||||||
for i := 0; i < loops; i++ {
|
for i := 0; i < loops; i++ {
|
||||||
|
if i < td[current_stage].Step {
|
||||||
|
fmt.Printf("%d -- %d -- %d", i, current_stage, td[current_stage].Amount )
|
||||||
|
populationSize = td[current_stage].Amount
|
||||||
|
} else {
|
||||||
|
fixGoids(goids, populationSize, td[current_stage].Amount)
|
||||||
|
current_stage += 1
|
||||||
|
}
|
||||||
move(goids, fo)
|
move(goids, fo)
|
||||||
frame := draw(goids)
|
frame := draw(goids)
|
||||||
printImage(frame.SubImage(frame.Rect))
|
printImage(frame.SubImage(frame.Rect))
|
||||||
// fo.Write()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
showCursor()
|
showCursor()
|
||||||
}
|
}
|
||||||
@ -64,6 +95,7 @@ type Goid struct {
|
|||||||
Color color.Color
|
Color color.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func createRandomGoid() (g Goid) {
|
func createRandomGoid() (g Goid) {
|
||||||
g = Goid{
|
g = Goid{
|
||||||
X: rand.Intn(windowWidth),
|
X: rand.Intn(windowWidth),
|
||||||
|
Loading…
Reference in New Issue
Block a user