Rewrite math and programmatic logic, and readme accordingly.#16
Open
curiosdevcookie wants to merge 1 commit intomainfrom
Open
Rewrite math and programmatic logic, and readme accordingly.#16curiosdevcookie wants to merge 1 commit intomainfrom
curiosdevcookie wants to merge 1 commit intomainfrom
Conversation
resterle
reviewed
Apr 4, 2023
resterle
reviewed
Apr 4, 2023
resterle
reviewed
Apr 4, 2023
| end | ||
| end | ||
|
|
||
| def patch_together() do |
Collaborator
There was a problem hiding this comment.
def paint() do
def draw() do
Collaborator
There was a problem hiding this comment.
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)
Collaborator
Author
There was a problem hiding this comment.
I don't understand what you mean.
Collaborator
There was a problem hiding this comment.
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()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.