automated snapshot
This commit is contained in:
62
main.go
62
main.go
@@ -15,10 +15,17 @@ import (
|
||||
const (
|
||||
targetWidth = 800
|
||||
targetHeight = 600
|
||||
sourceScale = 1
|
||||
sourceScale = 10
|
||||
snapshotsDir = "snapshots"
|
||||
)
|
||||
|
||||
type TextureCam struct {
|
||||
SourceWidth int
|
||||
SourceHeight int
|
||||
LookAt rl.Vector2
|
||||
Zoom float32
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
sourceWidth := sourceScale * targetWidth
|
||||
@@ -32,7 +39,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
rl.SetConfigFlags(rl.FlagWindowHighdpi & rl.FlagMsaa4xHint)
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(targetWidth, targetHeight, "sumi sierpinski arrow")
|
||||
|
||||
log.Printf("screen=%dx%d render=%dx%d",
|
||||
@@ -42,11 +49,11 @@ func main() {
|
||||
|
||||
// point at source center
|
||||
// put source center at center of screen
|
||||
var camera = rl.Camera2D {
|
||||
Target: rl.Vector2{X: float32(targetWidth) / 2, Y: float32(targetHeight) / 2},
|
||||
Offset: rl.Vector2{},
|
||||
Zoom: 1.0,
|
||||
Rotation: 0,
|
||||
var camera = TextureCam {
|
||||
LookAt: rl.Vector2 { X: float32(sourceWidth) / 2.0, Y: float32(sourceHeight) / 2.0 },
|
||||
Zoom: 1.0,
|
||||
SourceWidth: sourceWidth,
|
||||
SourceHeight: sourceHeight,
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -85,7 +92,6 @@ func main() {
|
||||
}
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
updateCamera(&camera)
|
||||
|
||||
// begin drawing
|
||||
t := time.Since(t0).Seconds()
|
||||
@@ -98,9 +104,11 @@ func main() {
|
||||
SourceHeight: int32(sourceHeight),
|
||||
Time: t,
|
||||
Ports: ports.Eval(t),
|
||||
Cam: camera,
|
||||
Cam: &camera,
|
||||
}
|
||||
|
||||
sketch.Update(renderCtx)
|
||||
|
||||
/**
|
||||
MAIN DRAWING
|
||||
**/
|
||||
@@ -131,6 +139,7 @@ type FieldSketch struct {
|
||||
Field Field
|
||||
}
|
||||
|
||||
/*
|
||||
func (s *FieldSketch) Draw(ctx *RenderCtx) {
|
||||
fmt.Printf("drawing field")
|
||||
for x := range ctx.TargetWidth {
|
||||
@@ -143,6 +152,7 @@ func (s *FieldSketch) Draw(ctx *RenderCtx) {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
type ContourLayer struct {
|
||||
field Field
|
||||
@@ -196,40 +206,6 @@ func RandRadialVec(rng *rand.Rand, minRadius float32, maxRadius float32, loAngle
|
||||
return rl.Vector2{X: float32(r * math.Cos(rad)), Y: float32(r * math.Sin(rad))}
|
||||
}
|
||||
|
||||
func updateCamera(camera *rl.Camera2D) {
|
||||
// Get the world point that is under the mouse
|
||||
mouseVec2 := rl.GetMousePosition()
|
||||
|
||||
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
||||
// get mouse delta from last frame
|
||||
delta := rl.GetMouseDelta()
|
||||
// compute the amount to move scaled by the camera zoom
|
||||
delta = rl.Vector2Scale(delta, -1.0/camera.Zoom)
|
||||
delta.Y = -delta.Y
|
||||
camera.Target = rl.Vector2Add(camera.Target, delta)
|
||||
}
|
||||
// Zoom based on mouse wheel
|
||||
wheel := rl.GetMouseWheelMove()
|
||||
if wheel != 0 {
|
||||
mouseWorldPos := rl.GetScreenToWorld2D(mouseVec2, *camera)
|
||||
|
||||
// Set the offset to where the mouse is
|
||||
camera.Offset = mouseVec2
|
||||
|
||||
// Set the target to match, so that the camera maps the world space point
|
||||
// under the cursor to the screen space point under the cursor at any zoom
|
||||
camera.Target = mouseWorldPos
|
||||
|
||||
// Zoom increment
|
||||
const zoomIncrement float32 = 0.125
|
||||
|
||||
camera.Zoom += (wheel * zoomIncrement)
|
||||
if camera.Zoom < zoomIncrement {
|
||||
camera.Zoom = zoomIncrement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Worm struct {
|
||||
position rl.Vector2
|
||||
angles []float32
|
||||
|
||||
Reference in New Issue
Block a user