Commit 725f2b35 authored by santiaago's avatar santiaago
Browse files

handle impact of colors theme ordering in space invaders controller and draw pkg

parent a0df588b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ func SpaceInvaders(w http.ResponseWriter, r *http.Request) {
			colors = append(colors, colorMap["base"]...)
		}
	} else {
		colors = append(colors, fg, bg)
		colors = append(colors, bg, fg)
	}

	size := extract.Size(r)
+59 −59
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size

		for xQ := 0; xQ < squares; xQ++ {
			x := xQ * quadrantSize
			fill := draw.FillFromRGBA(colors[1])
			fill := draw.FillFromRGBA(colors[0])
			if _, ok := colorMap[xQ]; !ok {
				if float64(xQ) < middle {
					colorMap[xQ] = draw.PickColor(key, colors, xQ+2*yQ)
@@ -42,15 +42,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else if invader.eyes == 3 {
						if xQ > 3 && xQ < 7 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else if invader.eyes == 4 {
						if xQ > 3 && xQ < 8 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
					if invader.eyes > 1 {
@@ -62,15 +62,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.anthenas == 2 {
					if xQ == 3 || xQ == 7 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.anthenas == 3 {
					if xQ == 2 || xQ == 5 || xQ == 8 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				}
			}
@@ -78,15 +78,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.anthenas == 2 {
					if xQ == 4 || xQ == 6 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.anthenas == 3 {
					if xQ == 3 || xQ == 5 || xQ == 7 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				}
			}
@@ -94,19 +94,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 2 {
					if xQ >= 4 && xQ <= 6 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 3 {
					if xQ >= 3 && xQ <= 7 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 4 {
					if xQ >= 3 && xQ <= 8 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				}
			}
@@ -114,19 +114,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 2 {
					if xQ >= 3 && xQ <= 7 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 3 {
					if xQ >= 2 && xQ <= 8 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 4 {
					if xQ >= 2 && xQ <= 9 {
						fill = draw.FillFromRGBA(colors[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				}
			}
@@ -135,7 +135,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}
				}
			}
@@ -144,12 +144,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
					if yQ == 6 && !invader.armsUp && invader.armSize == 3 {
						if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}
@@ -158,27 +158,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[1])
					} else if xQ == 4 || xQ == 6 {
						fill = draw.FillFromRGBA(colors[0])
					} else if xQ == 4 || xQ == 6 {
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 2 {
					if xQ == 4 || xQ == 6 {
						fill = draw.FillFromRGBA(colors[1])
					} else if xQ == 3 || xQ == 5 || xQ == 7 {
						fill = draw.FillFromRGBA(colors[0])
					} else if xQ == 3 || xQ == 5 || xQ == 7 {
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 3 {
					if xQ == 5 || xQ == 3 || xQ == 7 {
						fill = draw.FillFromRGBA(colors[1])
					} else if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 {
						fill = draw.FillFromRGBA(colors[0])
					} else if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 {
						fill = draw.FillFromRGBA(colors[1])
					}
				} else if invader.eyes == 4 {
					if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 {
						fill = draw.FillFromRGBA(colors[1])
					} else if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 {
						fill = draw.FillFromRGBA(colors[0])
					} else if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 {
						fill = draw.FillFromRGBA(colors[1])
					}
				}
			}
@@ -186,7 +186,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[0])
					fill = draw.FillFromRGBA(colors[1])
				}
			}

@@ -196,7 +196,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}

				}
@@ -208,7 +208,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[0])
						fill = draw.FillFromRGBA(colors[1])
					}

				}
@@ -220,11 +220,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else {
						if xQ == (leftOver/2)-1 || xQ == squares-leftOver/2 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}

					}
@@ -237,11 +237,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else {
						if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}
@@ -258,11 +258,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else {
						if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}
@@ -274,11 +274,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else {
						if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}
@@ -290,11 +290,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else {
						if xQ == (leftOver/2)-2 || xQ == squares+1-leftOver/2 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}
@@ -304,34 +304,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} 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[0])
										fill = draw.FillFromRGBA(colors[1])
									}
								} else {
									if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 {
										fill = draw.FillFromRGBA(colors[0])
										fill = draw.FillFromRGBA(colors[1])
									}
								}
							} else {
								if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 {
									fill = draw.FillFromRGBA(colors[0])
									fill = draw.FillFromRGBA(colors[1])
								}
							}
						} else {
							if yQ == lowBodyIndex {
								if xQ == 3 || xQ == 5 || xQ == 5 || xQ == 7 {
									fill = draw.FillFromRGBA(colors[0])
									fill = draw.FillFromRGBA(colors[1])
								}

							} else {
								if xQ == 2 || xQ == 4 || xQ == 6 || xQ == 8 {
									fill = draw.FillFromRGBA(colors[0])
									fill = draw.FillFromRGBA(colors[1])
								}
							}
						}
@@ -339,27 +339,27 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size
				} else {
					if invader.legs == 1 {
						if xQ == 5 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else if invader.legs == 3 {
						if invader.length > 5 {
							if xQ == 3 || xQ == 5 || xQ == 7 {
								fill = draw.FillFromRGBA(colors[0])
								fill = draw.FillFromRGBA(colors[1])
							}
						} else {
							if yQ == lowBodyIndex {
								if xQ == 4 || xQ == 5 || xQ == 6 {
									fill = draw.FillFromRGBA(colors[0])
									fill = draw.FillFromRGBA(colors[1])
								}
							} else {
								if xQ == 3 || xQ == 5 || xQ == 7 {
									fill = draw.FillFromRGBA(colors[0])
									fill = draw.FillFromRGBA(colors[1])
								}
							}
						}
					} else if invader.legs == 5 {
						if xQ == 1 || xQ == 3 || xQ == 5 || xQ == 7 || xQ == 9 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}
@@ -369,32 +369,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[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else if invader.legs == 4 {
						if xQ == 1 || xQ == 9 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				} else {
					if invader.legs == 1 {
						if xQ == 4 || xQ == 6 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					} else if invader.legs == 3 {
						if invader.length > 5 {
							if xQ == 2 || xQ == 8 {
								fill = draw.FillFromRGBA(colors[0])
								fill = draw.FillFromRGBA(colors[1])
							}
						} else {
							if xQ == 3 || xQ == 7 {
								fill = draw.FillFromRGBA(colors[0])
								fill = draw.FillFromRGBA(colors[1])
							}
						}

					} else if invader.legs == 5 {
						if xQ == 0 || xQ == 10 {
							fill = draw.FillFromRGBA(colors[0])
							fill = draw.FillFromRGBA(colors[1])
						}
					}
				}