more code cleanup
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
sg "github.com/d2fn/sumi/internal/graphics"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
"image/color"
|
||||
"math"
|
||||
"math/rand"
|
||||
sg "github.com/d2fn/sumi/internal/graphics"
|
||||
)
|
||||
|
||||
type ContourLayer struct {
|
||||
@@ -13,12 +14,12 @@ type ContourLayer struct {
|
||||
maxActors uint32
|
||||
actors []*Actor
|
||||
actorIndex uint32
|
||||
actorColor sg.Color
|
||||
actorColor color.RGBA
|
||||
loActorAngle 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
|
||||
|
||||
@@ -38,13 +39,13 @@ func NewContourLayer(sketch *Sketch, rng *rand.Rand, field Field, color sg.Color
|
||||
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 {
|
||||
x := s.rng.Int31() % sourceWidth
|
||||
y := s.rng.Int31() % sourceHeight
|
||||
newActor :=
|
||||
&Actor{
|
||||
position: sg.Point { X: float32(x), Y: float32(y) },
|
||||
position: sg.Point{X: float32(x), Y: float32(y)},
|
||||
field: s.field,
|
||||
stepSize: 1,
|
||||
color: s.actorColor,
|
||||
@@ -56,16 +57,15 @@ func (s *ContourLayer) AddActors(color sg.Color, n, sourceWidth, sourceHeight in
|
||||
}
|
||||
}
|
||||
|
||||
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) Update(env *Env, g *sg.Graphics) {
|
||||
s.AddActors(s.actorColor, 100, g.WidthInt32(), g.HeightInt32())
|
||||
}
|
||||
|
||||
func (s *ContourLayer) Draw(ctx *Env) {
|
||||
g := ctx.Graphics
|
||||
func (s *ContourLayer) Draw(env *Env, g *sg.Graphics) {
|
||||
g.BeginAdditiveBlend()
|
||||
for _, actor := range s.actors {
|
||||
if actor != nil {
|
||||
actor.Draw(ctx)
|
||||
actor.Draw(env, g)
|
||||
}
|
||||
}
|
||||
g.EndBlend()
|
||||
@@ -79,18 +79,17 @@ type Actor struct {
|
||||
position sg.Point
|
||||
field Field
|
||||
stepSize float32
|
||||
color sg.Color
|
||||
color color.RGBA
|
||||
loAngle 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)
|
||||
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)))}
|
||||
|
||||
g := ctx.Graphics
|
||||
g.SetStrokeWeight(1.0)
|
||||
g.SetStroke(true)
|
||||
g.SetStrokeColor(a.color)
|
||||
@@ -107,8 +106,7 @@ type Worm struct {
|
||||
renderPct float32
|
||||
}
|
||||
|
||||
func (w *Worm) Draw(ctx *Env) {
|
||||
g := ctx.Graphics
|
||||
func (w *Worm) Draw(env *Env, g *sg.Graphics) {
|
||||
g.PushMatrix()
|
||||
g.Translate(w.position)
|
||||
//rl.PushMatrix()
|
||||
@@ -122,8 +120,8 @@ func (w *Worm) Draw(ctx *Env) {
|
||||
deltaAngle := angle - lastAngle
|
||||
if !nudged {
|
||||
rad := float64(deltaAngle * math.Pi / 180.0)
|
||||
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)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user