Skip to content
Snippets Groups Projects
Commit 20a32ab9 authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

Have to check in, before an experiment

parent fa33a486
Branches
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import (
"sync"
"example.com/ackley_mc/ackley"
"example.com/ackley_mc/ui"
)
const (
......@@ -48,7 +49,7 @@ type cprm struct { // parameters calculated from input
plotXtrj []float32 // for plotting trajectories
coolme bool // Cooling ? or just constant temperature ?
fplotWrt io.WriteCloser // Where to write the plot of function values
fplotiobuf *bytes.Buffer // The buffer possibly behind fplotWrt
fplotbuf *bytes.Buffer // The buffer possibly behind fplotWrt
xplotme bool // Are we plotting X trajectories
}
......@@ -101,7 +102,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
}
if mcPrm.fPltName != "" { // Then we are writing to a file
if mcPrm.fPltName, err = setSuffix(mcPrm.fPltName, ".png"); err != nil {
if mcPrm.fPltName, err = setSuffix(mcPrm.fPltName, ".svg"); err != nil {
return fmt.Errorf("plot filename: %w", err)
}
if cprm.fplotWrt, err = os.Create(mcPrm.fPltName); err != nil {
......@@ -110,7 +111,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
} else { // Must be writing to a screen
var w bytes.Buffer // could be fancy, preallocate and use bytes.Newbuffer
cprm.fplotWrt = addClose(&w) // Fix this, effectively two copies
cprm.fplotiobuf = &w // of the pointer
cprm.fplotbuf = &w // of the pointer
}
n_alloc := mcPrm.nStep / 5 // About a fifth of the number of steps
cprm.plotnstp = make([]float64, 0, n_alloc)
......@@ -120,7 +121,7 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
}
if mcPrm.xPltName != "" {
if mcPrm.xPltName, err = setSuffix(mcPrm.xPltName, ".png"); err != nil {
if mcPrm.xPltName, err = setSuffix(mcPrm.xPltName, ".svg"); err != nil {
return fmt.Errorf("plot filename: %w", err)
}
cprm.xplotme = true
......@@ -272,9 +273,9 @@ func doRun(mcPrm *mcPrm) error {
return err
}
if cprm.fplotiobuf != nil {
fmt.Println("len", cprm.fplotiobuf.Len())
scrnplt(cprm.fplotiobuf.Bytes())
if cprm.fplotbuf != nil {
fmt.Println("len", cprm.fplotbuf.Len())
ui.Scrnplt(cprm.fplotbuf.Bytes())
}
if err := plotxWrt(&cprm, mcPrm.xPltName, len(mcPrm.xIni)); err != nil {
return err
......
......@@ -143,7 +143,7 @@ func plotfWrt(cprm *cprm) error {
},
}
if err := graph.Render(chart.PNG, cprm.fplotWrt); err != nil {
if err := graph.Render(chart.SVG, cprm.fplotWrt); err != nil {
return fmt.Errorf("Render: %w", err)
}
......@@ -201,7 +201,7 @@ func plotxWrt(cprm *cprm, xPltName string, ndim int) error {
return err
}
defer xPlt.Close()
if err := graph.Render(chart.PNG, xPlt); err != nil {
if err := graph.Render(chart.SVG, xPlt); err != nil {
return fmt.Errorf("plotting X trajectories: %w", err)
}
return nil
......
// 25 Jan 2020
// Given a buffer or two with a plot picture, send it to the screen
// I think this might be better in its own package
package mc_work
import (
"fmt"
)
func scrnplt (b []byte) {
fmt.Println ("scrnplt says hello, buf size", len(b))
}
// 25 Jan 2020
// Given a buffer or two with a plot picture, send it to the screen
// I think this might be better in its own package
package ui
import (
"bytes"
"fmt"
"image/color" // need this for the green ?
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
)
func Scrnplt (b []byte) {
fmt.Println ("scrnplt says buf size", len(b), "first few bytes:", string(b[:10]))
a := app.New()
w := a.NewWindow("container")
image := canvas.NewImageFromReader(bytes.NewReader(b), "boo.svg")
green := color.NRGBA{R: 0, G: 180, B: 0, A: 255}
text1 := canvas.NewText("Hello", green); print(text1)
text2 := canvas.NewText("There", green)
text2.Move(fyne.NewPos(20, 20))
content := container.NewWithoutLayout( image) // no more text 1, text2
// content := container.New(layout.NewGridLayout(2), text1, text2)
w.SetContent(content)
w.ShowAndRun()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment