You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.4 KiB
68 lines
1.4 KiB
defmodule Tetris.Points do |
|
|
|
def move_to_location(points, {x,y}) do |
|
Enum.map(points,fn {dx, dy} -> {dx + x, dy + y} end ) |
|
end |
|
|
|
def transpose(points) do |
|
points |
|
|> Enum.map( fn {x,y} -> {y,x} end ) |
|
end |
|
def mirror(points) do |
|
points |
|
|> Enum.map( fn{x,y} -> {5-x,y} end ) |
|
end |
|
def mirror(points, false), do: points |
|
def mirror(points, true), do: mirror points |
|
|
|
def flip(points) do |
|
points |
|
|> Enum.map( fn{x,y} -> {x,5-y} end ) |
|
end |
|
|
|
def rotate_90(points) do |
|
#by 90 degrees clockwise |
|
points |
|
|> transpose |
|
|> mirror |
|
end |
|
|
|
def rotate(points, 0), do: points |
|
def rotate(points, degrees) do |
|
rotate( |
|
rotate_90(points), |
|
degrees - 90 |
|
) |
|
end |
|
|
|
def with_colour(points, colour) do |
|
Enum.map(points,fn point -> add_colour(point, colour) end) |
|
end |
|
|
|
defp add_colour({_x, _y, _c} = point, _colour), do: point |
|
defp add_colour({x,y}, colour), do: {x,y,colour} |
|
|
|
|
|
|
|
#🔴 |
|
#⬜ |
|
#🟥 |
|
def to_string(points) do |
|
map = |
|
points |
|
|> Enum.map(fn key -> {key, "🟥"} end) |
|
|> Map.new() |
|
|
|
for y <- (1 .. 4), x <- (1 .. 4) do |
|
Map.get(map,{x,y},"⬜") |
|
end |
|
|> Enum.chunk_every(4) |
|
|> Enum.map(&Enum.join/1) |
|
|> Enum.join("\n") |
|
end |
|
|
|
def print(points) do |
|
IO.puts __MODULE__.to_string(points) |
|
points |
|
end |
|
end
|
|
|