automated snapshot
This commit is contained in:
89
main.go
89
main.go
@@ -20,15 +20,15 @@ const (
|
||||
)
|
||||
|
||||
type TextureCam struct {
|
||||
SourceWidth int
|
||||
SourceWidth int
|
||||
SourceHeight int
|
||||
LookAt rl.Vector2
|
||||
Zoom float32
|
||||
LookAt rl.Vector2
|
||||
Zoom float32
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
sourceWidth := sourceScale * targetWidth
|
||||
sourceWidth := sourceScale * targetWidth
|
||||
sourceHeight := sourceScale * targetHeight
|
||||
|
||||
os.MkdirAll(snapshotsDir, 0755)
|
||||
@@ -44,10 +44,10 @@ func main() {
|
||||
|
||||
// point at source center
|
||||
// put source center at center of screen
|
||||
var camera = TextureCam {
|
||||
LookAt: rl.Vector2 { X: float32(sourceWidth) / 2.0, Y: float32(sourceHeight) / 2.0 },
|
||||
Zoom: 1.0,
|
||||
SourceWidth: sourceWidth,
|
||||
var camera = TextureCam{
|
||||
LookAt: rl.Vector2{X: float32(sourceWidth) / 2.0, Y: float32(sourceHeight) / 2.0},
|
||||
Zoom: 1.0,
|
||||
SourceWidth: sourceWidth,
|
||||
SourceHeight: sourceHeight,
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ func main() {
|
||||
t0 := time.Now()
|
||||
|
||||
/*
|
||||
*/
|
||||
*/
|
||||
|
||||
imageField := NewImageField("/home/d/Dropbox/art/passage/data/david.png")
|
||||
|
||||
field :=
|
||||
TranslateField{
|
||||
x: -float32(sourceWidth/2.0),
|
||||
y: -float32(sourceHeight/2.0),
|
||||
field: &ScaleField {
|
||||
scale: 5.0,
|
||||
field: &imageField,
|
||||
},
|
||||
}
|
||||
x: -float32(sourceWidth / 2.0),
|
||||
y: -float32(sourceHeight / 2.0),
|
||||
field: &ScaleField{
|
||||
scale: 5.0,
|
||||
field: &imageField,
|
||||
},
|
||||
}
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
|
||||
contourLayer := NewContourLayer(rng, &field, sourceWidth, sourceHeight)
|
||||
@@ -75,11 +75,11 @@ func main() {
|
||||
sketch := NewSketch()
|
||||
//sketch.CreateLayer("testPattern", &TestPattern{}, int32(sourceWidth), int32(sourceHeight))
|
||||
//sketch.CreateLayer("actors", &contourLayer, int32(sourceWidth), int32(sourceHeight))
|
||||
sketch.CreateLayer("field", &FieldLayer { field: &field, dirty: true }, int32(sourceWidth), int32(sourceHeight))
|
||||
sketch.CreateLayer("field", &FieldLayer{field: &field, dirty: true}, int32(sourceWidth), int32(sourceHeight))
|
||||
sketch.CreateLayer("contours", &contourLayer, int32(sourceWidth), int32(sourceHeight))
|
||||
|
||||
ports := MakePorts()
|
||||
ports["sierpinskiArrowAngle"] = Sine {
|
||||
ports["sierpinskiArrowAngle"] = Sine{
|
||||
Amp: 120,
|
||||
Bias: 100,
|
||||
Freq: 0.1,
|
||||
@@ -110,7 +110,7 @@ func main() {
|
||||
rl.ClearBackground(rl.Blank)
|
||||
|
||||
sketch.Draw(renderCtx)
|
||||
|
||||
|
||||
if rl.IsKeyDown(rl.KeySpace) {
|
||||
if _, err := storage.Save(); err != nil {
|
||||
log.Printf("Error saving snapshot: %v\n", err)
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
if c == 'c' {
|
||||
resetCamera(&camera)
|
||||
} else if c >= '1' && c <= '9' {
|
||||
zoom := 1 << int(ch - '0')
|
||||
zoom := 1 << int(ch-'0')
|
||||
camera.Zoom = float32(zoom)
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func main() {
|
||||
}
|
||||
|
||||
func resetCamera(cam *TextureCam) {
|
||||
cam.LookAt = rl.Vector2 { X: float32(cam.SourceWidth) / 2.0, Y: float32(cam.SourceHeight) / 2.0 }
|
||||
cam.LookAt = rl.Vector2{X: float32(cam.SourceWidth) / 2.0, Y: float32(cam.SourceHeight) / 2.0}
|
||||
cam.Zoom = 1.0
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ type FieldLayer struct {
|
||||
}
|
||||
|
||||
func (s *FieldLayer) Update(ctx *RenderCtx) {
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
func (s *FieldLayer) Draw(ctx *RenderCtx) {
|
||||
@@ -169,32 +169,47 @@ func (s *FieldLayer) IsDirty() bool {
|
||||
}
|
||||
|
||||
type ContourLayer struct {
|
||||
field Field
|
||||
actors []*Actor
|
||||
field Field
|
||||
actors []*Actor
|
||||
rng *rand.Rand
|
||||
sourceWidth int
|
||||
sourceHeight int
|
||||
}
|
||||
|
||||
func NewContourLayer(rng *rand.Rand, field Field, sourceWidth int, sourceHeight int) ContourLayer {
|
||||
|
||||
actors := make([]*Actor, 20000)
|
||||
for i := range len(actors) {
|
||||
x := rng.Int() % sourceWidth
|
||||
y := rng.Int() % sourceHeight
|
||||
actors[i] =
|
||||
&Actor{
|
||||
position: rl.Vector2 { X: float32(x), Y: float32(y) },
|
||||
field: field,
|
||||
actors := make([]*Actor, 0)
|
||||
|
||||
layer := ContourLayer {
|
||||
rng: rng,
|
||||
field: field,
|
||||
actors: actors,
|
||||
sourceWidth: sourceWidth,
|
||||
sourceHeight: sourceHeight,
|
||||
}
|
||||
|
||||
layer.AddActors(1)
|
||||
|
||||
return layer
|
||||
}
|
||||
|
||||
func (s *ContourLayer) AddActors(n int) {
|
||||
for range n {
|
||||
x := s.rng.Int() % s.sourceWidth
|
||||
y := s.rng.Int() % s.sourceHeight
|
||||
newActor :=
|
||||
&Actor {
|
||||
position: rl.Vector2{X: float32(x), Y: float32(y)},
|
||||
field: s.field,
|
||||
stepSize: 1,
|
||||
color: rl.NewColor(11, 35, 176, 100),
|
||||
}
|
||||
}
|
||||
|
||||
return ContourLayer{
|
||||
actors: actors,
|
||||
s.actors = append(s.actors, newActor)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Update(ctx *RenderCtx) {
|
||||
;
|
||||
s.AddActors(100) // parameterize
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Draw(ctx *RenderCtx) {
|
||||
|
||||
Reference in New Issue
Block a user