automated snapshot
This commit is contained in:
@@ -36,7 +36,7 @@ func (s *ContourLayer) AddActors(n, sourceWidth, sourceHeight int32) {
|
|||||||
position: rl.Vector2{X: float32(x), Y: float32(y)},
|
position: rl.Vector2{X: float32(x), Y: float32(y)},
|
||||||
field: s.field,
|
field: s.field,
|
||||||
stepSize: 1,
|
stepSize: 1,
|
||||||
color: rl.NewColor(11, 35, 176, 20),
|
color: rl.NewColor(11, 35, 176, 50),
|
||||||
}
|
}
|
||||||
s.actors = append(s.actors, newActor)
|
s.actors = append(s.actors, newActor)
|
||||||
}
|
}
|
||||||
|
|||||||
26
main.go
26
main.go
@@ -12,16 +12,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
targetWidth = 1000
|
|
||||||
targetHeight = 1000
|
|
||||||
sourceScale = 2
|
|
||||||
snapshotsDir = "snapshots"
|
snapshotsDir = "snapshots"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
sourceWidth := int32(sourceScale * targetWidth)
|
var sourceWidth int32 = 8000
|
||||||
sourceHeight := int32(sourceScale * targetHeight)
|
var sourceHeight int32 = 6400
|
||||||
|
|
||||||
|
var targetWidth int32 = int32(2000)
|
||||||
|
var targetHeight int32 = int32(1200)
|
||||||
|
|
||||||
os.MkdirAll(snapshotsDir, 0755)
|
os.MkdirAll(snapshotsDir, 0755)
|
||||||
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||||
@@ -47,7 +47,7 @@ func main() {
|
|||||||
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: 1.0,
|
scale: 4.0,
|
||||||
field: &imageField,
|
field: &imageField,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -74,10 +74,16 @@ func main() {
|
|||||||
// begin drawing
|
// begin drawing
|
||||||
t := time.Since(t0).Seconds()
|
t := time.Since(t0).Seconds()
|
||||||
|
|
||||||
|
targetBounds := rl.Rectangle {
|
||||||
|
X: float32(targetWidth) / 4.0,
|
||||||
|
Y: 0,
|
||||||
|
Width: float32(targetWidth) * 3.0 / 4.0,
|
||||||
|
Height: float32(targetHeight),
|
||||||
|
}
|
||||||
|
|
||||||
// set up RenderCtx
|
// set up RenderCtx
|
||||||
renderCtx := &RenderCtx{
|
renderCtx := &RenderCtx{
|
||||||
TargetWidth: int32(targetWidth),
|
TargetBounds: targetBounds,
|
||||||
TargetHeight: int32(targetHeight),
|
|
||||||
SourceWidth: int32(sourceWidth),
|
SourceWidth: int32(sourceWidth),
|
||||||
SourceHeight: int32(sourceHeight),
|
SourceHeight: int32(sourceHeight),
|
||||||
Time: t,
|
Time: t,
|
||||||
@@ -91,11 +97,7 @@ func main() {
|
|||||||
*/
|
*/
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.Blank)
|
rl.ClearBackground(rl.Blank)
|
||||||
|
|
||||||
sketch.Draw(renderCtx)
|
sketch.Draw(renderCtx)
|
||||||
|
|
||||||
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeySpace) {
|
if rl.IsKeyDown(rl.KeySpace) {
|
||||||
|
|||||||
48
sketch.go
48
sketch.go
@@ -54,8 +54,8 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
|
|||||||
// render onto all layer textures
|
// render onto all layer textures
|
||||||
for _, instance := range s.layerToolsOrdered {
|
for _, instance := range s.layerToolsOrdered {
|
||||||
instance.layer.Update(ctx)
|
instance.layer.Update(ctx)
|
||||||
if instance.layer.IsDirty() {
|
|
||||||
layer := instance.layer
|
layer := instance.layer
|
||||||
|
if instance.layer.IsDirty() {
|
||||||
rl.BeginTextureMode(*instance.texture)
|
rl.BeginTextureMode(*instance.texture)
|
||||||
layer.Draw(ctx)
|
layer.Draw(ctx)
|
||||||
rl.EndTextureMode()
|
rl.EndTextureMode()
|
||||||
@@ -64,12 +64,7 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
|
|||||||
|
|
||||||
// composite all layers to screen
|
// composite all layers to screen
|
||||||
|
|
||||||
screen := rl.Rectangle {
|
outputRect := s.calcOutputRectKeepingAspectRatio(ctx)
|
||||||
X: 0,
|
|
||||||
Y: 0,
|
|
||||||
Width: float32(ctx.TargetWidth),
|
|
||||||
Height: float32(ctx.TargetHeight),
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy from full texture for compositing, with vertical flipping
|
// copy from full texture for compositing, with vertical flipping
|
||||||
src := rl.Rectangle {
|
src := rl.Rectangle {
|
||||||
@@ -92,7 +87,40 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
|
|||||||
}
|
}
|
||||||
rl.EndTextureMode()
|
rl.EndTextureMode()
|
||||||
|
|
||||||
rl.DrawTexturePro(s.composite.Texture, viewport, screen, rl.Vector2{}, 0, rl.White)
|
rl.DrawTexturePro(s.composite.Texture, viewport, outputRect, rl.Vector2{}, 0, rl.White)
|
||||||
|
|
||||||
|
outlineRect := outputRect.ToInt32()
|
||||||
|
rl.DrawRectangleLines(outlineRect.X, outlineRect.Y, outlineRect.Width, outlineRect.Height, rl.Gray)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Sketch) calcOutputRectKeepingAspectRatio(ctx *RenderCtx) rl.Rectangle {
|
||||||
|
sourceAspect := float32(ctx.SourceWidth) / float32(ctx.SourceHeight)
|
||||||
|
targetAspect := ctx.TargetBounds.Width / ctx.TargetBounds.Height
|
||||||
|
|
||||||
|
outputWidth := ctx.TargetBounds.Width
|
||||||
|
outputHeight := ctx.TargetBounds.Height
|
||||||
|
|
||||||
|
if sourceAspect < targetAspect {
|
||||||
|
// source is relatively taller than the target
|
||||||
|
// so we set the output height to the target height
|
||||||
|
// and calculate the width based on source aspect and center
|
||||||
|
outputWidth = outputHeight * sourceAspect
|
||||||
|
} else {
|
||||||
|
// source is relatively wider than the target
|
||||||
|
// so we set the output width to the target width
|
||||||
|
// and calculate the height based on source aspect and center
|
||||||
|
outputHeight = outputWidth / sourceAspect
|
||||||
|
}
|
||||||
|
|
||||||
|
// output width and height are correct -- center within TargetBounds
|
||||||
|
x := ctx.TargetBounds.X + ctx.TargetBounds.Width / 2.0 - outputWidth / 2.0
|
||||||
|
y := ctx.TargetBounds.Y + ctx.TargetBounds.Height / 2.0 - outputHeight / 2.0
|
||||||
|
|
||||||
|
return rl.Rectangle {
|
||||||
|
X: x, Y: y,
|
||||||
|
Width: outputWidth,
|
||||||
|
Height: outputHeight,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) CalcViewport(ctx *RenderCtx) rl.Rectangle {
|
func (s *Sketch) CalcViewport(ctx *RenderCtx) rl.Rectangle {
|
||||||
@@ -111,6 +139,7 @@ func (s *Sketch) Update(ctx *RenderCtx) {
|
|||||||
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
||||||
// get mouse delta from last frame
|
// get mouse delta from last frame
|
||||||
delta := rl.GetMouseDelta()
|
delta := rl.GetMouseDelta()
|
||||||
|
sourceScale := float32(ctx.SourceWidth) / ctx.TargetBounds.Width
|
||||||
// compute the amount to move scaled by the camera zoom
|
// compute the amount to move scaled by the camera zoom
|
||||||
delta = rl.Vector2Scale(delta, -sourceScale/s.cam.Zoom)
|
delta = rl.Vector2Scale(delta, -sourceScale/s.cam.Zoom)
|
||||||
delta.Y = -delta.Y
|
delta.Y = -delta.Y
|
||||||
@@ -233,8 +262,7 @@ func (p Ports) Eval(t float64) map[string]float64 {
|
|||||||
/** RenderCtx **/
|
/** RenderCtx **/
|
||||||
|
|
||||||
type RenderCtx struct {
|
type RenderCtx struct {
|
||||||
TargetWidth int32
|
TargetBounds rl.Rectangle
|
||||||
TargetHeight int32
|
|
||||||
SourceWidth int32
|
SourceWidth int32
|
||||||
SourceHeight int32
|
SourceHeight int32
|
||||||
Time float64
|
Time float64
|
||||||
|
|||||||
Reference in New Issue
Block a user