diff options
author | hanemile <hanemile@protonmail.com> | 2019-01-24 20:53:22 +0100 |
---|---|---|
committer | hanemile <hanemile@protonmail.com> | 2019-01-24 20:53:22 +0100 |
commit | ff57616581f71ae0596e9ddaf4ef05df17f881ce (patch) | |
tree | 26f64876390278095a8bd03872e7b6d82ae97f0c | |
parent | 944b12cb85557e5d33c533ce65e29d057ca8d5a2 (diff) |
implemented the calcNewPos function calculating the new position of a star and the insertStar function inserting the simulated star into a new tree
-rw-r--r-- | main.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/main.go b/main.go index 01a15f4..d9ab41f 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "net/url" "os" "runtime" + "strconv" "time" "git.darknebu.la/GalaxySimulator/structs" @@ -149,8 +150,49 @@ func processstars(url string, core int) { func insertStar(star structs.Star2D, galaxyindex int64) { // if the galaxy does not exist yet, create it + requrl := "http://db.nbg1.emile.space/nrofgalaxies" + resp, err := http.Get(requrl) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + currentAmounfOfGalaxies, _ := strconv.ParseInt(string(body), 10, 64) + + // if there is no galaxy to insert the star into, create it + if currentAmounfOfGalaxies <= galaxyindex { + + // create the new galaxy using a post request + requestURL := "http://db.nbg1.emile.space/new" + resp, err := http.PostForm(requestURL, + url.Values{ + "w": {fmt.Sprintf("%d", 1000000000)}, + }, + ) + if err != nil { + fmt.Printf("Cound not make a POST request to %s", requestURL) + } + defer resp.Body.Close() + } // insert the star into the galaxy + + // create the new galaxy using a post request + requestURL := fmt.Sprintf("http://db.nbg1.emile.space/insert/%d", galaxyindex) + resp, err = http.PostForm(requestURL, + url.Values{ + "x": {fmt.Sprintf("%d", star.C.X)}, + "y": {fmt.Sprintf("%d", star.C.Y)}, + "vx": {fmt.Sprintf("%d", star.V.X)}, + "vy": {fmt.Sprintf("%d", star.V.Y)}, + "m": {fmt.Sprintf("%d", star.M)}, + }, + ) + if err != nil { + fmt.Printf("Cound not make a POST request to %s", requestURL) + } + defer resp.Body.Close() } // calcallforces calculates the forces acting on a given star using the given |