automated snapshot
This commit is contained in:
22
field.go
22
field.go
@@ -14,21 +14,21 @@ type Field interface {
|
||||
|
||||
// TRANSFORM FIELDS
|
||||
type ScaleField struct {
|
||||
Field Field
|
||||
Scale float32
|
||||
field Field
|
||||
scale float32
|
||||
}
|
||||
|
||||
func (f *ScaleField) Get(x, y float32) float32 {
|
||||
return f.Field.Get(x / f.Scale, y / f.Scale)
|
||||
return f.field.Get(x / f.scale, y / f.scale)
|
||||
}
|
||||
|
||||
type TranslateField struct {
|
||||
Field Field
|
||||
field Field
|
||||
x, y float32
|
||||
}
|
||||
|
||||
func (f *TranslateField) Get(x, y float32) float32 {
|
||||
return f.Field.Get(x + f.x, y + f.y)
|
||||
return f.field.Get(x + f.x, y + f.y)
|
||||
}
|
||||
|
||||
// NOISE FIELDS
|
||||
@@ -46,6 +46,7 @@ func (f *SimplexNoiseField) Get(x, y float32) float32 {
|
||||
type ImageField struct {
|
||||
image *rl.Image
|
||||
pixels ImagePixels
|
||||
offsetX, offsetY float32
|
||||
}
|
||||
|
||||
type ImagePixels struct {
|
||||
@@ -71,11 +72,18 @@ func NewImageField(path string) ImageField {
|
||||
h: int(image.Height),
|
||||
colors: colors,
|
||||
}
|
||||
return ImageField { image: image, pixels: pixels }
|
||||
offsetX := float32(image.Width / 2)
|
||||
offsetY := float32(image.Height / 2)
|
||||
return ImageField {
|
||||
image: image,
|
||||
pixels: pixels,
|
||||
offsetX: offsetX,
|
||||
offsetY: offsetY,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ImageField) Get(x, y float32) float32 {
|
||||
// todo : blend colors
|
||||
c := f.pixels.Get(int(x), int(y))
|
||||
c := f.pixels.Get(int(x+f.offsetX), int(y + f.offsetY))
|
||||
return Brightness(c)
|
||||
}
|
||||
|
||||
47
main.go
47
main.go
@@ -13,8 +13,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
screenWidth = 1200
|
||||
screenHeight = 900
|
||||
screenWidth = 3000
|
||||
screenHeight = 2000
|
||||
displayScale = 2
|
||||
snapshotsDir = "snapshots"
|
||||
)
|
||||
@@ -22,15 +22,12 @@ const (
|
||||
func main() {
|
||||
|
||||
os.MkdirAll(snapshotsDir, 0755)
|
||||
|
||||
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
|
||||
storage, err := NewStorage(snapshotsDir)
|
||||
if err != nil {
|
||||
log.Printf("Error loading storage: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
rl.SetConfigFlags(rl.FlagWindowHighdpi)
|
||||
rl.InitWindow(screenWidth, screenHeight, "sumi sierpinski arrow")
|
||||
|
||||
@@ -59,25 +56,22 @@ func main() {
|
||||
}
|
||||
*/
|
||||
|
||||
imgf := NewImageField("aphrodite.jpeg")
|
||||
imgf := NewImageField("/home/d/Dropbox/art/passage/data/david.png")
|
||||
imageField :=
|
||||
TranslateField {
|
||||
x: float32(w) / 2.0,
|
||||
y: float32(h) / 2.0,
|
||||
//x: 5, y: 5,
|
||||
Field: &ScaleField {
|
||||
Scale: 4.5,
|
||||
Field: &imgf,
|
||||
},
|
||||
ScaleField {
|
||||
field: &imgf,
|
||||
scale: 0.5,
|
||||
}
|
||||
|
||||
rng := rand.New(rand.NewSource(0))
|
||||
|
||||
contourSketch := NewContourSketch(rng, &imageField)
|
||||
contourSketch := NewContourLayer(rng, &imageField)
|
||||
|
||||
sketches := []Sketch {
|
||||
//&FieldSketch { Field: &imageField },
|
||||
sketch := Sketch {
|
||||
layers: []Layer {
|
||||
&contourSketch,
|
||||
//&FieldSketch { Field: &imageField },
|
||||
},
|
||||
}
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
@@ -115,11 +109,11 @@ func main() {
|
||||
MAIN DRAWING
|
||||
**/
|
||||
|
||||
for _, s := range sketches {
|
||||
rl.PushMatrix()
|
||||
s.Draw(renderCtx)
|
||||
sketch.Draw(renderCtx)
|
||||
rl.PopMatrix()
|
||||
}
|
||||
|
||||
rl.DrawCircle(0, 0, 10, rl.Green)
|
||||
|
||||
if rl.IsKeyDown(rl.KeySpace) {
|
||||
if _, err := storage.Save(); err != nil {
|
||||
@@ -146,7 +140,6 @@ func (s *FieldSketch) Draw(ctx *RenderCtx) {
|
||||
fmt.Printf("drawing field")
|
||||
for x := range ctx.Width {
|
||||
for y := range ctx.Height {
|
||||
//screen := rl.Vector2 { X: float32(x) - float32(ctx.Width) / 2.0, Y: float32(y) - float32(ctx.Height) / 2.0 }
|
||||
screen := rl.Vector2 { X: float32(x), Y: float32(y) }
|
||||
world := rl.GetScreenToWorld2D(screen, ctx.Cam)
|
||||
v := s.Field.Get(world.X, world.Y)
|
||||
@@ -156,30 +149,30 @@ func (s *FieldSketch) Draw(ctx *RenderCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
type ContourSketch struct {
|
||||
type ContourLayer struct {
|
||||
field Field
|
||||
actors []*Actor
|
||||
}
|
||||
|
||||
func NewContourSketch(rng *rand.Rand, field Field) ContourSketch {
|
||||
func NewContourLayer(rng *rand.Rand, field Field) ContourLayer {
|
||||
|
||||
actors := make([]*Actor, 2000)
|
||||
actors := make([]*Actor, 20000)
|
||||
for i := range len(actors) {
|
||||
actors[i] =
|
||||
&Actor {
|
||||
position: RandRadialVec(rng, 0, 500, 0, 360),
|
||||
field: field,
|
||||
stepSize: 0.5,
|
||||
stepSize: 1,
|
||||
color: rl.NewColor(11, 35, 176, 100),
|
||||
}
|
||||
}
|
||||
|
||||
return ContourSketch {
|
||||
return ContourLayer {
|
||||
actors: actors,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ContourSketch) Draw(ctx *RenderCtx) {
|
||||
func (s *ContourLayer) Draw(ctx *RenderCtx) {
|
||||
for _, actor := range s.actors {
|
||||
actor.Draw()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user