automated snapshot
This commit is contained in:
BIN
aphrodite.jpeg
Normal file
BIN
aphrodite.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
50
field.go
50
field.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
"github.com/ojrac/opensimplex-go"
|
"github.com/ojrac/opensimplex-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,14 +14,23 @@ type Field interface {
|
|||||||
|
|
||||||
// TRANSFORM FIELDS
|
// TRANSFORM FIELDS
|
||||||
type ScaleField struct {
|
type ScaleField struct {
|
||||||
Scale float32
|
|
||||||
Field Field
|
Field Field
|
||||||
|
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 {
|
||||||
|
Field Field
|
||||||
|
x, y float32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *TranslateField) Get(x, y float32) float32 {
|
||||||
|
return f.Field.Get(x + f.x, y + f.y)
|
||||||
|
}
|
||||||
|
|
||||||
// NOISE FIELDS
|
// NOISE FIELDS
|
||||||
|
|
||||||
type SimplexNoiseField struct {
|
type SimplexNoiseField struct {
|
||||||
@@ -31,3 +41,41 @@ func (f *SimplexNoiseField) Get(x, y float32) float32 {
|
|||||||
return f.Noise.Eval2(x, y)
|
return f.Noise.Eval2(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IMAGE FIELDS
|
||||||
|
|
||||||
|
type ImageField struct {
|
||||||
|
image *rl.Image
|
||||||
|
pixels ImagePixels
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImagePixels struct {
|
||||||
|
w, h int
|
||||||
|
colors []rl.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ImagePixels) Get(x, y int) rl.Color {
|
||||||
|
if x < 0 || x >= p.w {
|
||||||
|
return rl.Black
|
||||||
|
}
|
||||||
|
if y < 0 || y >= p.h {
|
||||||
|
return rl.Black
|
||||||
|
}
|
||||||
|
return p.colors[x + y * p.w]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewImageField(path string) ImageField {
|
||||||
|
image := rl.LoadImage(path)
|
||||||
|
colors := rl.LoadImageColors(image)
|
||||||
|
pixels := ImagePixels {
|
||||||
|
w: int(image.Width),
|
||||||
|
h: int(image.Height),
|
||||||
|
colors: colors,
|
||||||
|
}
|
||||||
|
return ImageField { image: image, pixels: pixels }
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *ImageField) Get(x, y float32) float32 {
|
||||||
|
// todo : blend colors
|
||||||
|
c := f.pixels.Get(int(x), int(y))
|
||||||
|
return Brightness(c)
|
||||||
|
}
|
||||||
|
|||||||
26
main.go
26
main.go
@@ -13,8 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
screenWidth = 1400
|
screenWidth = 1200
|
||||||
screenHeight = 700
|
screenHeight = 900
|
||||||
displayScale = 2
|
displayScale = 2
|
||||||
snapshotsDir = "snapshots"
|
snapshotsDir = "snapshots"
|
||||||
)
|
)
|
||||||
@@ -49,20 +49,34 @@ func main() {
|
|||||||
Zoom: 1.0,
|
Zoom: 1.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
field :=
|
field :=
|
||||||
ScaleField {
|
ScaleField {
|
||||||
Scale: 10.0,
|
Scale: 50.0,
|
||||||
Field: &SimplexNoiseField {
|
Field: &SimplexNoiseField {
|
||||||
Noise: opensimplex.NewNormalized32(0),
|
Noise: opensimplex.NewNormalized32(0),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
imgf := NewImageField("aphrodite.jpeg")
|
||||||
|
imageField :=
|
||||||
|
TranslateField {
|
||||||
|
x: float32(w) / 2.0,
|
||||||
|
y: float32(h) / 2.0,
|
||||||
|
//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, &field)
|
contourSketch := NewContourSketch(rng, &imageField)
|
||||||
|
|
||||||
sketches := []Sketch {
|
sketches := []Sketch {
|
||||||
//&FieldSketch { Field: &field },
|
//&FieldSketch { Field: &imageField },
|
||||||
&contourSketch,
|
&contourSketch,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +170,7 @@ func NewContourSketch(rng *rand.Rand, field Field) ContourSketch {
|
|||||||
position: RandRadialVec(rng, 0, 500, 0, 360),
|
position: RandRadialVec(rng, 0, 500, 0, 360),
|
||||||
field: field,
|
field: field,
|
||||||
stepSize: 0.5,
|
stepSize: 0.5,
|
||||||
color: rl.NewColor(11, 35, 176, 200),
|
color: rl.NewColor(11, 35, 176, 170),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
utils.go
6
utils.go
@@ -21,4 +21,10 @@ func GrayCurve(v, k float32) rl.Color {
|
|||||||
return rl.Color{R: c, G: c, B: c, A: 255}
|
return rl.Color{R: c, G: c, B: c, A: 255}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Brightness(c rl.Color) float32 {
|
||||||
|
r := float32(c.R) / 255
|
||||||
|
g := float32(c.G) / 255
|
||||||
|
b := float32(c.B) / 255
|
||||||
|
return 0.2126*r + 0.7152*g + 0.0722*b
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user