ginger/gim/main.go

84 lines
1.8 KiB
Go
Raw Normal View History

2017-11-02 22:45:10 +00:00
package main
import (
"fmt"
"math/rand"
"os"
"strings"
"time"
"github.com/mediocregopher/ginger/gg"
"github.com/mediocregopher/ginger/gim/geo"
"github.com/mediocregopher/ginger/gim/terminal"
2017-11-02 22:45:10 +00:00
)
// Leave room for:
// - Changing the "flow" direction
// - Absolute positioning of some/all vertices
// TODO
// - assign edges to "slots" on boxes
2017-11-24 18:05:58 +00:00
// - finish initial implementation of constraint, use that to sort boxes by
// primary and secondary flowDir based on their edges
// - be able to draw circular graphs
2017-11-02 22:45:10 +00:00
const (
framerate = 10
2017-11-02 22:45:10 +00:00
frameperiod = time.Second / time.Duration(framerate)
rounder = geo.Ceil
2017-11-02 22:45:10 +00:00
)
func debugf(str string, args ...interface{}) {
if !strings.HasSuffix(str, "\n") {
str += "\n"
}
2017-11-02 22:45:10 +00:00
fmt.Fprintf(os.Stderr, str, args...)
}
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"))
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"))
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"))
return g
}
//func mkGraph() *gg.Graph {
// g := gg.Null
// g = g.AddValueIn(gg.ValueOut(str("a"), str("e")), str("b"))
// return g
//}
2017-11-02 22:45:10 +00:00
func main() {
rand.Seed(time.Now().UnixNano())
term := terminal.New()
term.Reset()
term.HideCursor()
v := view{
g: mkGraph(),
flowDir: geo.Down,
2017-11-24 18:05:58 +00:00
start: gg.Str("c"),
center: geo.Zero.Midpoint(term.WindowSize(), rounder),
}
for range time.Tick(frameperiod) {
term.Reset()
v.draw(term)
term.Flush()
2017-11-02 22:45:10 +00:00
}
}