-
Notifications
You must be signed in to change notification settings - Fork 7
feat: improve seeds #568
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
Merged
Merged
feat: improve seeds #568
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e22a256
feat: activitys and announcements english description and titles
GuilhermePSF ce6290d
fix: placeholder information for orgs with missing attributes
GuilhermePSF 5e92461
feat: text dependent of the organzation and/or activity in portuguese…
GuilhermePSF 3efe979
feat: add github like default icon generator
GuilhermePSF f8d20cd
feat: new icon uploader
GuilhermePSF d41cf09
format
GuilhermePSF fc663ad
fix: improve code readability
GuilhermePSF 094befc
docs: documentation for module icon
GuilhermePSF 8ac3e0a
docs: remove documentation from anonymous functions
GuilhermePSF 651a588
refactor: use join with 3 arity instead of 3 for efficiency
GuilhermePSF 54fd52a
refactor: rename file and module remove non needed lines
GuilhermePSF 94090a5
fix: outdated alias and function calls
GuilhermePSF 6b6a9ef
fix: remove non needed documentation
GuilhermePSF 69e3171
refactor: make avatar generator support multiple entities
GuilhermePSF 8eb836b
format
GuilhermePSF 94d5903
Merge branch 'develop' into gf/improve-seeds
GuilhermePSF 768c44d
feat: implement options for function generate_avatar
GuilhermePSF 3930f11
feat: update generate_avatar calls to match new options
GuilhermePSF e2e4b6f
fix: divide function generate_avatar into seperate function to deal w…
GuilhermePSF 7fe4bf7
chore: format
GuilhermePSF cc0da31
fix: typo
GuilhermePSF ff73a3e
chore: rename function
GuilhermePSF 74fd425
feat: implement pattern matching
GuilhermePSF f2b9e42
feat: new option handling
GuilhermePSF d7b695d
chore: format
GuilhermePSF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| defmodule Atomic.GenerateAvatar do | ||
| @moduledoc """ | ||
| A module for generating unique, GitHub-style avatars for organizations. | ||
| """ | ||
|
|
||
| import Phoenix.HTML | ||
|
|
||
| @grid_size 5 | ||
| @cell_size 50 | ||
|
|
||
| def generate_avatar(seed, output_type) do | ||
| hash = :crypto.hash(:sha256, seed) |> :binary.bin_to_list() | ||
| color = Enum.take(hash, 3) | ||
| grid = build_grid(hash) | ||
| svg = draw(grid, color) | ||
|
|
||
| handle_output(svg, output_type) | ||
| end | ||
|
|
||
| defp handle_output(svg, output) when is_binary(output), do: File.write(output, svg) | ||
|
|
||
| defp handle_output(svg, :svg), do: svg | ||
| defp handle_output(svg, :blob), do: :erlang.term_to_binary(svg) | ||
| defp handle_output(svg, :html), do: raw(svg) | ||
|
|
||
| defp handle_output(_svg, invalid) do | ||
| raise ArgumentError, | ||
| "Invalid output type: #{inspect(invalid)}. Expected one of :svg, :blob, :html, or a file path string." | ||
| end | ||
|
|
||
| defp build_grid(hash) do | ||
| hash | ||
| |> Enum.chunk_every(@grid_size, @grid_size, :discard) | ||
| |> Enum.map(&mirror/1) | ||
| |> List.flatten() | ||
| end | ||
|
|
||
| defp mirror([a, b, c | _]), do: [a, b, c, b, a] | ||
|
|
||
| defp draw(grid, [r, g, b]) do | ||
| header = """ | ||
| <svg width="#{@grid_size * @cell_size}" height="#{@grid_size * @cell_size}" xmlns="http://www.w3.org/2000/svg"> | ||
| """ | ||
|
|
||
| footer = "</svg>" | ||
|
|
||
| body = | ||
| Enum.map_join( | ||
| grid | ||
| |> Enum.with_index() | ||
| |> Enum.filter(fn {val, _} -> rem(val, 2) == 0 end), | ||
| "\n", | ||
| fn {_val, index} -> | ||
| x = rem(index, @grid_size) * @cell_size | ||
| y = div(index, @grid_size) * @cell_size | ||
|
|
||
| "<rect x='#{x}' y='#{y}' width='#{@cell_size}' height='#{@cell_size}' fill='rgb(#{r},#{g},#{b})' />" | ||
| end | ||
| ) | ||
|
|
||
| header <> body <> footer | ||
| end | ||
| end | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.