more code cleanup
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
sg "github.com/d2fn/sumi/internal/graphics"
|
||||||
"github.com/gen2brain/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
sg "github.com/d2fn/sumi/internal/graphics"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContourLayer struct {
|
type ContourLayer struct {
|
||||||
@@ -13,12 +14,12 @@ type ContourLayer struct {
|
|||||||
maxActors uint32
|
maxActors uint32
|
||||||
actors []*Actor
|
actors []*Actor
|
||||||
actorIndex uint32
|
actorIndex uint32
|
||||||
actorColor sg.Color
|
actorColor color.RGBA
|
||||||
loActorAngle float32
|
loActorAngle float32
|
||||||
hiActorAngle float32
|
hiActorAngle float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color sg.Color, loActorAngle float32, hiActorAngle float32) *ContourLayer {
|
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color color.RGBA, loActorAngle float32, hiActorAngle float32) *ContourLayer {
|
||||||
|
|
||||||
maxActors := 200000
|
maxActors := 200000
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color sg.Color
|
|||||||
return &layer
|
return &layer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContourLayer) AddActors(color sg.Color, n, sourceWidth, sourceHeight int32) {
|
func (s *ContourLayer) AddActors(color color.RGBA, n, sourceWidth, sourceHeight int32) {
|
||||||
for range n {
|
for range n {
|
||||||
x := s.rng.Int31() % sourceWidth
|
x := s.rng.Int31() % sourceWidth
|
||||||
y := s.rng.Int31() % sourceHeight
|
y := s.rng.Int31() % sourceHeight
|
||||||
@@ -56,16 +57,15 @@ func (s *ContourLayer) AddActors(color sg.Color, n, sourceWidth, sourceHeight in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContourLayer) Update(ctx *Env) {
|
func (s *ContourLayer) Update(env *Env, g *sg.Graphics) {
|
||||||
s.AddActors(s.actorColor, 100, int32(ctx.Graphics.Layout.Graphics.Width), int32(ctx.Graphics.Layout.Graphics.Height))
|
s.AddActors(s.actorColor, 100, g.WidthInt32(), g.HeightInt32())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContourLayer) Draw(ctx *Env) {
|
func (s *ContourLayer) Draw(env *Env, g *sg.Graphics) {
|
||||||
g := ctx.Graphics
|
|
||||||
g.BeginAdditiveBlend()
|
g.BeginAdditiveBlend()
|
||||||
for _, actor := range s.actors {
|
for _, actor := range s.actors {
|
||||||
if actor != nil {
|
if actor != nil {
|
||||||
actor.Draw(ctx)
|
actor.Draw(env, g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.EndBlend()
|
g.EndBlend()
|
||||||
@@ -79,18 +79,17 @@ type Actor struct {
|
|||||||
position sg.Point
|
position sg.Point
|
||||||
field Field
|
field Field
|
||||||
stepSize float32
|
stepSize float32
|
||||||
color sg.Color
|
color color.RGBA
|
||||||
loAngle float32
|
loAngle float32
|
||||||
hiAngle float32
|
hiAngle float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Actor) Draw(ctx *Env) {
|
func (a *Actor) Draw(env *Env, g *sg.Graphics) {
|
||||||
v := a.field.Get(a.position.X, a.position.Y)
|
v := a.field.Get(a.position.X, a.position.Y)
|
||||||
rad := rl.Remap(v, 0, 1, a.loAngle, a.hiAngle)
|
rad := rl.Remap(v, 0, 1, a.loAngle, a.hiAngle)
|
||||||
nextPosition := sg.Point{X: a.position.X + a.stepSize*float32(math.Cos(float64(rad))), Y: a.position.Y + a.stepSize*float32(math.Sin(float64(rad)))}
|
nextPosition := sg.Point{X: a.position.X + a.stepSize*float32(math.Cos(float64(rad))), Y: a.position.Y + a.stepSize*float32(math.Sin(float64(rad)))}
|
||||||
//nextPosition := rl.Vector2{X: a.position.X + a.stepSize*float32(math.Cos(float64(rad))), Y: a.position.Y + a.stepSize*float32(math.Sin(float64(rad)))}
|
//nextPosition := rl.Vector2{X: a.position.X + a.stepSize*float32(math.Cos(float64(rad))), Y: a.position.Y + a.stepSize*float32(math.Sin(float64(rad)))}
|
||||||
|
|
||||||
g := ctx.Graphics
|
|
||||||
g.SetStrokeWeight(1.0)
|
g.SetStrokeWeight(1.0)
|
||||||
g.SetStroke(true)
|
g.SetStroke(true)
|
||||||
g.SetStrokeColor(a.color)
|
g.SetStrokeColor(a.color)
|
||||||
@@ -107,8 +106,7 @@ type Worm struct {
|
|||||||
renderPct float32
|
renderPct float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Worm) Draw(ctx *Env) {
|
func (w *Worm) Draw(env *Env, g *sg.Graphics) {
|
||||||
g := ctx.Graphics
|
|
||||||
g.PushMatrix()
|
g.PushMatrix()
|
||||||
g.Translate(w.position)
|
g.Translate(w.position)
|
||||||
//rl.PushMatrix()
|
//rl.PushMatrix()
|
||||||
|
|||||||
33
env.go
33
env.go
@@ -2,14 +2,28 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
sg "github.com/d2fn/sumi/internal/graphics"
|
sg "github.com/d2fn/sumi/internal/graphics"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Env **/
|
/** Env **/
|
||||||
type Env struct {
|
type Env struct {
|
||||||
Layout Layout
|
Time time.Time
|
||||||
Time float64
|
Frame uint
|
||||||
Ports map[string]float64
|
Ports map[string]float64
|
||||||
Graphics sg.Graphics
|
Layout Layout
|
||||||
|
Viewport *sg.Graphics
|
||||||
|
Window *sg.Graphics
|
||||||
|
Controls *sg.Graphics
|
||||||
|
Offscreen *sg.Graphics
|
||||||
|
Storage *Storage
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEnv() *Env {
|
||||||
|
return &Env{
|
||||||
|
Time: time.Now(),
|
||||||
|
Frame: 0,
|
||||||
|
Ports: make(map[string]float64),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Layout struct {
|
type Layout struct {
|
||||||
@@ -22,16 +36,5 @@ type Layout struct {
|
|||||||
// bounds of the region of the app window reserved for rendering the graphics buffer
|
// bounds of the region of the app window reserved for rendering the graphics buffer
|
||||||
Viewport sg.Rect
|
Viewport sg.Rect
|
||||||
// bounds of the off screen graphics buffer where rendering happens
|
// bounds of the off screen graphics buffer where rendering happens
|
||||||
Graphics sg.Rect
|
Offscreen sg.Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (ctx *Env) GetGraphicsWidth() float32 {
|
|
||||||
return ctx.Graphics.Bounds.Width
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctx *Env) GetGraphicsHeight() float32 {
|
|
||||||
return ctx.Graphics.Bounds.Height
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
field.go
13
field.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
sg "github.com/d2fn/sumi/internal/graphics"
|
||||||
rl "github.com/gen2brain/raylib-go/raylib"
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
"github.com/ojrac/opensimplex-go"
|
"github.com/ojrac/opensimplex-go"
|
||||||
"math"
|
"math"
|
||||||
@@ -105,11 +106,13 @@ func (fl *FieldLayer) Update(env *Env) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fl *FieldLayer) Draw(env *Env) {
|
func (fl *FieldLayer) Draw(env *Env, g *sg.Graphics) {
|
||||||
rl.ClearBackground(rl.Blank)
|
g.Clear()
|
||||||
rl.BeginBlendMode(rl.BlendAlphaPremultiply)
|
g.BeginAdditiveBlend()
|
||||||
for x := range int32(env.GetGraphicsHeight()) {
|
//rl.ClearBackground(rl.Blank)
|
||||||
for y := range int32(env.GetGraphicsHeight()) {
|
//rl.BeginBlendMode(rl.BlendAlphaPremultiply)
|
||||||
|
for x := range g.WidthInt32() {
|
||||||
|
for y := range g.HeightInt32() {
|
||||||
v := fl.field.Get(float32(x), float32(y))
|
v := fl.field.Get(float32(x), float32(y))
|
||||||
clr := LerpCurve(v, 1.3, fl.loColor, fl.hiColor)
|
clr := LerpCurve(v, 1.3, fl.loColor, fl.hiColor)
|
||||||
rl.DrawPixel(x, y, clr)
|
rl.DrawPixel(x, y, clr)
|
||||||
|
|||||||
@@ -12,17 +12,63 @@ type Graphics struct {
|
|||||||
Bounds Rect
|
Bounds Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateGraphics(bounds Rect) *Graphics {
|
||||||
|
return &Graphics {
|
||||||
|
Bounds: bounds,
|
||||||
|
Style: Style {
|
||||||
|
Fill: false,
|
||||||
|
FillColor: rl.RayWhite,
|
||||||
|
Stroke: true,
|
||||||
|
StrokeColor: rl.Black,
|
||||||
|
StrokeWeight: 1.0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Style struct {
|
type Style struct {
|
||||||
StrokeColor, FillColor color.RGBA
|
StrokeColor, FillColor color.RGBA
|
||||||
StrokeWeight float32
|
StrokeWeight float32
|
||||||
Stroke, Fill bool
|
Stroke, Fill bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) GetGraphicsWidth() int32 {
|
func (g *Graphics) Center() Point {
|
||||||
|
return g.Bounds.Center()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) Begin() {
|
||||||
|
rl.BeginBlendMode(rl.BlendAlphaPremultiply)
|
||||||
|
g.PushMatrix()
|
||||||
|
g.Translate(g.Bounds.UL())
|
||||||
|
g.BeginClip(g.Bounds)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) Clear() {
|
||||||
|
rl.ClearBackground(rl.Blank)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) Background(c color.RGBA) {
|
||||||
|
rl.ClearBackground(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) End() {
|
||||||
|
g.EndBlend()
|
||||||
|
g.EndClip()
|
||||||
|
g.PopMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) Width() float32 {
|
||||||
|
return g.Bounds.Width
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) Height() float32 {
|
||||||
|
return g.Bounds.Height
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) WidthInt32() int32 {
|
||||||
return int32(g.Bounds.Width)
|
return int32(g.Bounds.Width)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) GetGraphicsHeight() int32 {
|
func (g *Graphics) HeightInt32() int32 {
|
||||||
return int32(g.Bounds.Height)
|
return int32(g.Bounds.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,11 +79,11 @@ func (g *Graphics) PushStyle() {
|
|||||||
func (g *Graphics) PopStyle() {
|
func (g *Graphics) PopStyle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) SetStrokeColor(c Color) {
|
func (g *Graphics) SetStrokeColor(c color.RGBA) {
|
||||||
g.Style.StrokeColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
g.Style.StrokeColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) SetFillColor(c Color) {
|
func (g *Graphics) SetFillColor(c color.RGBA) {
|
||||||
g.Style.FillColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
g.Style.FillColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +133,16 @@ func (g *Graphics) BeginTexture(t rl.RenderTexture2D) {
|
|||||||
rl.BeginTextureMode(t)
|
rl.BeginTextureMode(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (g *Graphics) DrawTexture(t rl.Texture2D, p Point, c color.RGBA) {
|
||||||
|
rl.DrawTexture(t, int32(p.X), int32(p.Y), c)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (g *Graphics) TransferTexture(t rl.Texture2D, src Rect, dst Rect, tint color.RGBA) {
|
||||||
|
rl.DrawTexturePro(t, src.ToRL(), dst.ToRL(), rl.Vector2{}, 0, tint)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Graphics) EndTexture() {
|
func (g *Graphics) EndTexture() {
|
||||||
rl.EndTextureMode()
|
rl.EndTextureMode()
|
||||||
}
|
}
|
||||||
@@ -114,22 +170,25 @@ func (g *Graphics) DrawLine(a, b Point) {
|
|||||||
rl.SetLineWidth(saveLineWidth)
|
rl.SetLineWidth(saveLineWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Color color.RGBA
|
|
||||||
|
|
||||||
func RGBA(r, g, b, a uint8) Color {
|
|
||||||
return Color { R: r, G: g, B: b, A: a }
|
|
||||||
}
|
|
||||||
|
|
||||||
type HSBA struct {
|
type HSBA struct {
|
||||||
H uint
|
H uint
|
||||||
S, B float32
|
S, B float32
|
||||||
A uint8
|
A uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Origin = Point { X: 0, Y: 0, Z: 0 }
|
||||||
|
|
||||||
type Point rl.Vector3
|
type Point rl.Vector3
|
||||||
type Vec rl.Vector3
|
type Vec rl.Vector3
|
||||||
type Rect rl.Rectangle
|
type Rect rl.Rectangle
|
||||||
|
|
||||||
|
func (r *Rect) Center() Point {
|
||||||
|
return Point {
|
||||||
|
X: r.X + r.Width / 2,
|
||||||
|
Y: r.X + r.Height / 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Point) Add(v Vec) Point {
|
func (p *Point) Add(v Vec) Point {
|
||||||
return Point { X: p.X + v.X, Y: p.Y + v.Y, Z: p.Z + v.Z }
|
return Point { X: p.X + v.X, Y: p.Y + v.Y, Z: p.Z + v.Z }
|
||||||
}
|
}
|
||||||
|
|||||||
59
main.go
59
main.go
@@ -17,8 +17,7 @@ import (
|
|||||||
//"github.com/ojrac/opensimplex-go"
|
//"github.com/ojrac/opensimplex-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Bootstrap() *Env {
|
||||||
func Bootstrap() sg.Graphics {
|
|
||||||
|
|
||||||
rl.InitWindow(800, 600, "bootstrap")
|
rl.InitWindow(800, 600, "bootstrap")
|
||||||
|
|
||||||
@@ -48,6 +47,8 @@ func Bootstrap() sg.Graphics {
|
|||||||
defaultWindowWidth, defaultWindowHeight,
|
defaultWindowWidth, defaultWindowHeight,
|
||||||
defaultGraphicsWidth, defaultWindowHeight)
|
defaultGraphicsWidth, defaultWindowHeight)
|
||||||
|
|
||||||
|
var snapshotsPath string
|
||||||
|
|
||||||
flag.StringVar(&snapshotsPath, "path", "snapshots", "Path to snapshots and db")
|
flag.StringVar(&snapshotsPath, "path", "snapshots", "Path to snapshots and db")
|
||||||
flag.IntVar(&graphicsWidth, "gw", defaultGraphicsWidth, "Width of the internal graphics buffer. Can be much larger than the screen.")
|
flag.IntVar(&graphicsWidth, "gw", defaultGraphicsWidth, "Width of the internal graphics buffer. Can be much larger than the screen.")
|
||||||
flag.IntVar(&graphicsHeight, "gh", defaultGraphicsHeight, "Height of the internal graphics buffer. Can be much larger than the screen.")
|
flag.IntVar(&graphicsHeight, "gh", defaultGraphicsHeight, "Height of the internal graphics buffer. Can be much larger than the screen.")
|
||||||
@@ -64,50 +65,47 @@ func Bootstrap() sg.Graphics {
|
|||||||
|
|
||||||
os.MkdirAll(snapshotsPath, 0755)
|
os.MkdirAll(snapshotsPath, 0755)
|
||||||
var err error
|
var err error
|
||||||
storage, err = NewStorage(snapshotsPath)
|
storage, err := NewStorage(snapshotsPath)
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
layout := sg.Layout {
|
layout := Layout{
|
||||||
Monitor: sg.Rect{X: 0, Y: 0, Width: float32(monitorWidth), Height: float32(monitorHeight)},
|
Monitor: sg.Rect{X: 0, Y: 0, Width: float32(monitorWidth), Height: float32(monitorHeight)},
|
||||||
Window: sg.Rect{X: 0, Y: 0, Width: float32(windowWidth), Height: float32(windowHeight)},
|
Window: sg.Rect{X: 0, Y: 0, Width: float32(windowWidth), Height: float32(windowHeight)},
|
||||||
Controls: sg.Rect{X: 0, Y: 0, Width: float32(controlsWidth), Height: float32(windowHeight)},
|
Controls: sg.Rect{X: 0, Y: 0, Width: float32(controlsWidth), Height: float32(windowHeight)},
|
||||||
Viewport: sg.Rect{X: float32(controlsWidth), Y: 0, Width: float32(viewportWidth), Height: float32(windowHeight)},
|
Viewport: sg.Rect{X: float32(controlsWidth), Y: 0, Width: float32(viewportWidth), Height: float32(windowHeight)},
|
||||||
Graphics: sg.Rect{X: 0, Y: 0, Width: float32(graphicsWidth), Height: float32(graphicsHeight)},
|
Offscreen: sg.Rect{X: 0, Y: 0, Width: float32(graphicsWidth), Height: float32(graphicsHeight)},
|
||||||
}
|
}
|
||||||
|
|
||||||
//rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
//rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||||
rl.InitWindow(int32(layout.Window.Width), int32(layout.Window.Height), "sumi sierpinski arrow")
|
rl.InitWindow(int32(layout.Window.Width), int32(layout.Window.Height), "sumi sierpinski arrow")
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
return sg.Graphics {
|
env := NewEnv()
|
||||||
Layout: layout,
|
env.Layout = layout
|
||||||
Style: sg.Style {
|
env.Window = sg.CreateGraphics(layout.Window)
|
||||||
Fill: false,
|
env.Viewport = sg.CreateGraphics(layout.Viewport)
|
||||||
FillColor: rl.RayWhite,
|
env.Offscreen = sg.CreateGraphics(layout.Offscreen)
|
||||||
Stroke: true,
|
env.Controls = sg.CreateGraphics(layout.Controls)
|
||||||
StrokeColor: rl.Black,
|
env.Storage = storage
|
||||||
StrokeWeight: 1.0,
|
|
||||||
},
|
return env
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
log := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||||
|
|
||||||
g := Bootstrap()
|
env := Bootstrap()
|
||||||
|
|
||||||
// reproducable flourescent color cycle
|
// reproducable flourescent color cycle
|
||||||
colorCycle := sg.NewFixedColorCycle(sg.FlourescentColors).Shuffle(0)
|
colorCycle := sg.NewFixedColorCycle(sg.FlourescentColors).Shuffle(0)
|
||||||
|
|
||||||
t0 := time.Now()
|
rng := rand.New(rand.NewSource(env.Time.Unix()))
|
||||||
|
|
||||||
rng := rand.New(rand.NewSource(0))
|
|
||||||
//imageField := NewImageField("/home/d/Dropbox/art/data/david.png")
|
//imageField := NewImageField("/home/d/Dropbox/art/data/david.png")
|
||||||
noiseField := &SimplexNoiseField{Noise: opensimplex.New32(0)}
|
noiseField := &SimplexNoiseField{Noise: opensimplex.New32(env.Time.Unix())}
|
||||||
sinXYField := &SinXYField{}
|
sinXYField := &SinXYField{}
|
||||||
//imageField := NewImageField("/home/d/Dropbox/art/data/ramstatue.png")
|
//imageField := NewImageField("/home/d/Dropbox/art/data/ramstatue.png")
|
||||||
//imageField := NewImageField("/home/d/Dropbox/art/data/bassrockastro/Photo Dec 24 2025, 5 58 23 PM.jpg")
|
//imageField := NewImageField("/home/d/Dropbox/art/data/bassrockastro/Photo Dec 24 2025, 5 58 23 PM.jpg")
|
||||||
@@ -115,8 +113,8 @@ func main() {
|
|||||||
//imageField := NewImageField("/home/d/Dropbox/art/data/moses_statue.jpg")
|
//imageField := NewImageField("/home/d/Dropbox/art/data/moses_statue.jpg")
|
||||||
field :=
|
field :=
|
||||||
&TranslateField{
|
&TranslateField{
|
||||||
x: -float32(g.Layout.Graphics.Width / 2.0),
|
x: -float32(env.Offscreen.Bounds.Width / 2.0),
|
||||||
y: -float32(g.Layout.Graphics.Height / 2.0),
|
y: -float32(env.Offscreen.Bounds.Height / 2.0),
|
||||||
field: &ScaleField{
|
field: &ScaleField{
|
||||||
scale: 100.0,
|
scale: 100.0,
|
||||||
field: &AdderField{
|
field: &AdderField{
|
||||||
@@ -130,7 +128,7 @@ func main() {
|
|||||||
|
|
||||||
//sierpinskiLayer := &SierpinskiArrow { dirty: true }
|
//sierpinskiLayer := &SierpinskiArrow { dirty: true }
|
||||||
|
|
||||||
sketch := NewSketch(&g)
|
sketch := NewSketch(env)
|
||||||
|
|
||||||
fieldColor := colorCycle.Next()
|
fieldColor := colorCycle.Next()
|
||||||
fmt.Printf("field color = %v\n", fieldColor)
|
fmt.Printf("field color = %v\n", fieldColor)
|
||||||
@@ -148,11 +146,10 @@ func main() {
|
|||||||
actorColor = sg.Clamp(actorColor, 10, 255)
|
actorColor = sg.Clamp(actorColor, 10, 255)
|
||||||
actorColor.A = 10
|
actorColor.A = 10
|
||||||
|
|
||||||
actorSGColor := sg.Color { R: actorColor.R, G: actorColor.G, B: actorColor.B, A: actorColor.A }
|
|
||||||
//NewColor(11, 35, 176, 50),
|
//NewColor(11, 35, 176, 50),
|
||||||
|
|
||||||
//r
|
//r
|
||||||
contourLayer := NewContourLayer(&sketch, rng, field, actorSGColor, -25*math.Pi, 25*math.Pi)
|
contourLayer := NewContourLayer(&sketch, rng, field, actorColor, -25*math.Pi, 25*math.Pi)
|
||||||
sketch.AddLayer("contours", contourLayer)
|
sketch.AddLayer("contours", contourLayer)
|
||||||
//sketch.AddLayer("sierpinski-arrowhead", sierpinskiLayer)
|
//sketch.AddLayer("sierpinski-arrowhead", sierpinskiLayer)
|
||||||
// aurora := NewImageLayer("/home/d/Dropbox/photos/Events/2025/Aurora/Photo Nov 11 2025, 9 52 03 PM.jpg")
|
// aurora := NewImageLayer("/home/d/Dropbox/photos/Events/2025/Aurora/Photo Nov 11 2025, 9 52 03 PM.jpg")
|
||||||
@@ -181,14 +178,10 @@ func main() {
|
|||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
// begin drawing
|
// begin drawing
|
||||||
t := time.Since(t0).Seconds()
|
t := time.Since(env.Time).Seconds()
|
||||||
|
|
||||||
// set up RenderCtx
|
env.Time = time.Now()
|
||||||
env := &Env {
|
env.Ports = ports.Eval(t)
|
||||||
Graphics: g,
|
|
||||||
Time: t,
|
|
||||||
Ports: ports.Eval(t),
|
|
||||||
}
|
|
||||||
|
|
||||||
sketch.Update(env)
|
sketch.Update(env)
|
||||||
|
|
||||||
@@ -267,7 +260,7 @@ func main() {
|
|||||||
for ch := rl.GetCharPressed(); ch != 0; ch = rl.GetCharPressed() {
|
for ch := rl.GetCharPressed(); ch != 0; ch = rl.GetCharPressed() {
|
||||||
c := rune(ch)
|
c := rune(ch)
|
||||||
if c == 'c' {
|
if c == 'c' {
|
||||||
sketch.ResetCamera()
|
sketch.ResetCamera(env)
|
||||||
} else if c >= '1' && c <= '9' {
|
} else if c >= '1' && c <= '9' {
|
||||||
zoom := 1 << int(ch-'0')
|
zoom := 1 << int(ch-'0')
|
||||||
sketch.cam.Zoom = float32(zoom)
|
sketch.cam.Zoom = float32(zoom)
|
||||||
|
|||||||
192
sketch.go
192
sketch.go
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Sketch struct {
|
type Sketch struct {
|
||||||
graphics *sg.Graphics
|
env *Env
|
||||||
cam *TextureCam
|
cam *TextureCam
|
||||||
composite rl.RenderTexture2D
|
composite rl.RenderTexture2D
|
||||||
layerTools map[string]*LayerTools
|
layerTools map[string]*LayerTools
|
||||||
@@ -42,26 +42,26 @@ type LayerConfig struct {
|
|||||||
kValue float32
|
kValue float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSketch(g *sg.Graphics) Sketch {
|
func NewSketch(env *Env) Sketch {
|
||||||
|
|
||||||
// point at source center
|
// point at source center
|
||||||
// put source center at center of screen
|
// put source center at center of screen
|
||||||
var camera = TextureCam{
|
var camera = TextureCam{
|
||||||
LookAt: rl.Vector2{X: float32(g.Layout.Graphics.Width) / 2.0, Y: float32(g.Layout.Graphics.Height) / 2.0},
|
LookAt: rl.Vector2{X: env.Offscreen.Width() / 2.0, Y: env.Offscreen.Height() / 2.0},
|
||||||
Zoom: 1.0,
|
Zoom: 1.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
return Sketch{
|
return Sketch{
|
||||||
graphics: g,
|
env: env,
|
||||||
layerTools: make(map[string]*LayerTools),
|
layerTools: make(map[string]*LayerTools),
|
||||||
layerToolsOrdered: []*LayerTools{},
|
layerToolsOrdered: []*LayerTools{},
|
||||||
composite: rl.LoadRenderTexture(int32(g.Layout.Graphics.Width), int32(g.Layout.Graphics.Height)),
|
composite: rl.LoadRenderTexture(env.Offscreen.WidthInt32(), env.Offscreen.HeightInt32()),
|
||||||
cam: &camera,
|
cam: &camera,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) AddLayer(name string, layer Layer) {
|
func (s *Sketch) AddLayer(name string, layer Layer) {
|
||||||
texture := rl.LoadRenderTexture(int32(s.graphics.Layout.Graphics.Width), int32(s.graphics.Layout.Graphics.Height))
|
texture := rl.LoadRenderTexture(s.env.Offscreen.WidthInt32(), s.env.Offscreen.HeightInt32())
|
||||||
config := NewLayerConfig()
|
config := NewLayerConfig()
|
||||||
layerTools :=
|
layerTools :=
|
||||||
LayerTools{
|
LayerTools{
|
||||||
@@ -82,35 +82,37 @@ func (s *Sketch) AddColorLayer(name string, c rl.Color) {
|
|||||||
s.AddLayer(name, colorLayer)
|
s.AddLayer(name, colorLayer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) Redraw(ctx *Env) {
|
func (s *Sketch) RedrawLayers(env *Env, g *sg.Graphics) {
|
||||||
g := ctx.Graphics
|
|
||||||
// render onto all layer textures
|
// render onto all layer textures
|
||||||
for _, instance := range s.layerToolsOrdered {
|
for _, instance := range s.layerToolsOrdered {
|
||||||
layer := instance.layer
|
layer := instance.layer
|
||||||
// ignore this layer entirely unless it's visible
|
// ignore this layer entirely unless it's visible
|
||||||
if instance.config.visible {
|
if instance.config.visible {
|
||||||
layer.Update(ctx)
|
w := float32(instance.texture.Texture.Width)
|
||||||
|
h := float32(instance.texture.Texture.Height)
|
||||||
|
lg := sg.CreateGraphics(sg.Rect { X: 0, Y: 0, Width: w, Height: h })
|
||||||
|
layer.Update(env, g)
|
||||||
// re-render to texture if dirty
|
// re-render to texture if dirty
|
||||||
if instance.layer.IsDirty() {
|
if instance.layer.IsDirty() {
|
||||||
g.PushMatrix()
|
lg.Begin()
|
||||||
g.BeginTexture(instance.texture)
|
lg.BeginTexture(instance.texture)
|
||||||
layer.Draw(ctx)
|
layer.Draw(env, lg)
|
||||||
g.PopMatrix()
|
lg.EndTexture()
|
||||||
g.EndTexture()
|
lg.End()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) Draw(ctx *Env) {
|
func (s *Sketch) Draw(env *Env) {
|
||||||
|
|
||||||
g := ctx.Graphics
|
offscreen := env.Offscreen
|
||||||
s.Redraw(ctx)
|
s.RedrawLayers(env, offscreen)
|
||||||
|
|
||||||
// copy from full texture for compositing, with vertical flipping
|
// copy from full texture for compositing, with vertical flipping
|
||||||
src := g.Layout.Graphics
|
src := offscreen.Bounds
|
||||||
src.Height = -src.Height
|
src.Height = -src.Height
|
||||||
dst := g.Layout.Graphics
|
dst := offscreen.Bounds
|
||||||
|
|
||||||
/*
|
/*
|
||||||
src := g.Rect {
|
src := g.Rect {
|
||||||
@@ -125,44 +127,56 @@ func (s *Sketch) Draw(ctx *Env) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
viewport := s.CalcViewport(ctx)
|
offscreen.Begin()
|
||||||
|
|
||||||
outputRect := g.Layout.Graphics.ScaleTo(g.Layout.Viewport)
|
// calculate the viewable region of the offscreen buffer
|
||||||
|
viewport := s.CalcViewport(env)
|
||||||
|
|
||||||
|
// scale the offscreen buffer to the viewport maintaining aspect ratio
|
||||||
|
outputRect := offscreen.Bounds.ScaleTo(env.Viewport.Bounds)
|
||||||
fmt.Printf("outputRect = %v\n", outputRect)
|
fmt.Printf("outputRect = %v\n", outputRect)
|
||||||
|
|
||||||
x := float32(0)
|
x := float32(0)
|
||||||
y := float32(0)
|
y := float32(0)
|
||||||
w := outputRect.Width
|
w := outputRect.Width
|
||||||
h := outputRect.Height
|
h := outputRect.Height
|
||||||
g.PushMatrix()
|
|
||||||
g.Translate(outputRect.UL())
|
output := sg.CreateGraphics(outputRect)
|
||||||
g.BeginClip(outputRect)
|
|
||||||
checkSize := float32(25.0)
|
output.Begin()
|
||||||
grey := rl.NewColor(220, 220, 220, 255)
|
output.SetFill(true)
|
||||||
|
output.SetStroke(false)
|
||||||
|
checkSize := float32(outputRect.Width / 30.0)
|
||||||
|
grey := sg.RGBA(220, 220, 220, 255)
|
||||||
cellX := 0
|
cellX := 0
|
||||||
cellY := 0
|
cellY := 0
|
||||||
for y < h {
|
for y < h {
|
||||||
x = 0
|
x = 0
|
||||||
cellX = 0
|
cellX = 0
|
||||||
for x < w {
|
for x < w {
|
||||||
c := rl.White
|
c := sg.RGBA(rl.White.R, rl.White.G, rl.White.B, rl.White.A)
|
||||||
if ((cellX + cellY) & 1) == 1 {
|
if ((cellX + cellY) & 1) == 1 {
|
||||||
c = grey
|
c = grey
|
||||||
}
|
}
|
||||||
rl.DrawRectangle(int32(x), int32(y), int32(checkSize), int32(checkSize), c)
|
output.SetFillColor(c)
|
||||||
|
output.DrawRect(sg.Rect { X: x, Y: y, Width: checkSize, Height: checkSize })
|
||||||
|
//rl.DrawRectangle(int32(x), int32(y), int32(checkSize), int32(checkSize), c)
|
||||||
x += checkSize
|
x += checkSize
|
||||||
cellX++
|
cellX++
|
||||||
}
|
}
|
||||||
y += checkSize
|
y += checkSize
|
||||||
cellY++
|
cellY++
|
||||||
}
|
}
|
||||||
g.EndClip()
|
|
||||||
g.PopMatrix()
|
|
||||||
|
|
||||||
rl.BeginBlendMode(rl.BlendAlphaPremultiply)
|
// render each layer onto the output graphics context
|
||||||
|
offscreen.BeginTexture(s.composite)
|
||||||
|
offscreen.Clear()
|
||||||
|
|
||||||
|
//rl.BeginBlendMode(rl.BlendAlphaPremultiply)
|
||||||
//rl.BeginBlendMode(rl.BlendAlpha)
|
//rl.BeginBlendMode(rl.BlendAlpha)
|
||||||
rl.BeginTextureMode(s.composite)
|
//rl.BeginTextureMode(s.composite)
|
||||||
rl.ClearBackground(rl.Blank)
|
|
||||||
|
//rl.ClearBackground(rl.Blank)
|
||||||
//rl.ClearBackground(rl.Black)
|
//rl.ClearBackground(rl.Black)
|
||||||
for _, instance := range s.layerToolsOrdered {
|
for _, instance := range s.layerToolsOrdered {
|
||||||
config := instance.config
|
config := instance.config
|
||||||
@@ -183,39 +197,44 @@ func (s *Sketch) Draw(ctx *Env) {
|
|||||||
g = uint8(float32(g) * (float32(config.a) / 255.0))
|
g = uint8(float32(g) * (float32(config.a) / 255.0))
|
||||||
b = uint8(float32(b) * (float32(config.a) / 255.0))
|
b = uint8(float32(b) * (float32(config.a) / 255.0))
|
||||||
tint := rl.NewColor(r, g, b, config.a)
|
tint := rl.NewColor(r, g, b, config.a)
|
||||||
rl.DrawTexturePro(instance.texture.Texture, src.ToRL(), dst.ToRL(), rl.Vector2{}, 0, tint)
|
offscreen.TransferTexture(instance.texture.Texture, src, dst, tint)
|
||||||
|
//rl.DrawTexturePro(instance.texture.Texture, src.ToRL(), dst.ToRL(), rl.Vector2{}, 0, tint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rl.EndTextureMode()
|
offscreen.EndTexture()
|
||||||
rl.EndBlendMode()
|
offscreen.End()
|
||||||
|
|
||||||
rl.GenTextureMipmaps(&s.composite.Texture)
|
rl.GenTextureMipmaps(&s.composite.Texture)
|
||||||
rl.SetTextureFilter(s.composite.Texture, rl.FilterTrilinear)
|
rl.SetTextureFilter(s.composite.Texture, rl.FilterTrilinear)
|
||||||
|
|
||||||
rl.DrawTexturePro(s.composite.Texture, viewport.ToRL(), outputRect.ToRL(), rl.Vector2{}, 0, rl.White)
|
output.TransferTexture(s.composite.Texture, viewport, outputRect, rl.White)
|
||||||
|
|
||||||
outputRectRL := outputRect.ToRL()
|
output.SetFill(false)
|
||||||
outlineRect := (&outputRectRL).ToInt32()
|
output.SetStroke(true)
|
||||||
rl.DrawRectangleLines(outlineRect.X, outlineRect.Y, outlineRect.Width, outlineRect.Height, rl.Gray)
|
output.SetStrokeColor(rl.Gray)
|
||||||
|
output.DrawRect(outputRect)
|
||||||
|
|
||||||
|
output.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) CalcViewport(ctx *Env) sg.Rect {
|
// calculate the visible clip of the offscreen buffer based on the camera /zoom
|
||||||
viewportWidth := rl.Clamp(float32(ctx.Graphics.Layout.Graphics.Width)/s.cam.Zoom, 0, float32(ctx.Graphics.Layout.Graphics.Width))
|
func (s *Sketch) CalcViewport(env *Env) sg.Rect {
|
||||||
viewportHeight := rl.Clamp(float32(ctx.Graphics.Layout.Graphics.Height)/s.cam.Zoom, 0, float32(ctx.Graphics.Layout.Graphics.Height))
|
viewportWidth := rl.Clamp(env.Offscreen.Width()/s.cam.Zoom, 0, env.Offscreen.Width())
|
||||||
|
viewportHeight := rl.Clamp(env.Offscreen.Height()/s.cam.Zoom, 0, env.Offscreen.Width())
|
||||||
return sg.Rect{
|
return sg.Rect{
|
||||||
X: rl.Clamp(s.cam.LookAt.X-viewportWidth/2.0, 0, float32(ctx.Graphics.Layout.Graphics.Width)-viewportWidth),
|
X: rl.Clamp(s.cam.LookAt.X-viewportWidth/2.0, 0, env.Layout.Offscreen.Width-viewportWidth),
|
||||||
Y: rl.Clamp(s.cam.LookAt.Y-viewportHeight/2.0, 0, float32(ctx.Graphics.Layout.Graphics.Height)-viewportHeight),
|
Y: rl.Clamp(s.cam.LookAt.Y-viewportHeight/2.0, 0, env.Layout.Offscreen.Height-viewportHeight),
|
||||||
Width: float32(viewportWidth),
|
Width: viewportWidth,
|
||||||
Height: -float32(viewportHeight),
|
Height: -viewportHeight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) Update(ctx *Env) {
|
func (s *Sketch) Update(env *Env) {
|
||||||
|
|
||||||
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
||||||
// get mouse delta from last frame
|
// get mouse delta from last frame
|
||||||
delta := rl.GetMouseDelta()
|
delta := rl.GetMouseDelta()
|
||||||
sourceScale := float32(ctx.Graphics.Layout.Graphics.Width) / float32(ctx.Graphics.Layout.Viewport.Width)
|
sourceScale := env.Offscreen.Width() / env.Viewport.Width()
|
||||||
// compute the amount to move scaled by the camera zoom
|
// compute the amount to move scaled by the camera zoom
|
||||||
delta = rl.Vector2Scale(delta, -sourceScale/s.cam.Zoom)
|
delta = rl.Vector2Scale(delta, -sourceScale/s.cam.Zoom)
|
||||||
delta.Y = -delta.Y
|
delta.Y = -delta.Y
|
||||||
@@ -223,8 +242,8 @@ func (s *Sketch) Update(ctx *Env) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clamp LookAt to be somewhere on the texture
|
// clamp LookAt to be somewhere on the texture
|
||||||
s.cam.LookAt.X = rl.Clamp(s.cam.LookAt.X, 0, float32(ctx.Graphics.Layout.Graphics.Width))
|
s.cam.LookAt.X = rl.Clamp(s.cam.LookAt.X, 0, env.Offscreen.Width())
|
||||||
s.cam.LookAt.Y = rl.Clamp(s.cam.LookAt.Y, 0, float32(ctx.Graphics.Layout.Graphics.Height))
|
s.cam.LookAt.Y = rl.Clamp(s.cam.LookAt.Y, 0, env.Offscreen.Height())
|
||||||
|
|
||||||
// Zoom based on mouse wheel
|
// Zoom based on mouse wheel
|
||||||
wheel := rl.GetMouseWheelMove()
|
wheel := rl.GetMouseWheelMove()
|
||||||
@@ -241,8 +260,12 @@ func (s *Sketch) Update(ctx *Env) {
|
|||||||
s.cam.Zoom = rl.Clamp(s.cam.Zoom, 1, math.MaxInt64)
|
s.cam.Zoom = rl.Clamp(s.cam.Zoom, 1, math.MaxInt64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) ResetCamera() {
|
func (s *Sketch) ResetCamera(env *Env) {
|
||||||
s.cam.LookAt = rl.Vector2{X: float32(s.graphics.Layout.Graphics.Width) / 2.0, Y: float32(s.graphics.Layout.Graphics.Height) / 2.0}
|
s.cam.LookAt =
|
||||||
|
rl.Vector2 {
|
||||||
|
X: env.Offscreen.Width() / 2.0,
|
||||||
|
Y: env.Offscreen.Height() / 2.0,
|
||||||
|
}
|
||||||
s.cam.Zoom = 1.0
|
s.cam.Zoom = 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +276,7 @@ type SketchCapture struct {
|
|||||||
layerToolsOrdered []*LayerTools
|
layerToolsOrdered []*LayerTools
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sketch) Capture() *SketchCapture {
|
func (s *Sketch) Capture(env *Env) *SketchCapture {
|
||||||
composite := rl.LoadImageFromTexture(s.composite.Texture)
|
composite := rl.LoadImageFromTexture(s.composite.Texture)
|
||||||
rl.ImageFlipVertical(composite)
|
rl.ImageFlipVertical(composite)
|
||||||
for _, layerTool := range s.layerToolsOrdered {
|
for _, layerTool := range s.layerToolsOrdered {
|
||||||
@@ -261,8 +284,8 @@ func (s *Sketch) Capture() *SketchCapture {
|
|||||||
rl.ImageFlipVertical(layerTool.capture)
|
rl.ImageFlipVertical(layerTool.capture)
|
||||||
}
|
}
|
||||||
return &SketchCapture{
|
return &SketchCapture{
|
||||||
width: s.graphics.GetGraphicsWidth(),
|
width: env.Offscreen.WidthInt32(),
|
||||||
height: s.graphics.GetGraphicsHeight(),
|
height: env.Offscreen.HeightInt32(),
|
||||||
compositeImage: composite,
|
compositeImage: composite,
|
||||||
layerTools: s.layerTools,
|
layerTools: s.layerTools,
|
||||||
layerToolsOrdered: s.layerToolsOrdered,
|
layerToolsOrdered: s.layerToolsOrdered,
|
||||||
@@ -287,8 +310,8 @@ func NewLayerConfig() LayerConfig {
|
|||||||
/** Layer **/
|
/** Layer **/
|
||||||
|
|
||||||
type Layer interface {
|
type Layer interface {
|
||||||
Update(ctx *Env)
|
Update(ctx *Env, g *sg.Graphics)
|
||||||
Draw(ctx *Env)
|
Draw(ctx *Env, g *sg.Graphics)
|
||||||
IsDirty() bool
|
IsDirty() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,12 +320,13 @@ type ColorLayer struct {
|
|||||||
dirty bool
|
dirty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *ColorLayer) Update(ctx *Env) {
|
func (cl *ColorLayer) Update(ctx *Env, g *sg.Graphics) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *ColorLayer) Draw(ctx *Env) {
|
func (cl *ColorLayer) Draw(ctx *Env, g *sg.Graphics) {
|
||||||
rl.ClearBackground(cl.color)
|
g.Background(cl.color)
|
||||||
|
//rl.ClearBackground(cl.color)
|
||||||
cl.dirty = false
|
cl.dirty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,55 +348,21 @@ func NewImageLayer(path string) *ImageLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (il *ImageLayer) Update(ctx *Env) {
|
func (il *ImageLayer) Update(ctx *Env, g *sg.Graphics) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (il *ImageLayer) Draw(ctx *Env) {
|
func (il *ImageLayer) Draw(env *Env, g *sg.Graphics) {
|
||||||
rl.Translatef(float32(ctx.GetGraphicsWidth())/2.0-float32(il.texture.Width)/2.0, float32(ctx.GetGraphicsHeight())/2.0-float32(il.texture.Height)/2.0, 0)
|
rl.Translatef(
|
||||||
rl.DrawTexture(il.texture, 0, 0, rl.White)
|
g.Width()/2.0-float32(il.texture.Width)/2.0,
|
||||||
|
g.Width()/2.0-float32(il.texture.Height)/2.0, 0)
|
||||||
|
g.DrawTexture(il.texture, sg.Origin, rl.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (il *ImageLayer) IsDirty() bool {
|
func (il *ImageLayer) IsDirty() bool {
|
||||||
return il.dirty
|
return il.dirty
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestPattern struct {
|
|
||||||
dirty bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tp *TestPattern) Update(ctx *Env) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tp *TestPattern) Draw(ctx *Env) {
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
centerX := float32(ctx.GetGraphicsWidth()) / 2
|
|
||||||
centerY := float32(ctx.GetGraphicsHeight()) / 2
|
|
||||||
|
|
||||||
rl.DrawRectangleRec(rl.Rectangle{X: 0, Y: 0, Width: centerX, Height: centerY}, rl.Red)
|
|
||||||
rl.DrawRectangleRec(rl.Rectangle{X: centerX, Y: 0, Width: centerX, Height: centerY}, rl.Green)
|
|
||||||
rl.DrawRectangleRec(rl.Rectangle{X: 0, Y: centerY, Width: centerX, Height: centerY}, rl.Blue)
|
|
||||||
rl.DrawRectangleRec(rl.Rectangle{X: centerX, Y: centerY, Width: centerX, Height: centerY}, rl.White)
|
|
||||||
|
|
||||||
rl.DrawLine(0, 0, ctx.Graphics.GetGraphicsWidth(), ctx.Graphics.GetGraphicsHeight(), rl.Black)
|
|
||||||
|
|
||||||
rl.PushMatrix()
|
|
||||||
rl.Translatef(centerX, centerY, 0)
|
|
||||||
rl.SetLineWidth(4.0)
|
|
||||||
rl.DrawLine(-10000, 0, 10000, 0, rl.Red)
|
|
||||||
rl.DrawLine(0, -10000, 0, 10000, rl.Green)
|
|
||||||
rl.DrawRectangleLines(-50, -50, 100, 100, rl.Magenta)
|
|
||||||
rl.PopMatrix()
|
|
||||||
|
|
||||||
tp.dirty = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tp *TestPattern) IsDirty() bool {
|
|
||||||
return tp.dirty
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Ports **/
|
/** Ports **/
|
||||||
|
|
||||||
type Ports map[string]Signal
|
type Ports map[string]Signal
|
||||||
|
|||||||
Reference in New Issue
Block a user