-
Notifications
You must be signed in to change notification settings - Fork 3
Rewrite math and programmatic logic, and readme accordingly. #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| end | ||
| end | ||
|
|
||
| def patch_together() do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def paint() do
def draw() do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe just let the paint or draw function have all its inputs as parameters.
draw("Java", &inside_egg?/2)
draw("Elixir", &inside_heart?/2)
draw("golang", &inside_bunny?/2)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how i would have done it. Just as a "Denksanstoß".
defmodule AsciiArt do
@columns 60
@rows 36
@row_offset -13
def draw_shape(word, shape_fun) do
make_cords()
|> offset_every_x(-div(@columns, 2))
|> offset_every_y(@row_offset)
|> append_visibility(shape_fun)
|> to_characters("#{word} ")
|> create_rows()
|> Enum.join("\n")
end
defp make_cords() do
0..(@columns*@rows)
|> Enum.map(fn a -> {rem(a, @columns), div(a, @columns)} end)
|> Enum.reverse()
end
defp offset_every_x(cords, offset) do
Enum.map(cords, &offsetX(&1, offset))
end
defp offsetX({x, y}, offset) do
{x+offset, y}
end
defp offset_every_y(cords, offset) do
Enum.map(cords, &offsetY(&1, offset))
end
defp offsetY({x, y}, offset) do
{x, y+offset}
end
defp append_visibility(cords, shape_fun) do
Enum.map(cords, fn {x, y} = c -> {x, y, shape_fun.(c)} end)
end
defp to_characters(cords, word) do
Enum.map(cords, &character_at(&1, word))
end
defp character_at({_x, _y, false}, _word), do: " "
defp character_at({x, y, true}, word) do
index = rem(x - y, String.length(word))
String.at(word, index)
end
defp create_rows(characters) do
characters
|> Enum.chunk_every(@columns)
|> Enum.map(&Enum.join/1)
end
endAnd then you can do:
inside_egg? = fn
{x, y} when y > 0 -> :math.pow(x / 2.5, 2) + :math.pow(y / 2, 2) <= 100
{x, y} -> :math.pow(x / 2.5, 2) + :math.pow(y / 1, 2) <= 100
end
AsciiArt.draw_shape("Java", inside_egg?)
|> Kino.Markdown.new()or:
inside_heart? = fn {x, y} ->
:math.pow(:math.pow(x * 0.05, 2) + :math.pow(y * 0.1, 2) - 1, 3) -
:math.pow(x * 0.05, 2) * :math.pow(y * 0.1, 3) <= 0
end
AsciiArt.draw_shape("Elixir", inside_heart?)
|> Kino.Markdown.new()
No description provided.