diff options
author | emile <hanemile@protonmail.com> | 2018-10-09 17:05:25 +0200 |
---|---|---|
committer | emile <hanemile@protonmail.com> | 2018-10-09 17:05:25 +0200 |
commit | d1dbd0d66ebee806843191fd5b213500d6d48c2f (patch) | |
tree | fecc7c48998132e43dc7b865cf43f98e9437639f | |
parent | 6e9ebcf82cad78b468834ce07882db3c5ac45a53 (diff) |
Trying out channels
-rw-r--r-- | draw/draw.go | 8 | ||||
-rw-r--r-- | llog/llog.go | 4 | ||||
-rw-r--r-- | main.go | 22 |
3 files changed, 13 insertions, 21 deletions
diff --git a/draw/draw.go b/draw/draw.go index 74e9a10..73cbc5c 100644 --- a/draw/draw.go +++ b/draw/draw.go @@ -35,7 +35,7 @@ func saveImage(dc *gg.Context, path string) { // drawStar draws the given stars to the given context func drawStar(dc *gg.Context, star structs.Star) { - dc.DrawPoint(star.C.X, star.C.Y, 2) + dc.DrawPoint(star.C.X/10, star.C.Y/10, 2) dc.Fill() dc.Stroke() } @@ -47,10 +47,10 @@ func vectorLength(force structs.Force) float64 { func drawForce(dc *gg.Context, star structs.Star) { // controll the length of the vector - var scalingFactor float64 = 40 + var scalingFactor float64 = 32 // Move the "cursor" to the start position of the vector - dc.MoveTo(star.C.X, star.C.Y) + dc.MoveTo(star.C.X/10, star.C.Y/10) // calculate the length of the vector vecLength := vectorLength(star.F) @@ -65,7 +65,7 @@ func drawForce(dc *gg.Context, star structs.Star) { // trace the Vector FxUnit := star.F.X / math.Abs(vecLength) FyUnit := star.F.Y / math.Abs(vecLength) - dc.LineTo(star.C.X+(FxUnit*scalingFactor), star.C.Y+(FyUnit*scalingFactor)) + dc.LineTo(star.C.X/10+(FxUnit*scalingFactor), star.C.Y/10+(FyUnit*scalingFactor)) // css dc.SetLineWidth(2) diff --git a/llog/llog.go b/llog/llog.go index 54620ed..b063610 100644 --- a/llog/llog.go +++ b/llog/llog.go @@ -6,8 +6,8 @@ import ( ) // Good prints a "good" (green) message with a timestamp and the given message -func Good(text string) { - fmt.Printf("%s\033[36m [+] \033[0m%-60s\t", currentTime(), text) +func Good(before string) { + fmt.Printf("%s\033[36m [+] \033[0m%-60s\t", currentTime(), before) } // Bad prints a "good" (green) message with a timestamp and the given message diff --git a/main.go b/main.go index e10aa2a..d173cba 100644 --- a/main.go +++ b/main.go @@ -9,14 +9,6 @@ import ( "fmt" ) -func AddToChannel(starsChan chan structs.Star, slice []structs.Star) { - - for index, _ := range slice { - starsChan <- slice[index] - } - -} - func main() { // the slice starsSlice stores the star structures starsSlice := []structs.Star{ @@ -29,18 +21,18 @@ func main() { {structs.Coord{X: 20000.0, Y: 80000}, structs.Force{X: 0, Y: 0}, 4000000}, } - // Define a channel - starsChannel := make(chan structs.Star, len(starsSlice)) - llog.Good("Opening the csv") starsSlice = csv.Import("data/structure03.ita.uni-heidelberg.de_26635.csv", 0, 2000, starsSlice) - go AddToChannel(starsChannel, starsSlice) + // starsSlice = csv.Import("data/U_ALL.csv", 0, 2000, starsSlice) fmt.Printf("Done\n") llog.Good("Calculate the acting forces") forces.CalcAllForces(starsSlice) - llog.Good("Drawing the slice") - draw.Slice(starsSlice, "out_50000.png") - fmt.Printf("Done\n") + // Filename without suffix and extension + path := "out" + + llog.Good(fmt.Sprintf("draw the slice and save it to %s", path)) + draw.Slice(starsSlice, path) + } |