about summary refs log tree commit diff
path: root/main.go
blob: 1126af27867b496407f599e57592b763e3e0909b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main

import (
	"encoding/json"
	"fmt"
	"git.darknebu.la/GalaxySimulator/Source/csv"
	"git.darknebu.la/GalaxySimulator/Source/structs"
	"os"
)

type Config struct {
	Threads    int    `json:"Threads"`
	Frames     int    `json:"Frames"`
	RangeStart int    `json:"RangeStart"`
	RangeEnd   int    `json:"RangeEnd"`
	LoadPath   string `json:"LoadPath"`
	OutPath    string `json:"OutPath"`
}

func main() {
	// Load the config
	var config Config = LoadConfiguration("config.json")

	fmt.Printf("[ ] Utilizing %d threads ", config.Threads)
	fmt.Printf("for drawing %d Frames, ", config.Frames)
	fmt.Printf("each containing %d Stars.\n", config.RangeEnd)

	fmt.Printf("[ ] Getting previously existing Stars from %s ", config.LoadPath)
	fmt.Printf("and writing the results to %s.\n", config.OutPath)

	// the slice starsSlice stores the star structures
	starsSlice := []structs.Star2D{
		structs.Star2D{
			C: structs.Vec2{
				X: -1e5,
				Y: 0,
			},
			V: structs.Vec2{
				X: 0,
				Y: 0,
			},
			M: 1e10,
		},
		structs.Star2D{
			C: structs.Vec2{
				X: 1e5,
				Y: 0,
			},
			V: structs.Vec2{
				X: 0,
				Y: 0,
			},
			M: 1e10,
		},
		structs.Star2D{
			C: structs.Vec2{
				X: 0,
				Y: 4e4,
			},
			V: structs.Vec2{
				X: 0,
				Y: 0,
			},
			M: 1e10,
		},
	}

	// import existing stars from a csv
	// generate new stars in a homogeneous grid

	starsSlice = csv.GenerateHomogeneousGrid(starsSlice, -5e5, 5e5, 1e5)
	fmt.Printf("Amount of Stars: %d\n", len(starsSlice))
	//starsSlice = csv.Import(config.LoadPath, config.RangeStart, config.RangeEnd, starsSlice)

	fmt.Println("[+] Done loading the data.")

	// Iterate over all the frames
	for i := 0; i < config.Frames; i++ {
		fmt.Printf("[ ] Frame %d\n", i)

		// Create a new quadtree
		boundary := *structs.NewBoundingBox(structs.Vec2{0, 0}, 1e8)
		starsQuadtree := *structs.NewQuadtree(boundary)

		// Print all the elements in the stars Slice
		for _, element := range starsSlice {
			fmt.Println(element)
		}

		// Insert all the stars from the starsSlice into the Quadtree
		//starQuadtree := quadtree.InsertSlice(starsSlice)

		//starsSlice = forces.NextTimestep(starsSlice, 25*math.Pow(10, 4+7))
		//starsSlice = forces.CalcAllAccelerations(starsSlice, config.Threads)
		//var starsQuadtree quadtree.Quadtree = quadtree.CreateWithSlice(starsSlice)
		//quadtree.Print(&starsQuadtree)
		//quadtree.Draw(&starsQuadtree)
		//quadtree.DrawQuadtree(starsQuadtree)

		fmt.Println("[+] Done Calculating the forces acting.")

		// draw the galaxy
		//fmt.Println("[ ] Drawing the Stars")
		//outputName := fmt.Sprintf("out_%d.png", i+4)
		//draw.Slice(starsSlice, outputName)
		//fmt.Println("[+] Done drawing all the stars")
	}
}

// LoadConfiguration loads a configuration file from a given path and returns a struct with
// the values that are defined inside of the configuration file.
func LoadConfiguration(file string) Config {

	// Define some config defaults
	var config = Config{
		Threads:    1,
		Frames:     1,
		RangeStart: 0,
		RangeEnd:   1,
		OutPath:    "",
	}

	// Reading the config file and closing when done
	configFile, _ := os.Open(file)
	defer configFile.Close()

	// Parsing the content and adding it to the config struct
	jsonParser := json.NewDecoder(configFile)
	err := jsonParser.Decode(&config)
	if err != nil {
		panic(err)
	}

	// Returning the config for further use
	return config
}