automated snapshot
This commit is contained in:
87
main.go
87
main.go
@@ -13,12 +13,48 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
screenWidth = 3000
|
||||
screenHeight = 2000
|
||||
screenWidth = 800
|
||||
screenHeight = 600
|
||||
sourceWidth = 10000
|
||||
sourceHeight = 10000
|
||||
displayScale = 2
|
||||
snapshotsDir = "snapshots"
|
||||
)
|
||||
|
||||
func main3() {
|
||||
rl.InitWindow(800, 600, "rt test")
|
||||
defer rl.CloseWindow()
|
||||
|
||||
rt := rl.LoadRenderTexture(512, 512)
|
||||
defer rl.UnloadRenderTexture(rt)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
// draw into offscreen buffer
|
||||
rl.BeginTextureMode(rt)
|
||||
rl.ClearBackground(rl.Blank)
|
||||
rl.DrawCircle(256, 256, 100, rl.Red)
|
||||
rl.EndTextureMode()
|
||||
|
||||
// draw to screen
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
src := rl.Rectangle{
|
||||
X: 0, Y: 0,
|
||||
Width: float32(rt.Texture.Width),
|
||||
Height: -float32(rt.Texture.Height),
|
||||
}
|
||||
dst := rl.Rectangle{
|
||||
X: 0, Y: 0,
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
}
|
||||
|
||||
rl.DrawTexturePro(rt.Texture, src, dst, rl.Vector2{}, 0, rl.White)
|
||||
rl.EndDrawing()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
os.MkdirAll(snapshotsDir, 0755)
|
||||
@@ -54,25 +90,22 @@ func main() {
|
||||
Noise: opensimplex.NewNormalized32(0),
|
||||
},
|
||||
}
|
||||
*/
|
||||
|
||||
imgf := NewImageField("/home/d/Dropbox/art/passage/data/david.png")
|
||||
|
||||
imageField :=
|
||||
ScaleField{
|
||||
field: &imgf,
|
||||
scale: 0.5,
|
||||
}
|
||||
*/
|
||||
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
//rng := rand.New(rand.NewSource(0))
|
||||
|
||||
contourSketch := NewContourLayer(rng, &imageField)
|
||||
//contourSketch := NewContourLayer(rng, &imageField)
|
||||
|
||||
sketch := Sketch {
|
||||
layers: []Layer {
|
||||
&contourSketch,
|
||||
//&FieldSketch { Field: &imageField },
|
||||
},
|
||||
}
|
||||
sketch := NewSketch()
|
||||
sketch.CreateLayer("testPattern", &TestPattern{}, sourceWidth, sourceHeight)
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
@@ -90,16 +123,14 @@ func main() {
|
||||
updateCamera(&camera)
|
||||
|
||||
// begin drawing
|
||||
rl.BeginDrawing()
|
||||
//rl.ClearBackground(rl.Black)
|
||||
rl.BeginMode2D(camera)
|
||||
rl.BeginBlendMode(rl.BlendAdditive)
|
||||
t := time.Since(t0).Seconds()
|
||||
|
||||
// set up RenderCtx
|
||||
renderCtx := &RenderCtx{
|
||||
Width: int32(w),
|
||||
Height: int32(h),
|
||||
TargetWidth: int32(w),
|
||||
TargetHeight: int32(h),
|
||||
SourceWidth: int32(sourceWidth),
|
||||
SourceHeight: int32(sourceHeight),
|
||||
Time: t,
|
||||
Ports: ports.Eval(t),
|
||||
Cam: camera,
|
||||
@@ -108,12 +139,17 @@ func main() {
|
||||
/**
|
||||
MAIN DRAWING
|
||||
**/
|
||||
rl.BeginDrawing()
|
||||
rl.ClearBackground(rl.Blank)
|
||||
|
||||
rl.PushMatrix()
|
||||
//rl.PushMatrix()
|
||||
sketch.Draw(renderCtx)
|
||||
rl.PopMatrix()
|
||||
|
||||
rl.DrawCircle(0, 0, 10, rl.Green)
|
||||
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
|
||||
//rl.PopMatrix()
|
||||
|
||||
rl.EndDrawing()
|
||||
//rl.DrawCircle(0, 0, 10, rl.Green)
|
||||
|
||||
if rl.IsKeyDown(rl.KeySpace) {
|
||||
if _, err := storage.Save(); err != nil {
|
||||
@@ -121,12 +157,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
rl.EndBlendMode()
|
||||
rl.EndMode2D()
|
||||
//rl.EndMode2D()
|
||||
|
||||
// HUD
|
||||
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.Black)
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.CloseWindow()
|
||||
@@ -138,8 +171,8 @@ type FieldSketch struct {
|
||||
|
||||
func (s *FieldSketch) Draw(ctx *RenderCtx) {
|
||||
fmt.Printf("drawing field")
|
||||
for x := range ctx.Width {
|
||||
for y := range ctx.Height {
|
||||
for x := range ctx.TargetWidth {
|
||||
for y := range ctx.TargetHeight {
|
||||
screen := rl.Vector2{X: float32(x), Y: float32(y)}
|
||||
world := rl.GetScreenToWorld2D(screen, ctx.Cam)
|
||||
v := s.Field.Get(world.X, world.Y)
|
||||
@@ -178,7 +211,6 @@ func (s *ContourLayer) Draw(ctx *RenderCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type Actor struct {
|
||||
position rl.Vector2
|
||||
field Field
|
||||
@@ -195,7 +227,6 @@ func (a *Actor) Draw() {
|
||||
a.position = nextPosition
|
||||
}
|
||||
|
||||
|
||||
func RandRadialVec(rng *rand.Rand, minRadius float32, maxRadius float32, loAngle float32, hiAngle float32) rl.Vector2 {
|
||||
r := float64(rl.Remap(rng.Float32(), 0, 1, minRadius, maxRadius))
|
||||
deg := float64(rl.Remap(rng.Float32(), 0, 1, loAngle, hiAngle))
|
||||
|
||||
64
sketch.go
64
sketch.go
@@ -5,21 +5,75 @@ import (
|
||||
)
|
||||
|
||||
type Sketch struct {
|
||||
layers []Layer
|
||||
layerTools map[string]LayerTools
|
||||
}
|
||||
|
||||
func NewSketch() Sketch {
|
||||
return Sketch {
|
||||
layerTools: make(map[string]LayerTools),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sketch) CreateLayer(name string, layer Layer, sourceWidth int32, sourceHeight int32) {
|
||||
texture := rl.LoadRenderTexture(sourceWidth, sourceHeight)
|
||||
s.layerTools[name] = LayerTools {
|
||||
name: name,
|
||||
texture: &texture,
|
||||
layer: layer,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
for _, layer := range s.layers {
|
||||
// render onto all layer textures
|
||||
for _, instance := range s.layerTools {
|
||||
layer := instance.layer
|
||||
rl.BeginTextureMode(*instance.texture)
|
||||
layer.Draw(ctx)
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
// composite all layers to screen
|
||||
|
||||
src := rl.Rectangle {
|
||||
X: 0, Y: 0,
|
||||
Width: float32(ctx.SourceWidth),
|
||||
Height: -float32(ctx.SourceHeight),
|
||||
}
|
||||
dst := rl.Rectangle {
|
||||
X: 0, Y: 0,
|
||||
Width: float32(ctx.TargetWidth),
|
||||
Height: float32(ctx.TargetHeight),
|
||||
}
|
||||
|
||||
for _, instance := range s.layerTools {
|
||||
rl.DrawTexturePro(instance.texture.Texture, src, dst, rl.Vector2{}, 0, rl.White)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type LayerTools struct {
|
||||
name string
|
||||
layer Layer
|
||||
texture *rl.RenderTexture2D
|
||||
}
|
||||
|
||||
|
||||
/** Layer **/
|
||||
|
||||
type Layer interface {
|
||||
Draw(ctx *RenderCtx)
|
||||
}
|
||||
|
||||
type TestPattern struct { }
|
||||
|
||||
func (tp *TestPattern) Draw(ctx *RenderCtx) {
|
||||
rl.DrawRectangle(0, 0, int32(ctx.SourceWidth), int32(ctx.SourceHeight), rl.Magenta)
|
||||
rl.PushMatrix()
|
||||
rl.Translatef(float32(ctx.SourceWidth)/2.0, float32(ctx.SourceHeight)/2.0, 0.0)
|
||||
rl.DrawRectangle(-100, -100, 200, 200, rl.Green)
|
||||
rl.PopMatrix()
|
||||
}
|
||||
|
||||
|
||||
/** Ports **/
|
||||
|
||||
type Ports map[string]Signal
|
||||
@@ -42,8 +96,10 @@ func (p Ports) Eval(t float64) map[string]float64 {
|
||||
/** RenderCtx **/
|
||||
|
||||
type RenderCtx struct {
|
||||
Width int32
|
||||
Height int32
|
||||
TargetWidth int32
|
||||
TargetHeight int32
|
||||
SourceWidth int32
|
||||
SourceHeight int32
|
||||
Time float64
|
||||
Ports map[string]float64
|
||||
Cam rl.Camera2D
|
||||
|
||||
Reference in New Issue
Block a user