more code cleanup
This commit is contained in:
67
main.go
67
main.go
@@ -17,8 +17,7 @@ import (
|
||||
//"github.com/ojrac/opensimplex-go"
|
||||
)
|
||||
|
||||
|
||||
func Bootstrap() sg.Graphics {
|
||||
func Bootstrap() *Env {
|
||||
|
||||
rl.InitWindow(800, 600, "bootstrap")
|
||||
|
||||
@@ -48,6 +47,8 @@ func Bootstrap() sg.Graphics {
|
||||
defaultWindowWidth, defaultWindowHeight,
|
||||
defaultGraphicsWidth, defaultWindowHeight)
|
||||
|
||||
var snapshotsPath string
|
||||
|
||||
flag.StringVar(&snapshotsPath, "path", "snapshots", "Path to snapshots and db")
|
||||
flag.IntVar(&graphicsWidth, "gw", defaultGraphicsWidth, "Width of the internal graphics buffer. Can be much larger than the screen.")
|
||||
flag.IntVar(&graphicsHeight, "gh", defaultGraphicsHeight, "Height of the internal graphics buffer. Can be much larger than the screen.")
|
||||
@@ -64,50 +65,47 @@ func Bootstrap() sg.Graphics {
|
||||
|
||||
os.MkdirAll(snapshotsPath, 0755)
|
||||
var err error
|
||||
storage, err = NewStorage(snapshotsPath)
|
||||
storage, err := NewStorage(snapshotsPath)
|
||||
if err != nil {
|
||||
log.Printf("Error loading storage: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
layout := sg.Layout {
|
||||
Monitor: sg.Rect{X: 0, Y: 0, Width: float32(monitorWidth), Height: float32(monitorHeight)},
|
||||
Window: sg.Rect{X: 0, Y: 0, Width: float32(windowWidth), Height: float32(windowHeight)},
|
||||
Controls: sg.Rect{X: 0, Y: 0, Width: float32(controlsWidth), Height: float32(windowHeight)},
|
||||
Viewport: sg.Rect{X: float32(controlsWidth), Y: 0, Width: float32(viewportWidth), Height: float32(windowHeight)},
|
||||
Graphics: sg.Rect{X: 0, Y: 0, Width: float32(graphicsWidth), Height: float32(graphicsHeight)},
|
||||
layout := Layout{
|
||||
Monitor: sg.Rect{X: 0, Y: 0, Width: float32(monitorWidth), Height: float32(monitorHeight)},
|
||||
Window: sg.Rect{X: 0, Y: 0, Width: float32(windowWidth), Height: float32(windowHeight)},
|
||||
Controls: sg.Rect{X: 0, Y: 0, Width: float32(controlsWidth), Height: float32(windowHeight)},
|
||||
Viewport: sg.Rect{X: float32(controlsWidth), Y: 0, Width: float32(viewportWidth), Height: float32(windowHeight)},
|
||||
Offscreen: sg.Rect{X: 0, Y: 0, Width: float32(graphicsWidth), Height: float32(graphicsHeight)},
|
||||
}
|
||||
|
||||
//rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(int32(layout.Window.Width), int32(layout.Window.Height), "sumi sierpinski arrow")
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
return sg.Graphics {
|
||||
Layout: layout,
|
||||
Style: sg.Style {
|
||||
Fill: false,
|
||||
FillColor: rl.RayWhite,
|
||||
Stroke: true,
|
||||
StrokeColor: rl.Black,
|
||||
StrokeWeight: 1.0,
|
||||
},
|
||||
}
|
||||
env := NewEnv()
|
||||
env.Layout = layout
|
||||
env.Window = sg.CreateGraphics(layout.Window)
|
||||
env.Viewport = sg.CreateGraphics(layout.Viewport)
|
||||
env.Offscreen = sg.CreateGraphics(layout.Offscreen)
|
||||
env.Controls = sg.CreateGraphics(layout.Controls)
|
||||
env.Storage = storage
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
|
||||
g := Bootstrap()
|
||||
env := Bootstrap()
|
||||
|
||||
// reproducable flourescent color cycle
|
||||
colorCycle := sg.NewFixedColorCycle(sg.FlourescentColors).Shuffle(0)
|
||||
|
||||
t0 := time.Now()
|
||||
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
rng := rand.New(rand.NewSource(env.Time.Unix()))
|
||||
//imageField := NewImageField("/home/d/Dropbox/art/data/david.png")
|
||||
noiseField := &SimplexNoiseField{Noise: opensimplex.New32(0)}
|
||||
noiseField := &SimplexNoiseField{Noise: opensimplex.New32(env.Time.Unix())}
|
||||
sinXYField := &SinXYField{}
|
||||
//imageField := NewImageField("/home/d/Dropbox/art/data/ramstatue.png")
|
||||
//imageField := NewImageField("/home/d/Dropbox/art/data/bassrockastro/Photo Dec 24 2025, 5 58 23 PM.jpg")
|
||||
@@ -115,8 +113,8 @@ func main() {
|
||||
//imageField := NewImageField("/home/d/Dropbox/art/data/moses_statue.jpg")
|
||||
field :=
|
||||
&TranslateField{
|
||||
x: -float32(g.Layout.Graphics.Width / 2.0),
|
||||
y: -float32(g.Layout.Graphics.Height / 2.0),
|
||||
x: -float32(env.Offscreen.Bounds.Width / 2.0),
|
||||
y: -float32(env.Offscreen.Bounds.Height / 2.0),
|
||||
field: &ScaleField{
|
||||
scale: 100.0,
|
||||
field: &AdderField{
|
||||
@@ -130,7 +128,7 @@ func main() {
|
||||
|
||||
//sierpinskiLayer := &SierpinskiArrow { dirty: true }
|
||||
|
||||
sketch := NewSketch(&g)
|
||||
sketch := NewSketch(env)
|
||||
|
||||
fieldColor := colorCycle.Next()
|
||||
fmt.Printf("field color = %v\n", fieldColor)
|
||||
@@ -148,11 +146,10 @@ func main() {
|
||||
actorColor = sg.Clamp(actorColor, 10, 255)
|
||||
actorColor.A = 10
|
||||
|
||||
actorSGColor := sg.Color { R: actorColor.R, G: actorColor.G, B: actorColor.B, A: actorColor.A }
|
||||
//NewColor(11, 35, 176, 50),
|
||||
|
||||
//r
|
||||
contourLayer := NewContourLayer(&sketch, rng, field, actorSGColor, -25*math.Pi, 25*math.Pi)
|
||||
contourLayer := NewContourLayer(&sketch, rng, field, actorColor, -25*math.Pi, 25*math.Pi)
|
||||
sketch.AddLayer("contours", contourLayer)
|
||||
//sketch.AddLayer("sierpinski-arrowhead", sierpinskiLayer)
|
||||
// aurora := NewImageLayer("/home/d/Dropbox/photos/Events/2025/Aurora/Photo Nov 11 2025, 9 52 03 PM.jpg")
|
||||
@@ -181,14 +178,10 @@ func main() {
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
// begin drawing
|
||||
t := time.Since(t0).Seconds()
|
||||
t := time.Since(env.Time).Seconds()
|
||||
|
||||
// set up RenderCtx
|
||||
env := &Env {
|
||||
Graphics: g,
|
||||
Time: t,
|
||||
Ports: ports.Eval(t),
|
||||
}
|
||||
env.Time = time.Now()
|
||||
env.Ports = ports.Eval(t)
|
||||
|
||||
sketch.Update(env)
|
||||
|
||||
@@ -267,7 +260,7 @@ func main() {
|
||||
for ch := rl.GetCharPressed(); ch != 0; ch = rl.GetCharPressed() {
|
||||
c := rune(ch)
|
||||
if c == 'c' {
|
||||
sketch.ResetCamera()
|
||||
sketch.ResetCamera(env)
|
||||
} else if c >= '1' && c <= '9' {
|
||||
zoom := 1 << int(ch-'0')
|
||||
sketch.cam.Zoom = float32(zoom)
|
||||
|
||||
Reference in New Issue
Block a user