Loading draw/spaceinvaders/spaceinvaders.go +60 −62 Original line number Diff line number Diff line package spaceinvaders import ( "fmt" "image/color" "log" "math" "net/http" Loading @@ -15,7 +13,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size canvas := svg.New(w) canvas.Start(size, size) invader := newInvader(key) log.Println(fmt.Sprintf("%+v\n", invader)) // log.Println(fmt.Sprintf("%+v\n", invader)) // for debug squares := 11 quadrantSize := size / squares middle := math.Ceil(float64(squares) / float64(2)) Loading @@ -29,7 +27,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size fill := draw.FillFromRGBA(colors[0]) if _, ok := colorMap[xQ]; !ok { if float64(xQ) < middle { colorMap[xQ] = draw.PickColor(key, colors, xQ+2*yQ) colorMap[xQ] = draw.PickColor(key, colors[1:], xQ+2*yQ) } else if xQ < squares { colorMap[xQ] = colorMap[squares-xQ-1] } else { Loading @@ -42,15 +40,15 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == highBodyIndex { if invader.eyes == 2 { if xQ > 4 && xQ < 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ > 3 && xQ < 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ > 3 && xQ < 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } if invader.eyes > 1 { Loading @@ -62,15 +60,15 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == highBodyIndex-1 && invader.anthenaSize == 2 { if invader.anthenas == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 2 { if xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 3 { if xQ == 2 || xQ == 5 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -78,15 +76,15 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == highBodyIndex { if invader.anthenas == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 2 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 3 { if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -94,19 +92,19 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 3 { // pre frontal lobe :p if invader.eyes == 1 { if xQ >= 5 && xQ <= 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 2 { if xQ >= 4 && xQ <= 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ >= 3 && xQ <= 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ >= 3 && xQ <= 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -114,19 +112,19 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 4 { // frontal lobe if invader.eyes == 1 { if xQ >= 4 && xQ <= 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 2 { if xQ >= 3 && xQ <= 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ >= 2 && xQ <= 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ >= 2 && xQ <= 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -135,7 +133,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size leftOver := squares - invader.length if invader.arms > 0 { if xQ == (leftOver/2) || xQ == squares-1-leftOver/2 || xQ == (leftOver/2)-1 || xQ == (squares-leftOver/2) { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -144,12 +142,12 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if yQ == 4 && invader.armsUp && invader.armSize == 3 { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } if yQ == 6 && !invader.armsUp && invader.armSize == 3 { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -158,27 +156,27 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 5 { // eyes if invader.eyes == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 2 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ == 5 || xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -186,7 +184,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 6 { // length of body leftOver := squares - invader.length if xQ > (leftOver/2)-1 && xQ < squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -196,7 +194,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == lowBodyIndex { leftOver := squares - invader.length if xQ > (leftOver/2) && xQ < (squares-1-leftOver/2) { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -208,7 +206,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == lowBodyIndex { leftOver := squares - invader.length if xQ > (leftOver/2)+1 && xQ < (squares-2-leftOver/2) { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -220,11 +218,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - (leftOver / 2) - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-2 || xQ == squares-leftOver/2+1 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -237,11 +235,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - (leftOver / 2) - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -258,11 +256,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - leftOver/2 - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -274,11 +272,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - leftOver/2 - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -290,11 +288,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - leftOver/2 - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-2 || xQ == squares-leftOver/2+1 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -304,34 +302,34 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.legs%2 == 0 { if invader.legs == 2 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 4 { if invader.length >= 6 { if invader.height >= 7 { if yQ == lowBodyIndex { if xQ == 3 || xQ == 4 || xQ == 6 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else { if yQ == lowBodyIndex { if xQ == 3 || xQ == 5 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -339,27 +337,27 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size } else { if invader.legs == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 3 { if invader.length > 5 { if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if yQ == lowBodyIndex { if xQ == 4 || xQ == 5 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } } else if invader.legs == 5 { if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -369,32 +367,32 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.legs%2 == 0 { if invader.legs == 2 { if xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 4 { if xQ == 1 || xQ == 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else { if invader.legs == 1 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 3 { if invader.length > 5 { if xQ == 2 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else if invader.legs == 5 { if xQ == 0 || xQ == 10 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading Loading
draw/spaceinvaders/spaceinvaders.go +60 −62 Original line number Diff line number Diff line package spaceinvaders import ( "fmt" "image/color" "log" "math" "net/http" Loading @@ -15,7 +13,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size canvas := svg.New(w) canvas.Start(size, size) invader := newInvader(key) log.Println(fmt.Sprintf("%+v\n", invader)) // log.Println(fmt.Sprintf("%+v\n", invader)) // for debug squares := 11 quadrantSize := size / squares middle := math.Ceil(float64(squares) / float64(2)) Loading @@ -29,7 +27,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size fill := draw.FillFromRGBA(colors[0]) if _, ok := colorMap[xQ]; !ok { if float64(xQ) < middle { colorMap[xQ] = draw.PickColor(key, colors, xQ+2*yQ) colorMap[xQ] = draw.PickColor(key, colors[1:], xQ+2*yQ) } else if xQ < squares { colorMap[xQ] = colorMap[squares-xQ-1] } else { Loading @@ -42,15 +40,15 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == highBodyIndex { if invader.eyes == 2 { if xQ > 4 && xQ < 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ > 3 && xQ < 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ > 3 && xQ < 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } if invader.eyes > 1 { Loading @@ -62,15 +60,15 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == highBodyIndex-1 && invader.anthenaSize == 2 { if invader.anthenas == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 2 { if xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 3 { if xQ == 2 || xQ == 5 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -78,15 +76,15 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == highBodyIndex { if invader.anthenas == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 2 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.anthenas == 3 { if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -94,19 +92,19 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 3 { // pre frontal lobe :p if invader.eyes == 1 { if xQ >= 5 && xQ <= 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 2 { if xQ >= 4 && xQ <= 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ >= 3 && xQ <= 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ >= 3 && xQ <= 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -114,19 +112,19 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 4 { // frontal lobe if invader.eyes == 1 { if xQ >= 4 && xQ <= 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 2 { if xQ >= 3 && xQ <= 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ >= 2 && xQ <= 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ >= 2 && xQ <= 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -135,7 +133,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size leftOver := squares - invader.length if invader.arms > 0 { if xQ == (leftOver/2) || xQ == squares-1-leftOver/2 || xQ == (leftOver/2)-1 || xQ == (squares-leftOver/2) { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -144,12 +142,12 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if yQ == 4 && invader.armsUp && invader.armSize == 3 { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } if yQ == 6 && !invader.armsUp && invader.armSize == 3 { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -158,27 +156,27 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 5 { // eyes if invader.eyes == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 2 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 3 { if xQ == 5 || xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.eyes == 4 { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[0]) fill = draw.FillFromRGBA(colors[0]) //... } else if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -186,7 +184,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == 6 { // length of body leftOver := squares - invader.length if xQ > (leftOver/2)-1 && xQ < squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -196,7 +194,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == lowBodyIndex { leftOver := squares - invader.length if xQ > (leftOver/2) && xQ < (squares-1-leftOver/2) { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -208,7 +206,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if yQ == lowBodyIndex { leftOver := squares - invader.length if xQ > (leftOver/2)+1 && xQ < (squares-2-leftOver/2) { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -220,11 +218,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - (leftOver / 2) - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-2 || xQ == squares-leftOver/2+1 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } Loading @@ -237,11 +235,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - (leftOver / 2) - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -258,11 +256,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - leftOver/2 - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -274,11 +272,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - leftOver/2 - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -290,11 +288,11 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.arms > 0 { if (squares - leftOver/2 - (leftOver / 2) - 1) >= invader.length { if xQ == (leftOver/2)-2 || xQ == squares-leftOver/2+1 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -304,34 +302,34 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.legs%2 == 0 { if invader.legs == 2 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 4 { if invader.length >= 6 { if invader.height >= 7 { if yQ == lowBodyIndex { if xQ == 3 || xQ == 4 || xQ == 6 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else { if yQ == lowBodyIndex { if xQ == 3 || xQ == 5 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -339,27 +337,27 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size } else { if invader.legs == 1 { if xQ == 5 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 3 { if invader.length > 5 { if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if yQ == lowBodyIndex { if xQ == 4 || xQ == 5 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 3 || xQ == 5 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } } else if invader.legs == 5 { if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading @@ -369,32 +367,32 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size if invader.legs%2 == 0 { if invader.legs == 2 { if xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 4 { if xQ == 1 || xQ == 9 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else { if invader.legs == 1 { if xQ == 4 || xQ == 6 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else if invader.legs == 3 { if invader.length > 5 { if xQ == 2 || xQ == 8 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } else { if xQ == 3 || xQ == 7 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } else if invader.legs == 5 { if xQ == 0 || xQ == 10 { fill = draw.FillFromRGBA(colors[1]) fill = draw.FillFromRGBA(colorMap[xQ]) } } } Loading