automated snapshot
This commit is contained in:
50
field.go
50
field.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
"github.com/ojrac/opensimplex-go"
|
||||
)
|
||||
|
||||
@@ -13,14 +14,23 @@ type Field interface {
|
||||
|
||||
// TRANSFORM FIELDS
|
||||
type ScaleField struct {
|
||||
Scale float32
|
||||
Field Field
|
||||
Scale float32
|
||||
}
|
||||
|
||||
func (f *ScaleField) Get(x, y float32) float32 {
|
||||
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
|
||||
|
||||
type SimplexNoiseField struct {
|
||||
@@ -31,3 +41,41 @@ func (f *SimplexNoiseField) Get(x, y float32) float32 {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user