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...)
|
|
|
|
}
|
|
|
|
|
2017-11-19 21:39:56 +00:00
|
|
|
func mkGraph() *gg.Graph {
|
2017-11-24 18:05:58 +00:00
|
|
|
aE0 := gg.ValueOut(gg.Str("a"), gg.Str("aE0"))
|
|
|
|
aE1 := gg.ValueOut(gg.Str("a"), gg.Str("aE1"))
|
|
|
|
aE2 := gg.ValueOut(gg.Str("a"), gg.Str("aE2"))
|
|
|
|
aE3 := gg.ValueOut(gg.Str("a"), gg.Str("aE3"))
|
2017-11-19 21:39:56 +00:00
|
|
|
g := gg.Null
|
2017-11-24 18:05:58 +00:00
|
|
|
g = g.AddValueIn(aE0, gg.Str("b0"))
|
|
|
|
g = g.AddValueIn(aE1, gg.Str("b1"))
|
|
|
|
g = g.AddValueIn(aE2, gg.Str("b2"))
|
|
|
|
g = g.AddValueIn(aE3, gg.Str("b3"))
|
2017-11-19 21:39:56 +00:00
|
|
|
|
|
|
|
jE := gg.JunctionOut([]gg.OpenEdge{
|
2017-11-24 18:05:58 +00:00
|
|
|
gg.ValueOut(gg.Str("b0"), gg.Str("")),
|
|
|
|
gg.ValueOut(gg.Str("b1"), gg.Str("")),
|
|
|
|
gg.ValueOut(gg.Str("b2"), gg.Str("")),
|
|
|
|
gg.ValueOut(gg.Str("b3"), gg.Str("")),
|
|
|
|
}, gg.Str("jE"))
|
|
|
|
g = g.AddValueIn(jE, gg.Str("c"))
|
2017-11-19 21:39:56 +00:00
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
//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
|
|
|
|
2017-11-23 19:19:32 +00:00
|
|
|
v := view{
|
2017-12-03 19:38:53 +00:00
|
|
|
g: mkGraph(),
|
|
|
|
primFlowDir: geo.Right,
|
|
|
|
secFlowDir: geo.Down,
|
|
|
|
start: gg.Str("c"),
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|