Graphics Fixes

This commit is contained in:
Sarah Jamie Lewis 2019-08-10 16:02:20 -07:00
parent f222cf86b5
commit b77b03f570
4 changed files with 71 additions and 8 deletions

View File

@ -12,14 +12,26 @@ type Slush struct {
func (sm *Slush) Setup(env *core.Environment, t *core.Turtle) {
sm.color = rand.Intn(2) + 1
if sm.color !=1 && sm.color !=2 {
panic("wrong color")
}
}
func (sm *Slush) Run(env *core.Environment, t *core.Turtle) {
t.Wiggle()
if t.Near(env, 1,2, "1") {
sm.color = 1
} else if t.Near(env, 1,2, "2") {
sm.color = 2
notChanged := true
threshold := float32(1.0)
for notChanged {
notChanged = false
if t.Near(env, 1, threshold, "1") {
sm.color = 1
notChanged = true
}
if t.Near(env, 1, threshold, "2") {
sm.color = 2
notChanged = true
}
threshold+=0.01
}
t.Step(env)
t.Drop(env, 1, strconv.Itoa(sm.color))

40
actors/snowball.go Normal file
View File

@ -0,0 +1,40 @@
package actors
import (
"git.openprivacy.ca/sarah/microworlds/core"
"math/rand"
"strconv"
)
type Snowball struct {
color int
sureness int
}
func (sm *Snowball) Setup(env *core.Environment, t *core.Turtle) {
sm.color = rand.Intn(2) + 1
if sm.color !=1 && sm.color !=2 {
panic("wrong color")
}
sm.sureness = 0
}
func (sm *Snowball) Run(env *core.Environment, t *core.Turtle) {
t.Wiggle()
if sm.color == 1 && t.Near(env, 1, float32(sm.sureness), "1") {
sm.sureness++
} else if sm.color == 1 && t.Near(env, 1, float32(sm.sureness), "2") {
sm.sureness = 0
sm.color = 2
} else if sm.color == 2 && t.Near(env, 1, float32(sm.sureness), "2") {
sm.sureness++
} else if sm.color == 2 && t.Near(env, 1, float32(sm.sureness), "1") {
sm.sureness = 0
sm.color = 1
}
t.Step(env)
t.Drop(env, 1, strconv.Itoa(sm.color))
}

View File

@ -64,8 +64,11 @@ func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) {
for name, color := range g.colorMap {
amount := math.Min(float64(env.Sniff(name, x, y)), 255)
if amount > 2 {
amount = 2
}
if amount > 0 {
// TODO explictly define this scale
scaledamountRed := uint8(float64(color[0]) * (amount/2))
scaledamountGreen := uint8(float64(color[1]) * (amount/2))
scaledamountBlue := uint8(float64(color[2]) * (amount/2))
@ -76,7 +79,7 @@ func (g *Graphics) Render(env *core.Environment, turtles []*core.Turtle) {
}
g.renderer.SetDrawColor(uint8(scaledamountRedTotal/len(g.colorMap)),uint8(scaledamountGreenTotal/len(g.colorMap)),uint8(scaledamountBlueTotal/len(g.colorMap)), uint8(0xF0))
g.renderer.DrawPoint(int32(x), int32(y))
g.DrawTileColor(int32(x), int32(y))
if env.HasValue(x, y) {
g.renderer.SetDrawColor(255, 255, 255, uint8(255))

12
main.go
View File

@ -97,8 +97,16 @@ func main() {
}
env.InitPheromone("1")
env.InitPheromone("2")
g.ColorPheromone("1", [4]uint8{0x00, 0xFF, 0x00, 0x00})
g.ColorPheromone("2", [4]uint8{0x00, 0, 0xFF, 0x00})
g.ColorPheromone("1", [4]uint8{0x80, 0xFF, 0x00, 0x00})
g.ColorPheromone("2", [4]uint8{0xFF, 0, 0xFF, 0x00})
case "snowball":
for i := 0; i < *numTurtles; i++ {
turtles[i] = core.NewTurtle(env, &actors.Snowball{})
}
env.InitPheromone("1")
env.InitPheromone("2")
g.ColorPheromone("1", [4]uint8{0x00, 0xFF, 0xFF, 0x00})
g.ColorPheromone("2", [4]uint8{0xFF, 0xFF, 0x00, 0x00})
case "flocking":
for i := 0; i < *numTurtles; i++ {
turtles[i] = core.NewTurtle(env, &actors.Flocking{SniffDistance: 1})