automated snapshot
This commit is contained in:
11
field.go
11
field.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
"github.com/ojrac/opensimplex-go"
|
||||
)
|
||||
@@ -46,7 +47,7 @@ func (f *SimplexNoiseField) Get(x, y float32) float32 {
|
||||
type ImageField struct {
|
||||
image *rl.Image
|
||||
pixels ImagePixels
|
||||
offsetX, offsetY float32
|
||||
offsetX, offsetY int
|
||||
}
|
||||
|
||||
type ImagePixels struct {
|
||||
@@ -66,14 +67,15 @@ func (p *ImagePixels) Get(x, y int) rl.Color {
|
||||
|
||||
func NewImageField(path string) ImageField {
|
||||
image := rl.LoadImage(path)
|
||||
fmt.Printf("loaded image from %s\n", path)
|
||||
colors := rl.LoadImageColors(image)
|
||||
pixels := ImagePixels{
|
||||
w: int(image.Width),
|
||||
h: int(image.Height),
|
||||
colors: colors,
|
||||
}
|
||||
offsetX := float32(image.Width / 2)
|
||||
offsetY := float32(image.Height / 2)
|
||||
offsetX := int(image.Width)/2
|
||||
offsetY := int(image.Height)/2
|
||||
return ImageField{
|
||||
image: image,
|
||||
pixels: pixels,
|
||||
@@ -82,8 +84,9 @@ func NewImageField(path string) ImageField {
|
||||
}
|
||||
}
|
||||
|
||||
// zero centered
|
||||
func (f *ImageField) Get(x, y float32) float32 {
|
||||
// todo : blend colors
|
||||
c := f.pixels.Get(int(x+f.offsetX), int(y+f.offsetY))
|
||||
c := f.pixels.Get(int(x+float32(f.offsetX)), int(y+float32(f.offsetY)))
|
||||
return Brightness(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user