refactoring progress
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
"math"
|
||||
"math/rand"
|
||||
sg "github.com/d2fn/sumi/internal/graphics"
|
||||
)
|
||||
|
||||
type ContourLayer struct {
|
||||
@@ -12,12 +13,12 @@ type ContourLayer struct {
|
||||
maxActors uint32
|
||||
actors []*Actor
|
||||
actorIndex uint32
|
||||
actorColor rl.Color
|
||||
actorColor sg.Color
|
||||
loActorAngle float32
|
||||
hiActorAngle float32
|
||||
}
|
||||
|
||||
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color rl.Color, loActorAngle float32, hiActorAngle float32) *ContourLayer {
|
||||
func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color sg.Color, loActorAngle float32, hiActorAngle float32) *ContourLayer {
|
||||
|
||||
maxActors := 200000
|
||||
|
||||
@@ -37,13 +38,13 @@ func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color rl.Color
|
||||
return &layer
|
||||
}
|
||||
|
||||
func (s *ContourLayer) AddActors(color rl.Color, n, sourceWidth, sourceHeight int32) {
|
||||
func (s *ContourLayer) AddActors(color sg.Color, n, sourceWidth, sourceHeight int32) {
|
||||
for range n {
|
||||
x := s.rng.Int31() % sourceWidth
|
||||
y := s.rng.Int31() % sourceHeight
|
||||
newActor :=
|
||||
&Actor{
|
||||
position: rl.Vector2{X: float32(x), Y: float32(y)},
|
||||
position: sg.Point { X: float32(x), Y: float32(y) },
|
||||
field: s.field,
|
||||
stepSize: 1,
|
||||
color: s.actorColor,
|
||||
@@ -55,18 +56,19 @@ func (s *ContourLayer) AddActors(color rl.Color, n, sourceWidth, sourceHeight in
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Update(ctx *RenderCtx) {
|
||||
s.AddActors(s.actorColor, 100, ctx.SourceWidth, ctx.SourceHeight)
|
||||
func (s *ContourLayer) Update(ctx *Env) {
|
||||
s.AddActors(s.actorColor, 100, int32(ctx.Graphics.Layout.Graphics.Width), int32(ctx.Graphics.Layout.Graphics.Height))
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Draw(ctx *RenderCtx) {
|
||||
rl.BeginBlendMode(rl.BlendAdditive)
|
||||
func (s *ContourLayer) Draw(ctx *Env) {
|
||||
g := ctx.Graphics
|
||||
g.BeginAdditiveBlend()
|
||||
for _, actor := range s.actors {
|
||||
if actor != nil {
|
||||
actor.Draw()
|
||||
actor.Draw(ctx)
|
||||
}
|
||||
}
|
||||
rl.EndBlendMode()
|
||||
g.EndBlend()
|
||||
}
|
||||
|
||||
func (s *ContourLayer) IsDirty() bool {
|
||||
@@ -74,40 +76,43 @@ func (s *ContourLayer) IsDirty() bool {
|
||||
}
|
||||
|
||||
type Actor struct {
|
||||
position rl.Vector2
|
||||
position sg.Point
|
||||
field Field
|
||||
stepSize float32
|
||||
color rl.Color
|
||||
color sg.Color
|
||||
loAngle float32
|
||||
hiAngle float32
|
||||
}
|
||||
|
||||
func (a *Actor) Draw() {
|
||||
func (a *Actor) Draw(ctx *Env) {
|
||||
v := a.field.Get(a.position.X, a.position.Y)
|
||||
rad := rl.Remap(v, 0, 1, a.loAngle, a.hiAngle)
|
||||
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)))}
|
||||
rl.DrawLineV(a.position, nextPosition, a.color)
|
||||
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)))}
|
||||
|
||||
g := ctx.Graphics
|
||||
g.SetStrokeWeight(1.0)
|
||||
g.SetStroke(true)
|
||||
g.SetStrokeColor(a.color)
|
||||
g.DrawLine(a.position, nextPosition)
|
||||
//rl.DrawLineV(a.position, nextPosition, a.color)
|
||||
a.position = nextPosition
|
||||
}
|
||||
|
||||
func RandRadialVec(rng *rand.Rand, minRadius float32, maxRadius float32, loAngle float32, hiAngle float32) rl.Vector2 {
|
||||
r := float64(rl.Remap(rng.Float32(), 0, 1, minRadius, maxRadius))
|
||||
deg := float64(rl.Remap(rng.Float32(), 0, 1, loAngle, hiAngle))
|
||||
rad := rl.Deg2rad * deg
|
||||
return rl.Vector2{X: float32(r * math.Cos(rad)), Y: float32(r * math.Sin(rad))}
|
||||
}
|
||||
|
||||
type Worm struct {
|
||||
position rl.Vector2
|
||||
position sg.Point
|
||||
angles []float32
|
||||
angleIndex int
|
||||
stepSize int
|
||||
renderPct float32
|
||||
}
|
||||
|
||||
func (w *Worm) Draw(ctx *RenderCtx) {
|
||||
rl.PushMatrix()
|
||||
rl.Translatef(w.position.X, w.position.Y, 0)
|
||||
func (w *Worm) Draw(ctx *Env) {
|
||||
g := ctx.Graphics
|
||||
g.PushMatrix()
|
||||
g.Translate(w.position)
|
||||
//rl.PushMatrix()
|
||||
//rl.Translatef(w.position.X, w.position.Y, 0)
|
||||
lastAngle := float32(0.0)
|
||||
stepCount := 0
|
||||
nudged := false
|
||||
@@ -117,8 +122,8 @@ func (w *Worm) Draw(ctx *RenderCtx) {
|
||||
deltaAngle := angle - lastAngle
|
||||
if !nudged {
|
||||
rad := float64(deltaAngle * math.Pi / 180.0)
|
||||
nudge := rl.Vector2{X: float32(w.stepSize) * float32(math.Cos(rad)), Y: float32(w.stepSize) * float32(math.Sin(rad))}
|
||||
w.position = rl.Vector2Add(w.position, nudge)
|
||||
nudge := sg.Vec {X: float32(w.stepSize) * float32(math.Cos(rad)), Y: float32(w.stepSize) * float32(math.Sin(rad))}
|
||||
w.position = w.position.Add(nudge)//rl.Vector2Add(w.position, nudge)
|
||||
nudged = true
|
||||
}
|
||||
rl.Rotatef(deltaAngle, 0, 0, 1)
|
||||
@@ -130,6 +135,6 @@ func (w *Worm) Draw(ctx *RenderCtx) {
|
||||
break
|
||||
}
|
||||
}
|
||||
rl.PopMatrix()
|
||||
g.PopMatrix()
|
||||
w.angleIndex = (w.angleIndex + 1) % len(w.angles)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user