Remove simulation.go and move its code to animation.go
This commit is contained in:
parent
37daa05e1c
commit
00972bfa83
31
animate.go
31
animate.go
|
@ -1,12 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
"github.com/status-im/simulation/propagation"
|
||||
)
|
||||
|
||||
const BlinkDecay = 100 * time.Millisecond
|
||||
const (
|
||||
// TODO(divan): move this as variables to the frontend
|
||||
BlinkDecay = 100 * time.Millisecond // time for highlighted node/link to be active
|
||||
AnimationSlowdown = 1 // slowdown factor for propagation animation
|
||||
)
|
||||
|
||||
func (w *WebGLScene) animate() {
|
||||
if w.renderer == nil {
|
||||
|
@ -56,3 +62,26 @@ func (w *WebGLScene) BlinkEdge(id int) {
|
|||
restore := func() { edge.Object.Set("material", DefaultEdgeMaterial) }
|
||||
time.AfterFunc(BlinkDecay, restore)
|
||||
}
|
||||
|
||||
// AnimatePropagation visualizes propagation of message based on plog.
|
||||
func (w *WebGLScene) AnimatePropagation(plog *propagation.Log) {
|
||||
fmt.Println("Animating plog")
|
||||
for i, ts := range plog.Timestamps {
|
||||
duration := time.Duration(time.Duration(ts) * time.Millisecond)
|
||||
duration = duration * AnimationSlowdown
|
||||
|
||||
nodes := plog.Nodes[i]
|
||||
edges := plog.Indices[i]
|
||||
fn := func() {
|
||||
// blink nodes for this timestamp
|
||||
for _, idx := range nodes {
|
||||
w.BlinkNode(idx)
|
||||
}
|
||||
// blink links for this timestamp
|
||||
for _, idx := range edges {
|
||||
w.BlinkEdge(idx)
|
||||
}
|
||||
}
|
||||
time.AfterFunc(duration, fn)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/status-im/simulation/propagation"
|
||||
)
|
||||
|
||||
const AnimationSlowdown = 1
|
||||
|
||||
// AnimatePropagation visualizes propagation of message based on plog.
|
||||
func (w *WebGLScene) AnimatePropagation(plog *propagation.Log) {
|
||||
fmt.Println("Animating plog")
|
||||
for i, ts := range plog.Timestamps {
|
||||
duration := time.Duration(time.Duration(ts) * time.Millisecond)
|
||||
duration = duration * AnimationSlowdown
|
||||
|
||||
nodes := plog.Nodes[i]
|
||||
edges := plog.Indices[i]
|
||||
fn := func() {
|
||||
// blink nodes for this timestamp
|
||||
for _, idx := range nodes {
|
||||
w.BlinkNode(idx)
|
||||
}
|
||||
// blink links for this timestamp
|
||||
for _, idx := range edges {
|
||||
w.BlinkEdge(idx)
|
||||
}
|
||||
}
|
||||
time.AfterFunc(duration, fn)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue