284 lines
8.9 KiB
Go
284 lines
8.9 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"math"
|
|
"math/rand"
|
|
"os"
|
|
"time"
|
|
|
|
sg "github.com/d2fn/sumi/internal/graphics"
|
|
"github.com/ojrac/opensimplex-go"
|
|
|
|
gui "github.com/gen2brain/raylib-go/raygui"
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
//"github.com/ojrac/opensimplex-go"
|
|
)
|
|
|
|
|
|
func Bootstrap() sg.Graphics {
|
|
|
|
rl.InitWindow(800, 600, "bootstrap")
|
|
|
|
monitor := rl.GetCurrentMonitor()
|
|
fmt.Printf("Using monitor %d\n", monitor)
|
|
|
|
// derive defaults from the monitor size
|
|
monitorWidth := rl.GetMonitorWidth(monitor)
|
|
monitorHeight := rl.GetMonitorHeight(monitor)
|
|
|
|
// use a large portion of the available space, but not all of it!
|
|
defaultWindowWidth := int(float32(monitorWidth) * 0.95)
|
|
defaultWindowHeight := int(float32(monitorHeight) * 0.9)
|
|
windowWidth := defaultWindowWidth
|
|
windowHeight := defaultWindowHeight
|
|
|
|
// set controls to use 1/6th of the width
|
|
controlsRelWidth := 1.0 / 12.0
|
|
|
|
defaultGraphicsWidth := 5 * int((float64(defaultWindowWidth) * (1.0 - controlsRelWidth)))
|
|
defaultGraphicsHeight := 5 * defaultWindowHeight
|
|
graphicsWidth := defaultGraphicsWidth
|
|
graphicsHeight := defaultGraphicsHeight
|
|
|
|
fmt.Printf("monitor : %d x %d / window : %d x %d / buffer : %d x %d",
|
|
monitorWidth, monitorHeight,
|
|
defaultWindowWidth, defaultWindowHeight,
|
|
defaultGraphicsWidth, defaultWindowHeight)
|
|
|
|
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.")
|
|
flag.IntVar(&windowWidth, "w", defaultWindowWidth, "Width of the display window")
|
|
flag.IntVar(&windowHeight, "h", defaultWindowHeight, "Height of the display window")
|
|
flag.Parse()
|
|
|
|
controlsWidth := int(float64(windowWidth) * controlsRelWidth)
|
|
viewportWidth := windowWidth - controlsWidth
|
|
|
|
rl.CloseWindow()
|
|
|
|
log.Printf("Storing snapshots at '%s'\n", snapshotsPath)
|
|
|
|
os.MkdirAll(snapshotsPath, 0755)
|
|
var err error
|
|
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)},
|
|
}
|
|
|
|
//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,
|
|
},
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
|
|
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
|
|
|
g := Bootstrap()
|
|
|
|
// reproducable flourescent color cycle
|
|
colorCycle := sg.NewFixedColorCycle(sg.FlourescentColors).Shuffle(0)
|
|
|
|
t0 := time.Now()
|
|
|
|
rng := rand.New(rand.NewSource(0))
|
|
//imageField := NewImageField("/home/d/Dropbox/art/data/david.png")
|
|
noiseField := &SimplexNoiseField{Noise: opensimplex.New32(0)}
|
|
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")
|
|
//imageField := NewImageField("/home/d/Dropbox/art/data/bassrockastro/andromeda.jpg")
|
|
//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),
|
|
field: &ScaleField{
|
|
scale: 100.0,
|
|
field: &AdderField{
|
|
fields: []Field{
|
|
&ScaleField{scale: 10, field: noiseField},
|
|
sinXYField,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
//sierpinskiLayer := &SierpinskiArrow { dirty: true }
|
|
|
|
sketch := NewSketch(&g)
|
|
|
|
fieldColor := colorCycle.Next()
|
|
fmt.Printf("field color = %v\n", fieldColor)
|
|
|
|
sketch.AddColorLayer("background-magenta", rl.Magenta)
|
|
sketch.AddColorLayer("background-black", rl.Black)
|
|
//sketch.AddLayer("field", &FieldLayer{field: field, loColor: rl.NewColor(0, 0, 0, 0), hiColor: fieldColor, dirty: true})
|
|
actorColor := colorCycle.Next()
|
|
|
|
fmt.Printf("actor color = %v\n", actorColor)
|
|
|
|
hsv := rl.ColorToHSV(actorColor)
|
|
hsv.Z *= 0.7
|
|
actorColor = rl.ColorFromHSV(hsv.X, hsv.Y, hsv.Z)
|
|
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)
|
|
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")
|
|
// sketch.AddLayer("aurora", aurora)
|
|
// cave := NewImageLayer("/home/d/Dropbox/photos/Events/2025/ Chelsea and James visit Lindell/Photo Nov 29 2025, 5 26 40 PM (29).jpg")
|
|
// sketch.AddLayer("cave", cave)
|
|
|
|
ports := MakePorts()
|
|
ports["sierpinskiArrowAngle"] =
|
|
Sine{
|
|
Amp: 5,
|
|
Freq: 0.1,
|
|
Bias: 60,
|
|
}
|
|
|
|
ports["sierpinskiArrowDepth"] =
|
|
Const{
|
|
V: 6,
|
|
}
|
|
|
|
ports["sierpinskiArrowLength"] =
|
|
Const{
|
|
V: 8000,
|
|
}
|
|
|
|
for !rl.WindowShouldClose() {
|
|
|
|
// begin drawing
|
|
t := time.Since(t0).Seconds()
|
|
|
|
// set up RenderCtx
|
|
env := &Env {
|
|
Graphics: g,
|
|
Time: t,
|
|
Ports: ports.Eval(t),
|
|
}
|
|
|
|
sketch.Update(env)
|
|
|
|
/**
|
|
* MAIN DRAWING
|
|
*/
|
|
rl.BeginDrawing()
|
|
rl.ClearBackground(rl.GetColor(uint(gui.GetStyle(gui.DEFAULT, gui.BACKGROUND_COLOR))))
|
|
|
|
sketch.Draw(env)
|
|
|
|
gui.SetStyle(gui.DEFAULT, gui.BACKGROUND_COLOR, 0x181818FF)
|
|
gui.SetStyle(gui.DEFAULT, gui.BASE_COLOR_NORMAL, 0x2A2A2AFF)
|
|
gui.SetStyle(gui.DEFAULT, gui.BASE_COLOR_FOCUSED, 0x3A3A3AFF)
|
|
gui.SetStyle(gui.DEFAULT, gui.BASE_COLOR_PRESSED, 0x4A4A4AFF)
|
|
gui.SetStyle(gui.DEFAULT, gui.TEXT_COLOR_NORMAL, 0xE0E0E0FF)
|
|
gui.SetStyle(gui.DEFAULT, gui.TEXT_COLOR_FOCUSED, 0xFFFFFFFF)
|
|
gui.SetStyle(gui.DEFAULT, gui.BORDER_COLOR_NORMAL, 0x404040FF)
|
|
|
|
y := float32(10)
|
|
|
|
minX := float32(60)
|
|
maxX := float32(g.Layout.Controls.X + g.Layout.Controls.Width - 20)
|
|
sliderWidth := maxX - minX - 20
|
|
controlRowHeight := 20
|
|
for _, layerTools := range sketch.layerToolsOrdered {
|
|
|
|
config := layerTools.config
|
|
|
|
//layerTools.texture.Texture
|
|
|
|
gui.Label(rl.Rectangle{X: minX, Y: y, Width: 120, Height: 24}, layerTools.name)
|
|
|
|
y += float32(controlRowHeight + 10)
|
|
|
|
config.visible = gui.Toggle(rl.Rectangle{X: minX, Y: y, Width: 16, Height: 16}, "A", config.visible)
|
|
config.a = uint8(gui.Slider(rl.Rectangle{X: minX + 20, Y: y, Width: sliderWidth, Height: 16}, "", "", float32(config.a), 0, 255))
|
|
|
|
y += float32(controlRowHeight)
|
|
|
|
config.rVisible = gui.Toggle(rl.Rectangle{X: minX, Y: y, Width: 16, Height: 16}, "R", config.rVisible)
|
|
config.r = uint8(gui.Slider(rl.Rectangle{X: minX + 20, Y: y, Width: sliderWidth, Height: 16}, "", "", float32(config.r), 0, 255))
|
|
|
|
y += float32(controlRowHeight)
|
|
|
|
config.gVisible = gui.Toggle(rl.Rectangle{X: minX, Y: y, Width: 16, Height: 16}, "G", config.gVisible)
|
|
config.g = uint8(gui.Slider(rl.Rectangle{X: minX + 20, Y: y, Width: sliderWidth, Height: 16}, "", "", float32(config.g), 0, 255))
|
|
|
|
y += float32(controlRowHeight)
|
|
|
|
config.bVisible = gui.Toggle(rl.Rectangle{X: minX, Y: y, Width: 16, Height: 16}, "B", config.bVisible)
|
|
config.b = uint8(gui.Slider(rl.Rectangle{X: minX + 20, Y: y, Width: sliderWidth, Height: 16}, "", "", float32(config.b), 0, 255))
|
|
|
|
/*
|
|
// don't do anything with saturation / k values yet
|
|
y += float32(controlRowHeight)
|
|
config.desaturate = !gui.Toggle(rl.Rectangle{X: minX, Y: y, Width: 16, Height: 16}, "S", !config.desaturate)
|
|
config.saturation = gui.Slider(rl.Rectangle{X: minX + 20, Y: y, Width: sliderWidth, Height: 16}, "", "", config.saturation, 0, 100)
|
|
y += float32(controlRowHeight)
|
|
gui.Label(rl.Rectangle{X: minX, Y: y, Width: 16, Height: 16}, "K")
|
|
config.kValue = gui.Slider(rl.Rectangle{X: minX + 20, Y: y, Width: sliderWidth, Height: 16}, "", "", config.kValue, 0, 2)
|
|
*/
|
|
|
|
y += float32(controlRowHeight + 10)
|
|
}
|
|
|
|
rl.EndDrawing()
|
|
|
|
if rl.IsKeyDown(rl.KeySpace) {
|
|
capture := sketch.Capture()
|
|
if _, err := storage.Save(capture); err != nil {
|
|
log.Printf("Error saving snapshot: %v\n", err)
|
|
}
|
|
}
|
|
|
|
for ch := rl.GetCharPressed(); ch != 0; ch = rl.GetCharPressed() {
|
|
c := rune(ch)
|
|
if c == 'c' {
|
|
sketch.ResetCamera()
|
|
} else if c >= '1' && c <= '9' {
|
|
zoom := 1 << int(ch-'0')
|
|
sketch.cam.Zoom = float32(zoom)
|
|
}
|
|
}
|
|
|
|
//rl.EndMode2D()
|
|
|
|
// HUD
|
|
}
|
|
|
|
rl.CloseWindow()
|
|
}
|