automated snapshot
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
@@ -8,21 +9,27 @@ import (
|
||||
|
||||
type ContourLayer struct {
|
||||
field Field
|
||||
maxActors uint32
|
||||
actors []*Actor
|
||||
actorIndex uint32
|
||||
rng *rand.Rand
|
||||
}
|
||||
|
||||
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field) *ContourLayer {
|
||||
|
||||
actors := make([]*Actor, 0)
|
||||
maxActors := 200000
|
||||
|
||||
actors := make([]*Actor, maxActors)
|
||||
|
||||
layer := ContourLayer {
|
||||
rng: rng,
|
||||
field: field,
|
||||
actors: actors,
|
||||
maxActors: uint32(maxActors),
|
||||
actorIndex: 0,
|
||||
}
|
||||
|
||||
layer.AddActors(1, sketch.sourceWidth, sketch.sourceHeight)
|
||||
//layer.AddActors(1, sketch.sourceWidth, sketch.sourceHeight)
|
||||
|
||||
return &layer
|
||||
}
|
||||
@@ -38,19 +45,23 @@ func (s *ContourLayer) AddActors(n, sourceWidth, sourceHeight int32) {
|
||||
stepSize: 1,
|
||||
color: rl.NewColor(11, 35, 176, 50),
|
||||
}
|
||||
s.actors = append(s.actors, newActor)
|
||||
s.actors[s.actorIndex] = newActor
|
||||
s.actorIndex = (s.actorIndex + 1) % s.maxActors
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Update(ctx *RenderCtx) {
|
||||
s.AddActors(100, ctx.SourceWidth, ctx.SourceHeight)
|
||||
fmt.Printf("num actors = %d\n", len(s.actors))
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Draw(ctx *RenderCtx) {
|
||||
rl.BeginBlendMode(rl.BlendAdditive)
|
||||
for _, actor := range s.actors {
|
||||
if actor != nil {
|
||||
actor.Draw()
|
||||
}
|
||||
}
|
||||
rl.EndBlendMode()
|
||||
}
|
||||
|
||||
|
||||
11
sketch.go
11
sketch.go
@@ -90,11 +90,14 @@ func (s *Sketch) AddColorLayer(name string, c rl.Color) {
|
||||
s.AddLayer(name, colorLayer)
|
||||
}
|
||||
|
||||
func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
func (s *Sketch) Redraw(ctx *RenderCtx) {
|
||||
// render onto all layer textures
|
||||
for _, instance := range s.layerToolsOrdered {
|
||||
layer := instance.layer
|
||||
// ignore this layer entirely unless it's visible
|
||||
if instance.config.visible {
|
||||
layer.Update(ctx)
|
||||
// re-render to texture if dirty
|
||||
if instance.layer.IsDirty() {
|
||||
rl.BeginTextureMode(instance.texture)
|
||||
rl.PushMatrix()
|
||||
@@ -103,9 +106,12 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// composite all layers to screen
|
||||
func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
|
||||
s.Redraw(ctx)
|
||||
|
||||
// copy from full texture for compositing, with vertical flipping
|
||||
src := rl.Rectangle {
|
||||
@@ -122,7 +128,6 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
viewport := s.CalcViewport(ctx)
|
||||
|
||||
rl.BeginTextureMode(s.composite)
|
||||
//rl.ClearBackground(rl.Black)
|
||||
for _, instance := range s.layerToolsOrdered {
|
||||
config := instance.config
|
||||
if config.visible {
|
||||
|
||||
Reference in New Issue
Block a user