automated snapshot
This commit is contained in:
63
main.go
63
main.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -38,6 +39,8 @@ func main() {
|
|||||||
|
|
||||||
os.MkdirAll(snapshotsDir, 0755)
|
os.MkdirAll(snapshotsDir, 0755)
|
||||||
|
|
||||||
|
rng := rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||||
|
|
||||||
storage, err := NewStorage(snapshotsDir)
|
storage, err := NewStorage(snapshotsDir)
|
||||||
@@ -58,25 +61,26 @@ func main() {
|
|||||||
w := rl.GetRenderWidth()
|
w := rl.GetRenderWidth()
|
||||||
h := rl.GetRenderHeight()
|
h := rl.GetRenderHeight()
|
||||||
|
|
||||||
angles := make([]float32, 2000)
|
sketches := make([]Sketch, 1000)
|
||||||
noise := opensimplex.NewNormalized(0)
|
for i := range 1000 {
|
||||||
r := 2.0
|
angles := make([]float32, 100)
|
||||||
dtheta := 360.0/float64(len(angles))
|
noise := opensimplex.NewNormalized(int64(i))
|
||||||
for i := range len(angles) {
|
r := 1.0
|
||||||
rad := float64(i) * dtheta * math.Pi / 180.0
|
dtheta := 360.0/float64(len(angles))
|
||||||
x := r * math.Cos(rad)
|
for i := range len(angles) {
|
||||||
y := r * math.Sin(rad)
|
rad := float64(i) * dtheta * math.Pi / 180.0
|
||||||
angles[i] = float32(noise.Eval2(x, y) * 360.0)
|
x := r * math.Cos(rad)
|
||||||
}
|
y := r * math.Sin(rad)
|
||||||
|
angles[i] = float32(noise.Eval2(x, y) * 360.0)
|
||||||
sketches := []Sketch{
|
}
|
||||||
&Worm{
|
sketches[i] =
|
||||||
position: rl.Vector2 { X: 50, Y: 50 },
|
&Worm{
|
||||||
angles: angles,
|
position: RandRadialVec(rng, 0, 100, -180, 180),
|
||||||
angleIndex: 0,
|
angles: angles,
|
||||||
stepSize: 1,
|
angleIndex: 0,
|
||||||
renderPct: 0.1,
|
stepSize: 1,
|
||||||
},
|
renderPct: 0.80,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var camera = rl.Camera2D{
|
var camera = rl.Camera2D{
|
||||||
@@ -110,7 +114,7 @@ func main() {
|
|||||||
|
|
||||||
// begin drawing
|
// begin drawing
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.Black)
|
||||||
rl.BeginMode2D(camera)
|
rl.BeginMode2D(camera)
|
||||||
|
|
||||||
t := time.Since(t0).Seconds()
|
t := time.Since(t0).Seconds()
|
||||||
@@ -149,6 +153,13 @@ func main() {
|
|||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
rad := rl.Deg2rad * deg
|
||||||
|
return rl.Vector2 { X: float32(r * math.Cos(rad)), Y: float32(r * math.Sin(rad)) }
|
||||||
|
}
|
||||||
|
|
||||||
func updateCamera(camera *rl.Camera2D) {
|
func updateCamera(camera *rl.Camera2D) {
|
||||||
// Get the world point that is under the mouse
|
// Get the world point that is under the mouse
|
||||||
mouseVec2 := rl.GetMousePosition()
|
mouseVec2 := rl.GetMousePosition()
|
||||||
@@ -195,11 +206,19 @@ func (w *Worm) Draw(ctx *RenderCtx) {
|
|||||||
rl.Translatef(w.position.X, w.position.Y, 0)
|
rl.Translatef(w.position.X, w.position.Y, 0)
|
||||||
lastAngle := float32(0.0)
|
lastAngle := float32(0.0)
|
||||||
stepCount := 0
|
stepCount := 0
|
||||||
|
nudged := false
|
||||||
for i := range w.angles {
|
for i := range w.angles {
|
||||||
ii := (i + w.angleIndex) % len(w.angles)
|
ii := (i + w.angleIndex) % len(w.angles)
|
||||||
angle := w.angles[ii]
|
angle := w.angles[ii]
|
||||||
rl.Rotatef(angle - lastAngle, 0, 0, 1)
|
deltaAngle := angle - lastAngle
|
||||||
rl.DrawLine(0, 0, int32(w.stepSize), 0, rl.Black)
|
if !nudged {
|
||||||
|
rad := float64(deltaAngle * math.Pi / 180.0)
|
||||||
|
nudge := rl.Vector2 { X: float32(w.stepSize) * float32(math.Cos(rad)), Y: float32(w.stepSize) * float32(math.Sin(rad)) }
|
||||||
|
w.position = rl.Vector2Add(w.position, nudge)
|
||||||
|
nudged = true
|
||||||
|
}
|
||||||
|
rl.Rotatef(deltaAngle, 0, 0, 1)
|
||||||
|
rl.DrawLine(0, 0, int32(w.stepSize), 0, rl.NewColor(184, 187, 38, 50))
|
||||||
rl.Translatef(float32(w.stepSize), 0, 0)
|
rl.Translatef(float32(w.stepSize), 0, 0)
|
||||||
lastAngle = angle
|
lastAngle = angle
|
||||||
stepCount++
|
stepCount++
|
||||||
|
|||||||
Reference in New Issue
Block a user