-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
118 lines (91 loc) · 2.84 KB
/
Copy pathmain.go
File metadata and controls
118 lines (91 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
"github.com/mmoghaddam385/stock-market-visualizer/visualizer"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
screenWidth = 800 * 2
screenHeight = 600 * 2
)
type Renderer struct {
v visualizer.Visualizer
}
func main() {
cmd := cobra.Command{
Use: "screen-saver",
Short: "Run a visualization that looks like a screen saver",
Long: "Don't actually use this as a screen saver, it won't save your screen but it'll look cool.",
PersistentPreRunE: rootPersistentPreRun,
RunE: runE,
}
cmd.Flags().Bool("fullscreen", false, "whether or not to start the program in fullscreen mode")
cmd.Flags().Float64("scale", 1, "The scaling factor to use for visualizations")
if err := cmd.Execute(); err != nil {
logrus.WithError(err).Fatal("exiting with error")
}
}
func runE(_ *cobra.Command, args []string) error {
cfg := visualizer.Config{
WindowWidth: 800,
WindowHeight: 600,
}
//rl.SetConfigFlags(rl.FlagMsaa4xHint | rl.FlagVsyncHint)
rl.InitWindow(cfg.WindowWidth, cfg.WindowHeight, "some kinda visualizer")
if viper.GetBool("fullscreen") {
display := rl.GetCurrentMonitor()
cfg.WindowWidth = int32(rl.GetMonitorWidth(display))
cfg.WindowHeight = int32(rl.GetMonitorHeight(display))
rl.SetWindowSize(int(cfg.WindowWidth), int(cfg.WindowHeight))
rl.ToggleFullscreen()
rl.HideCursor()
}
rl.SetTargetFPS(60)
scale := viper.GetFloat64("scale")
scaleCamera := rl.NewCamera2D(rl.Vector2{}, rl.Vector2{}, 0, float32(scale))
cfg.WindowWidth = int32(float64(cfg.WindowWidth) / scale)
cfg.WindowHeight = int32(float64(cfg.WindowHeight) / scale)
cfg.ScaleFactor = float32(scale)
v := visualizer.NewPlinko(cfg)
debug := false
for !rl.WindowShouldClose() {
if rl.GetCharPressed() == 'd' {
debug = !debug
}
v.Update(rl.GetFrameTime())
rl.BeginDrawing()
rl.BeginMode2D(scaleCamera)
v.Draw(debug)
rl.EndMode2D()
if debug {
rl.DrawText(fmt.Sprintf("FPS: %.2f; %v", rl.GetFPS(), rl.GetKeyPressed()), 10, 10, 12, rl.RayWhite)
}
rl.EndDrawing()
}
rl.CloseWindow()
return nil
}
// bindViperFlagsPreRun binds the flags for a command in PreRunE.
// This has to be done in pre-run because it can only run for the command+subcommands that are actually going to execute.
func bindViperFlagsPreRun(cmd *cobra.Command, _ []string) error {
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err
}
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return nil
}
func rootPersistentPreRun(cmd *cobra.Command, args []string) error {
if err := bindViperFlagsPreRun(cmd, args); err != nil {
return err
}
if viper.GetBool("verbose") {
logrus.SetLevel(logrus.TraceLevel)
}
logrus.SetOutput(cmd.ErrOrStderr())
return nil
}