2017-11-02 22:45:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2017-11-19 21:39:56 +00:00
|
|
|
"github.com/mediocregopher/ginger/gg"
|
2017-11-04 21:29:15 +00:00
|
|
|
"github.com/mediocregopher/ginger/gim/geo"
|
|
|
|
"github.com/mediocregopher/ginger/gim/terminal"
|
2017-11-02 22:45:10 +00:00
|
|
|
)
|
|
|
|
|
2017-11-19 21:39:56 +00:00
|
|
|
// Leave room for:
|
|
|
|
// - Changing the "flow" direction
|
|
|
|
// - Absolute positioning of some/all vertices
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// - assign edges to "slots" on boxes
|
2017-12-03 19:38:53 +00:00
|
|
|
// - edge values
|
2017-11-23 19:19:32 +00:00
|
|
|
// - be able to draw circular graphs
|
2017-12-03 19:38:53 +00:00
|
|
|
// - audit all steps, make sure everything is deterministic
|
2017-11-19 21:39:56 +00:00
|
|
|
|
2017-11-02 22:45:10 +00:00
|
|
|
const (
|
2017-11-04 21:29:15 +00:00
|
|
|
framerate = 10
|
2017-11-02 22:45:10 +00:00
|
|
|
frameperiod = time.Second / time.Duration(framerate)
|
2017-11-19 21:39:56 +00:00
|
|
|
rounder = geo.Ceil
|
2017-11-02 22:45:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func debugf(str string, args ...interface{}) {
|
2017-11-04 21:29:15 +00:00
|
|
|
if !strings.HasSuffix(str, "\n") {
|
|
|
|
str += "\n"
|
|
|
|
}
|
2017-11-02 22:45:10 +00:00
|
|
|
fmt.Fprintf(os.Stderr, str, args...)
|
|
|
|
}
|
|
|
|
|
2018-01-21 15:39:25 +00:00
|
|
|
func mkGraph() (*gg.Graph, gg.Value) {
|
|
|
|
a := gg.NewValue("a")
|
|
|
|
aE0 := gg.NewValue("aE0")
|
|
|
|
aE1 := gg.NewValue("aE1")
|
|
|
|
aE2 := gg.NewValue("aE2")
|
|
|
|
aE3 := gg.NewValue("aE3")
|
|
|
|
b0 := gg.NewValue("b0")
|
|
|
|
b1 := gg.NewValue("b1")
|
|
|
|
b2 := gg.NewValue("b2")
|
|
|
|
b3 := gg.NewValue("b3")
|
|
|
|
oaE0 := gg.ValueOut(a, aE0)
|
|
|
|
oaE1 := gg.ValueOut(a, aE1)
|
|
|
|
oaE2 := gg.ValueOut(a, aE2)
|
|
|
|
oaE3 := gg.ValueOut(a, aE3)
|
2017-11-19 21:39:56 +00:00
|
|
|
g := gg.Null
|
2018-01-21 15:39:25 +00:00
|
|
|
g = g.AddValueIn(oaE0, b0)
|
|
|
|
g = g.AddValueIn(oaE1, b1)
|
|
|
|
g = g.AddValueIn(oaE2, b2)
|
|
|
|
g = g.AddValueIn(oaE3, b3)
|
2017-11-19 21:39:56 +00:00
|
|
|
|
2018-01-21 15:39:25 +00:00
|
|
|
c := gg.NewValue("c")
|
|
|
|
empty := gg.NewValue("")
|
2017-11-19 21:39:56 +00:00
|
|
|
jE := gg.JunctionOut([]gg.OpenEdge{
|
2018-01-21 15:39:25 +00:00
|
|
|
gg.ValueOut(b0, empty),
|
|
|
|
gg.ValueOut(b1, empty),
|
|
|
|
gg.ValueOut(b2, empty),
|
|
|
|
gg.ValueOut(b3, empty),
|
|
|
|
}, gg.NewValue("jE"))
|
|
|
|
g = g.AddValueIn(jE, c)
|
|
|
|
return g, c
|
2017-11-19 21:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//func mkGraph() *gg.Graph {
|
|
|
|
// g := gg.Null
|
|
|
|
// g = g.AddValueIn(gg.ValueOut(str("a"), str("e")), str("b"))
|
|
|
|
// return g
|
|
|
|
//}
|
2017-11-04 21:29:15 +00:00
|
|
|
|
2017-11-02 22:45:10 +00:00
|
|
|
func main() {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
2017-11-04 21:29:15 +00:00
|
|
|
term := terminal.New()
|
2017-11-19 21:39:56 +00:00
|
|
|
term.Reset()
|
2017-11-23 19:19:32 +00:00
|
|
|
term.HideCursor()
|
2017-11-19 21:39:56 +00:00
|
|
|
|
2018-01-21 15:39:25 +00:00
|
|
|
g, start := mkGraph()
|
2017-11-23 19:19:32 +00:00
|
|
|
v := view{
|
2018-01-21 15:39:25 +00:00
|
|
|
g: g,
|
2017-12-03 19:38:53 +00:00
|
|
|
primFlowDir: geo.Right,
|
|
|
|
secFlowDir: geo.Down,
|
2018-01-21 15:39:25 +00:00
|
|
|
start: start,
|
2017-12-03 19:38:53 +00:00
|
|
|
center: geo.Zero.Midpoint(term.WindowSize(), rounder),
|
2017-11-19 21:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for range time.Tick(frameperiod) {
|
2017-11-04 21:29:15 +00:00
|
|
|
term.Reset()
|
2017-11-23 19:19:32 +00:00
|
|
|
v.draw(term)
|
2017-11-04 21:29:15 +00:00
|
|
|
term.Flush()
|
2017-11-02 22:45:10 +00:00
|
|
|
}
|
|
|
|
}
|