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