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