Skip to content

Commit

Permalink
fix error with opening autosave file; more tug of war example graph i…
Browse files Browse the repository at this point in the history
…mprovements
  • Loading branch information
kkoreilly committed Sep 7, 2024
1 parent fc0b755 commit 7feb30b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion marbles/graphs/tug-of-war.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Params":{"NMarbles":100,"MarbleStartX":{"Expr":"if(rand\u003c0.5, 5(rand+0.1), 5(rand-1.1))"},"MarbleStartY":{"Expr":"10-2n/nmarbles"},"StartVelocityY":{"Expr":{"Expr":"0"}},"StartVelocityX":{"Expr":{"Expr":"0"}},"UpdateRate":{"Expr":{"Expr":".02"}},"TimeStep":{"Expr":{"Expr":"0.01"}},"YForce":{"Expr":{"Expr":"-0.1"}},"XForce":{"Expr":{"Expr":"0"}},"CenterX":{"Expr":{"Expr":"0"}},"CenterY":{"Expr":{"Expr":"0"}},"TrackingSettings":{"TrackByDefault":false,"NTrackingFrames":300,"Accuracy":20,"LineColor":{"R":255,"G":255,"B":255,"A":255}}},"Lines":[{"Expr":{"Expr":"x^2/3"},"GraphIf":{"Expr":"false"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":0,"G":182,"B":77,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}},{"Expr":{"Expr":"f(x+5)-h/100"},"GraphIf":{"Expr":"x\u003c-0.01"},"Bounce":{"Expr":"0.3rand+0.8"},"Colors":{"Color":{"R":255,"G":0,"B":0,"A":255},"ColorSwitch":{"R":255,"G":0,"B":0,"A":255}}},{"Expr":{"Expr":"f(x-5)-h/100"},"GraphIf":{"Expr":"x\u003e0"},"Bounce":{"Expr":"0.3rand+0.8"},"Colors":{"Color":{"R":0,"G":0,"B":255,"A":255},"ColorSwitch":{"R":0,"G":0,"B":255,"A":255}}},{"Expr":{"Expr":"gx-bx-f(x+5)+f(x-5)"},"GraphIf":{"Expr":"false"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":188,"G":174,"B":0,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}},{"Expr":{"Expr":"9"},"GraphIf":{"Expr":"t\u003e1\u0026\u0026cx\u003e0\u0026\u0026abs(x-cx)\u003c1"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":0,"G":0,"B":255,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}},{"Expr":{"Expr":"9"},"GraphIf":{"Expr":"t\u003e1\u0026\u0026cx\u003c0\u0026\u0026abs(x-cx)\u003c1"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":255,"G":0,"B":0,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}}]}
{"Params":{"NMarbles":100,"MarbleStartX":{"Expr":"if(n%2==0, 5(rand+0.1), 5(rand-1.1))"},"MarbleStartY":{"Expr":"10-2n/nmarbles"},"StartVelocityY":{"Expr":{"Expr":"0"}},"StartVelocityX":{"Expr":{"Expr":"0"}},"UpdateRate":{"Expr":{"Expr":".02"}},"TimeStep":{"Expr":{"Expr":"0.01"}},"YForce":{"Expr":{"Expr":"-0.1"}},"XForce":{"Expr":{"Expr":"0"}},"CenterX":{"Expr":{"Expr":"0"}},"CenterY":{"Expr":{"Expr":"0"}},"TrackingSettings":{"TrackByDefault":false,"NTrackingFrames":300,"Accuracy":20,"LineColor":{"R":255,"G":255,"B":255,"A":255}}},"Lines":[{"Expr":{"Expr":"x^2/3"},"GraphIf":{"Expr":"false"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":0,"G":182,"B":77,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}},{"Expr":{"Expr":"f(x+5)-h/100"},"GraphIf":{"Expr":"x\u003c-0.01"},"Bounce":{"Expr":"0.3rand+0.8"},"Colors":{"Color":{"R":255,"G":0,"B":0,"A":255},"ColorSwitch":{"R":255,"G":0,"B":0,"A":255}}},{"Expr":{"Expr":"f(x-5)-h/100"},"GraphIf":{"Expr":"x\u003e0"},"Bounce":{"Expr":"0.3rand+0.8"},"Colors":{"Color":{"R":0,"G":0,"B":255,"A":255},"ColorSwitch":{"R":0,"G":0,"B":255,"A":255}}},{"Expr":{"Expr":"gx-bx-f(x+5)+f(x-5)"},"GraphIf":{"Expr":"false"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":188,"G":174,"B":0,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}},{"Expr":{"Expr":"9"},"GraphIf":{"Expr":"t\u003e1\u0026\u0026cx\u003e=0\u0026\u0026abs(x-cx)\u003c1"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":0,"G":0,"B":255,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}},{"Expr":{"Expr":"9"},"GraphIf":{"Expr":"t\u003e1\u0026\u0026cx\u003c0\u0026\u0026abs(x-cx)\u003c1"},"Bounce":{"Expr":"0.95"},"Colors":{"Color":{"R":255,"G":0,"B":0,"A":255},"ColorSwitch":{"R":255,"G":255,"B":255,"A":255}}}]}
5 changes: 5 additions & 0 deletions marbles/io.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"errors"
"fmt"
"io/fs"
"path/filepath"

"cogentcore.org/core/base/iox/jsonx"
Expand Down Expand Up @@ -31,6 +33,9 @@ func (gr *Graph) OpenJSON(filename core.Filename) error { //types:add
// OpenAutoSave opens the last graphed graph, stays between sessions of the app
func (gr *Graph) OpenAutoSave() error {
err := jsonx.Open(gr, filepath.Join(core.TheApp.AppDataDir(), "autosave.json"))
if errors.Is(err, fs.ErrNotExist) {
return nil
}
if HandleError(err) {
return err
}
Expand Down

0 comments on commit 7feb30b

Please sign in to comment.