├── .formatter.exs ├── .gitignore ├── README.md ├── assets ├── .babelrc ├── css │ ├── app.scss │ ├── my_app.css │ └── phoenix.css ├── js │ └── app.js ├── package-lock.json ├── package.json ├── static │ ├── favicon.ico │ ├── images │ │ └── phoenix.png │ └── robots.txt └── webpack.config.js ├── circles1.jpg ├── circles2.jpg ├── config ├── config.exs ├── dev.exs ├── prod.exs ├── prod.secret.exs └── test.exs ├── lib ├── poisson_colors.ex ├── poisson_colors │ ├── application.ex │ └── style.ex ├── poisson_colors_web.ex └── poisson_colors_web │ ├── channels │ └── user_socket.ex │ ├── endpoint.ex │ ├── gettext.ex │ ├── live │ ├── circles_live.ex │ ├── circles_live.html.leex │ ├── page_live.ex │ └── page_live.html.leex │ ├── router.ex │ ├── telemetry.ex │ ├── templates │ ├── layout │ │ ├── app.html.eex │ │ ├── live.html.leex │ │ ├── live_fullscreen.html.leex │ │ └── root.html.leex │ └── svg_template.eex │ └── views │ ├── error_helpers.ex │ ├── error_view.ex │ └── layout_view.ex ├── mix.exs ├── mix.lock ├── priv ├── gettext │ ├── en │ │ └── LC_MESSAGES │ │ │ └── errors.po │ └── errors.pot └── output │ └── .output_dir └── test ├── poisson_colors_web └── views │ ├── error_view_test.exs │ └── layout_view_test.exs ├── support ├── channel_case.ex └── conn_case.ex └── test_helper.exs /.formatter.exs: -------------------------------------------------------------------------------- 1 | [ 2 | import_deps: [:phoenix], 3 | inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"] 4 | ] 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | # Ignore package tarball (built via "mix hex.build"). 23 | poisson_colors-*.tar 24 | 25 | # If NPM crashes, it generates a log, let's ignore it too. 26 | npm-debug.log 27 | 28 | # The directory NPM downloads your dependencies sources to. 29 | /assets/node_modules/ 30 | 31 | # Since we are building assets from assets/, 32 | # we ignore priv/static. You may want to comment 33 | # this depending on your deployment strategy. 34 | /priv/static/ 35 | 36 | # Output 37 | /priv/output/*.jpg 38 | /priv/output/*.svg 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Generating graphics using Elixir, Phoenix LiveView and SVG 2 | 3 | To start your Phoenix server: 4 | 5 | * Install dependencies with `mix deps.get` 6 | * Install Node.js dependencies with `npm install` inside the `assets` directory 7 | * Start Phoenix endpoint with `mix phx.server` 8 | 9 | Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. 10 | 11 | ## The App 12 | 13 | The app **renders circles** according to settings (minimum distance of circles, color, opacity, size). You can even **save the final image as JPG** (and maybe use it 14 | as a wallpaper ;-)). 15 | 16 | ![Poisson circles](circles1.jpg "circles") 17 | 18 | ## About building this app 19 | 20 | ### It's a Phoenix LiveView project 21 | 22 | New project is created using [Mix](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html): 23 | 24 | `mix phx.new poisson_colors --no-ecto --live` 25 | 26 | ### Poisson disc sampling 27 | 28 | Circles' positions are calculated using 29 | [Poisson disc sampling algorithm](https://github.com/miladamilli/poisson_disc_sampling) 30 | (even random distribution). 31 | 32 | ### UI & updating settings 33 | 34 | Settings are updated using [LiveView](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html)'s 35 | _phx-change_ form event, for example: 36 | 37 | `
` 38 | 39 | and _handle_event_ callback: 40 | 41 | `def handle_event("color", color, socket) do` 42 | 43 | Socket is then updated and graphics regenerated according to the new settings: 44 | 45 | `{:noreply, assign(socket, settings: settings, objects: re_generate_objects(socket.assigns.objects, settings))}` 46 | 47 | ### SVG 48 | 49 | Each circle has its style, for example: 50 | 51 | `%{radius: 53, hue: 329, saturation: 72, lightness: 60, opacity: 0.8}` 52 | 53 | Circles are rendered as SVG elements into `.html.leex` template 54 | 55 | ``` 56 | <%= for object <- @objects do %> 57 | 61 | <% end %> 62 | ``` 63 | 64 | ### Exporting images to JPG 65 | 66 | At first, graphics is exported to a SVG file using [EEx.eval_file](https://hexdocs.pm/eex/EEx.html#eval_file/3) and `.eex` template. 67 | 68 | ``` 69 | EEx.eval_file(@export_template, 70 | objects: socket.assigns.objects, 71 | canvas_w: socket.assigns.canvas_w, 72 | canvas_h: socket.assigns.canvas_h, 73 | background: socket.assigns.background 74 | ) 75 | ``` 76 | 77 | SVG file is then converted to a JPG using ImageMagick's [convert](https://imagemagick.org/script/convert.php) function. (For this to work you need to have ImageMagick installed.) 78 | 79 | `System.cmd("convert", [file <> ".svg", file <> ".jpg"])` 80 | 81 | ![Poisson circles](circles2.jpg "circles") 82 | -------------------------------------------------------------------------------- /assets/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /assets/css/app.scss: -------------------------------------------------------------------------------- 1 | /* This file is for your main application css. */ 2 | @import "./phoenix.css"; 3 | @import "../node_modules/nprogress/nprogress.css"; 4 | @import "./my_app.css"; 5 | 6 | /* LiveView specific classes for your customizations */ 7 | .invalid-feedback { 8 | color: #a94442; 9 | display: block; 10 | margin: -1rem 0 2rem; 11 | } 12 | 13 | .phx-no-feedback.invalid-feedback, .phx-no-feedback .invalid-feedback { 14 | display: none; 15 | } 16 | 17 | .phx-click-loading { 18 | opacity: 0.5; 19 | transition: opacity 1s ease-out; 20 | } 21 | 22 | .phx-disconnected{ 23 | cursor: wait; 24 | } 25 | .phx-disconnected *{ 26 | pointer-events: none; 27 | } 28 | 29 | .phx-modal { 30 | opacity: 1!important; 31 | position: fixed; 32 | z-index: 1; 33 | left: 0; 34 | top: 0; 35 | width: 100%; 36 | height: 100%; 37 | overflow: auto; 38 | background-color: rgb(0,0,0); 39 | background-color: rgba(0,0,0,0.4); 40 | } 41 | 42 | .phx-modal-content { 43 | background-color: #fefefe; 44 | margin: 15% auto; 45 | padding: 20px; 46 | border: 1px solid #888; 47 | width: 80%; 48 | } 49 | 50 | .phx-modal-close { 51 | color: #aaa; 52 | float: right; 53 | font-size: 28px; 54 | font-weight: bold; 55 | } 56 | 57 | .phx-modal-close:hover, 58 | .phx-modal-close:focus { 59 | color: black; 60 | text-decoration: none; 61 | cursor: pointer; 62 | } 63 | 64 | 65 | /* Alerts and form errors */ 66 | .alert { 67 | padding: 15px; 68 | margin-bottom: 20px; 69 | border: 1px solid transparent; 70 | border-radius: 4px; 71 | } 72 | .alert-info { 73 | color: #31708f; 74 | background-color: #d9edf7; 75 | border-color: #bce8f1; 76 | } 77 | .alert-warning { 78 | color: #8a6d3b; 79 | background-color: #fcf8e3; 80 | border-color: #faebcc; 81 | } 82 | .alert-danger { 83 | color: #a94442; 84 | background-color: #f2dede; 85 | border-color: #ebccd1; 86 | } 87 | .alert p { 88 | margin-bottom: 0; 89 | } 90 | .alert:empty { 91 | display: none; 92 | } 93 | -------------------------------------------------------------------------------- /assets/css/my_app.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0 3 | } 4 | 5 | h2 { 6 | color: #9e61db; 7 | margin-top: 2rem; 8 | } 9 | 10 | ul { 11 | list-style: none; 12 | font-size: 1.5em; 13 | } 14 | 15 | .footer { 16 | position: absolute; 17 | } 18 | 19 | blockquote, dl, figure, form, ol, p, pre, table, ul { 20 | margin-bottom: 0rem; 21 | } 22 | 23 | input { 24 | padding: 0 0.5em; 25 | } 26 | 27 | form div { 28 | float: left; 29 | } 30 | 31 | .fullscreen { 32 | position: fixed; 33 | width: 100%; 34 | height: 100%; 35 | } 36 | 37 | .menu { 38 | width: 100%; 39 | margin: 0 5rem; 40 | } 41 | 42 | .menu>form>div { 43 | background: rgba(255, 255, 255, .4); 44 | border-radius: 1rem; 45 | } 46 | 47 | button { 48 | background-color: #9e61db; 49 | border: 0.1rem solid #9e61db; 50 | border-radius: .4rem; 51 | color: #fff; 52 | cursor: pointer; 53 | display: inline-block; 54 | font-size: 1.1rem; 55 | font-weight: 700; 56 | height: 3rem; 57 | letter-spacing: .1rem; 58 | line-height: 2.8rem; 59 | padding: 0 1.5rem; 60 | text-align: center; 61 | text-transform: uppercase; 62 | } 63 | 64 | @media screen and (min-device-width: 720px) { 65 | .graphics { 66 | position: fixed; 67 | width: 100%; 68 | height: 100%; 69 | } 70 | .menu { 71 | position: fixed; 72 | } 73 | .menu>form>div { 74 | padding: 0 0.5rem; 75 | margin: 0 0.5rem; 76 | } 77 | .footer { 78 | margin: 0 15rem 0 10rem; 79 | bottom: 10px; 80 | } 81 | } 82 | 83 | /* Style for mobile */ 84 | 85 | @media screen and (min-width: 240px) and (max-device-width: 720px) { 86 | .graphics { 87 | float: left; 88 | width: 100%; 89 | } 90 | h2 { 91 | font-size: 1.5em; 92 | } 93 | ul { 94 | font-size: 1.3em; 95 | } 96 | li { 97 | margin-bottom: 0; 98 | } 99 | .menu { 100 | background: #eee; 101 | margin: 0; 102 | line-height: 0.6em; 103 | padding: 0 2rem 3rem 2rem; 104 | font-size: 0.9em; 105 | height: 100%; 106 | } 107 | .menu>form>div { 108 | margin: 0 0.3rem; 109 | } 110 | .menu label, .menu1 label { 111 | font-size: 0.9em; 112 | } 113 | .footer { 114 | width: 90%; 115 | padding: 0 2rem; 116 | bottom: 0; 117 | float: left; 118 | font-size: 0.8em; 119 | margin: 0; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /assets/css/phoenix.css: -------------------------------------------------------------------------------- 1 | /* Includes some default style for the starter application. 2 | * This can be safely deleted to start fresh. 3 | */ 4 | 5 | /* Milligram v1.3.0 https://milligram.github.io 6 | * Copyright (c) 2017 CJ Patoilo Licensed under the MIT license 7 | */ 8 | 9 | *,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='email'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem;width:100%}input[type='email']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{-ms-grid-row-align:center;align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem;text-align:left}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right} 10 | 11 | /* General style */ 12 | h1{font-size: 3.6rem; line-height: 1.25} 13 | h2{font-size: 2.8rem; line-height: 1.3} 14 | h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35} 15 | h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5} 16 | h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4} 17 | h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2} 18 | pre{padding: 1em;} 19 | 20 | .container{ 21 | margin: 0 auto; 22 | max-width: 80.0rem; 23 | padding: 0 2.0rem; 24 | position: relative; 25 | width: 100% 26 | } 27 | select { 28 | width: auto; 29 | } 30 | 31 | /* Phoenix promo and logo */ 32 | .phx-hero { 33 | text-align: center; 34 | border-bottom: 1px solid #e3e3e3; 35 | background: #eee; 36 | border-radius: 6px; 37 | padding: 3em 3em 1em; 38 | margin-bottom: 3rem; 39 | font-weight: 200; 40 | font-size: 120%; 41 | } 42 | .phx-hero input { 43 | background: #ffffff; 44 | } 45 | .phx-logo { 46 | min-width: 300px; 47 | margin: 1rem; 48 | display: block; 49 | } 50 | .phx-logo img { 51 | width: auto; 52 | display: block; 53 | } 54 | 55 | /* Headers */ 56 | header { 57 | width: 100%; 58 | background: #fdfdfd; 59 | border-bottom: 1px solid #eaeaea; 60 | margin-bottom: 2rem; 61 | } 62 | header section { 63 | align-items: center; 64 | display: flex; 65 | flex-direction: column; 66 | justify-content: space-between; 67 | } 68 | header section :first-child { 69 | order: 2; 70 | } 71 | header section :last-child { 72 | order: 1; 73 | } 74 | header nav ul, 75 | header nav li { 76 | margin: 0; 77 | padding: 0; 78 | display: block; 79 | text-align: right; 80 | white-space: nowrap; 81 | } 82 | header nav ul { 83 | margin: 1rem; 84 | margin-top: 0; 85 | } 86 | header nav a { 87 | display: block; 88 | } 89 | 90 | @media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */ 91 | header section { 92 | flex-direction: row; 93 | } 94 | header nav ul { 95 | margin: 1rem; 96 | } 97 | .phx-logo { 98 | flex-basis: 527px; 99 | margin: 2rem 1rem; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /assets/js/app.js: -------------------------------------------------------------------------------- 1 | // We need to import the CSS so that webpack will load it. 2 | // The MiniCssExtractPlugin is used to separate it out into 3 | // its own CSS file. 4 | import "../css/app.scss" 5 | 6 | // webpack automatically bundles all modules in your 7 | // entry points. Those entry points can be configured 8 | // in "webpack.config.js". 9 | // 10 | // Import deps with the dep name or local files with a relative path, for example: 11 | // 12 | // import {Socket} from "phoenix" 13 | // import socket from "./socket" 14 | // 15 | import "phoenix_html" 16 | import {Socket} from "phoenix" 17 | import NProgress from "nprogress" 18 | import {LiveSocket} from "phoenix_live_view" 19 | 20 | let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") 21 | let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) 22 | 23 | // Show progress bar on live navigation and form submits 24 | window.addEventListener("phx:page-loading-start", info => NProgress.start()) 25 | window.addEventListener("phx:page-loading-stop", info => NProgress.done()) 26 | 27 | // connect if there are any LiveViews on the page 28 | liveSocket.connect() 29 | 30 | // expose liveSocket on window for web console debug logs and latency simulation: 31 | // >> liveSocket.enableDebug() 32 | // >> liveSocket.enableLatencySim(1000) 33 | window.liveSocket = liveSocket 34 | -------------------------------------------------------------------------------- /assets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "repository": {}, 3 | "description": " ", 4 | "license": "MIT", 5 | "scripts": { 6 | "deploy": "webpack --mode production", 7 | "watch": "webpack --mode development --watch" 8 | }, 9 | "dependencies": { 10 | "phoenix": "file:../deps/phoenix", 11 | "phoenix_html": "file:../deps/phoenix_html", 12 | "phoenix_live_view": "file:../deps/phoenix_live_view", 13 | "nprogress": "^0.2.0" 14 | }, 15 | "devDependencies": { 16 | "@babel/core": "^7.0.0", 17 | "@babel/preset-env": "^7.0.0", 18 | "babel-loader": "^8.0.0", 19 | "copy-webpack-plugin": "^5.1.1", 20 | "css-loader": "^3.4.2", 21 | "sass-loader": "^8.0.2", 22 | "node-sass": "^4.13.1", 23 | "mini-css-extract-plugin": "^0.9.0", 24 | "optimize-css-assets-webpack-plugin": "^5.0.1", 25 | "terser-webpack-plugin": "^2.3.2", 26 | "webpack": "4.41.5", 27 | "webpack-cli": "^3.3.2" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /assets/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miladamilli/artcode_poisson_colors/98249b20a9ef085c393f2c58aa81986d38e35201/assets/static/favicon.ico -------------------------------------------------------------------------------- /assets/static/images/phoenix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miladamilli/artcode_poisson_colors/98249b20a9ef085c393f2c58aa81986d38e35201/assets/static/images/phoenix.png -------------------------------------------------------------------------------- /assets/static/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /assets/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const glob = require('glob'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | const TerserPlugin = require('terser-webpack-plugin'); 5 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); 6 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 7 | 8 | module.exports = (env, options) => { 9 | const devMode = options.mode !== 'production'; 10 | 11 | return { 12 | optimization: { 13 | minimizer: [ 14 | new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }), 15 | new OptimizeCSSAssetsPlugin({}) 16 | ] 17 | }, 18 | entry: { 19 | 'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js']) 20 | }, 21 | output: { 22 | filename: '[name].js', 23 | path: path.resolve(__dirname, '../priv/static/js'), 24 | publicPath: '/js/' 25 | }, 26 | devtool: devMode ? 'source-map' : undefined, 27 | module: { 28 | rules: [ 29 | { 30 | test: /\.js$/, 31 | exclude: /node_modules/, 32 | use: { 33 | loader: 'babel-loader' 34 | } 35 | }, 36 | { 37 | test: /\.[s]?css$/, 38 | use: [ 39 | MiniCssExtractPlugin.loader, 40 | 'css-loader', 41 | 'sass-loader', 42 | ], 43 | } 44 | ] 45 | }, 46 | plugins: [ 47 | new MiniCssExtractPlugin({ filename: '../css/app.css' }), 48 | new CopyWebpackPlugin([{ from: 'static/', to: '../' }]) 49 | ] 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /circles1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miladamilli/artcode_poisson_colors/98249b20a9ef085c393f2c58aa81986d38e35201/circles1.jpg -------------------------------------------------------------------------------- /circles2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miladamilli/artcode_poisson_colors/98249b20a9ef085c393f2c58aa81986d38e35201/circles2.jpg -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | # 4 | # This configuration file is loaded before any dependency and 5 | # is restricted to this project. 6 | 7 | # General application configuration 8 | use Mix.Config 9 | 10 | # Configures the endpoint 11 | config :poisson_colors, PoissonColorsWeb.Endpoint, 12 | url: [host: "localhost"], 13 | secret_key_base: "YKt4AuxP8kvHbuxG/1EHnmhqSQWTaER+lEereZoxoiYiCAENRwGxQVlaY/oGtl4p", 14 | render_errors: [view: PoissonColorsWeb.ErrorView, accepts: ~w(html json), layout: false], 15 | pubsub_server: PoissonColors.PubSub, 16 | live_view: [signing_salt: "3cXaeX3X"] 17 | 18 | # Configures Elixir's Logger 19 | config :logger, :console, 20 | format: "$time $metadata[$level] $message\n", 21 | metadata: [:request_id] 22 | 23 | # Use Jason for JSON parsing in Phoenix 24 | config :phoenix, :json_library, Jason 25 | 26 | # Import environment specific config. This must remain at the bottom 27 | # of this file so it overrides the configuration defined above. 28 | import_config "#{Mix.env()}.exs" 29 | -------------------------------------------------------------------------------- /config/dev.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # For development, we disable any cache and enable 4 | # debugging and code reloading. 5 | # 6 | # The watchers configuration can be used to run external 7 | # watchers to your application. For example, we use it 8 | # with webpack to recompile .js and .css sources. 9 | config :poisson_colors, PoissonColorsWeb.Endpoint, 10 | http: [port: 4000], 11 | debug_errors: true, 12 | code_reloader: true, 13 | check_origin: false, 14 | watchers: [ 15 | node: [ 16 | "node_modules/webpack/bin/webpack.js", 17 | "--mode", 18 | "development", 19 | "--watch-stdin", 20 | cd: Path.expand("../assets", __DIR__) 21 | ] 22 | ] 23 | 24 | # ## SSL Support 25 | # 26 | # In order to use HTTPS in development, a self-signed 27 | # certificate can be generated by running the following 28 | # Mix task: 29 | # 30 | # mix phx.gen.cert 31 | # 32 | # Note that this task requires Erlang/OTP 20 or later. 33 | # Run `mix help phx.gen.cert` for more information. 34 | # 35 | # The `http:` config above can be replaced with: 36 | # 37 | # https: [ 38 | # port: 4001, 39 | # cipher_suite: :strong, 40 | # keyfile: "priv/cert/selfsigned_key.pem", 41 | # certfile: "priv/cert/selfsigned.pem" 42 | # ], 43 | # 44 | # If desired, both `http:` and `https:` keys can be 45 | # configured to run both http and https servers on 46 | # different ports. 47 | 48 | # Watch static and templates for browser reloading. 49 | config :poisson_colors, PoissonColorsWeb.Endpoint, 50 | live_reload: [ 51 | patterns: [ 52 | ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", 53 | ~r"priv/gettext/.*(po)$", 54 | ~r"lib/poisson_colors_web/(live|views)/.*(ex)$", 55 | ~r"lib/poisson_colors_web/templates/.*(eex)$" 56 | ] 57 | ] 58 | 59 | # Do not include metadata nor timestamps in development logs 60 | config :logger, :console, format: "[$level] $message\n" 61 | 62 | # Set a higher stacktrace during development. Avoid configuring such 63 | # in production as building large stacktraces may be expensive. 64 | config :phoenix, :stacktrace_depth, 20 65 | 66 | # Initialize plugs at runtime for faster development compilation 67 | config :phoenix, :plug_init_mode, :runtime 68 | -------------------------------------------------------------------------------- /config/prod.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # For production, don't forget to configure the url host 4 | # to something meaningful, Phoenix uses this information 5 | # when generating URLs. 6 | # 7 | # Note we also include the path to a cache manifest 8 | # containing the digested version of static files. This 9 | # manifest is generated by the `mix phx.digest` task, 10 | # which you should run after static files are built and 11 | # before starting your production server. 12 | config :poisson_colors, PoissonColorsWeb.Endpoint, 13 | url: [host: "example.com", port: 80], 14 | cache_static_manifest: "priv/static/cache_manifest.json" 15 | 16 | # Do not print debug messages in production 17 | config :logger, level: :info 18 | 19 | # ## SSL Support 20 | # 21 | # To get SSL working, you will need to add the `https` key 22 | # to the previous section and set your `:url` port to 443: 23 | # 24 | # config :poisson_colors, PoissonColorsWeb.Endpoint, 25 | # ... 26 | # url: [host: "example.com", port: 443], 27 | # https: [ 28 | # port: 443, 29 | # cipher_suite: :strong, 30 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), 31 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH"), 32 | # transport_options: [socket_opts: [:inet6]] 33 | # ] 34 | # 35 | # The `cipher_suite` is set to `:strong` to support only the 36 | # latest and more secure SSL ciphers. This means old browsers 37 | # and clients may not be supported. You can set it to 38 | # `:compatible` for wider support. 39 | # 40 | # `:keyfile` and `:certfile` expect an absolute path to the key 41 | # and cert in disk or a relative path inside priv, for example 42 | # "priv/ssl/server.key". For all supported SSL configuration 43 | # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 44 | # 45 | # We also recommend setting `force_ssl` in your endpoint, ensuring 46 | # no data is ever sent via http, always redirecting to https: 47 | # 48 | # config :poisson_colors, PoissonColorsWeb.Endpoint, 49 | # force_ssl: [hsts: true] 50 | # 51 | # Check `Plug.SSL` for all available options in `force_ssl`. 52 | 53 | # Finally import the config/prod.secret.exs which loads secrets 54 | # and configuration from environment variables. 55 | import_config "prod.secret.exs" 56 | -------------------------------------------------------------------------------- /config/prod.secret.exs: -------------------------------------------------------------------------------- 1 | # In this file, we load production configuration and secrets 2 | # from environment variables. You can also hardcode secrets, 3 | # although such is generally not recommended and you have to 4 | # remember to add this file to your .gitignore. 5 | use Mix.Config 6 | 7 | secret_key_base = 8 | System.get_env("SECRET_KEY_BASE") || 9 | raise """ 10 | environment variable SECRET_KEY_BASE is missing. 11 | You can generate one by calling: mix phx.gen.secret 12 | """ 13 | 14 | config :poisson_colors, PoissonColorsWeb.Endpoint, 15 | http: [ 16 | port: String.to_integer(System.get_env("PORT") || "4000"), 17 | transport_options: [socket_opts: [:inet6]] 18 | ], 19 | secret_key_base: secret_key_base 20 | 21 | # ## Using releases (Elixir v1.9+) 22 | # 23 | # If you are doing OTP releases, you need to instruct Phoenix 24 | # to start each relevant endpoint: 25 | # 26 | # config :poisson_colors, PoissonColorsWeb.Endpoint, server: true 27 | # 28 | # Then you can assemble a release by calling `mix release`. 29 | # See `mix help release` for more information. 30 | -------------------------------------------------------------------------------- /config/test.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | # We don't run a server during test. If one is required, 4 | # you can enable the server option below. 5 | config :poisson_colors, PoissonColorsWeb.Endpoint, 6 | http: [port: 4002], 7 | server: false 8 | 9 | # Print only warnings and errors during test 10 | config :logger, level: :warn 11 | -------------------------------------------------------------------------------- /lib/poisson_colors.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColors do 2 | @moduledoc """ 3 | PoissonColors keeps the contexts that define your domain 4 | and business logic. 5 | 6 | Contexts are also responsible for managing your data, regardless 7 | if it comes from the database, an external API or others. 8 | """ 9 | end 10 | -------------------------------------------------------------------------------- /lib/poisson_colors/application.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColors.Application do 2 | # See https://hexdocs.pm/elixir/Application.html 3 | # for more information on OTP Applications 4 | @moduledoc false 5 | 6 | use Application 7 | 8 | def start(_type, _args) do 9 | children = [ 10 | # Start the Telemetry supervisor 11 | PoissonColorsWeb.Telemetry, 12 | # Start the PubSub system 13 | {Phoenix.PubSub, name: PoissonColors.PubSub}, 14 | # Start the Endpoint (http/https) 15 | PoissonColorsWeb.Endpoint 16 | # Start a worker by calling: PoissonColors.Worker.start_link(arg) 17 | # {PoissonColors.Worker, arg} 18 | ] 19 | 20 | # See https://hexdocs.pm/elixir/Supervisor.html 21 | # for other strategies and supported options 22 | opts = [strategy: :one_for_one, name: PoissonColors.Supervisor] 23 | Supervisor.start_link(children, opts) 24 | end 25 | 26 | # Tell Phoenix to update the endpoint configuration 27 | # whenever the application is updated. 28 | def config_change(changed, _new, removed) do 29 | PoissonColorsWeb.Endpoint.config_change(changed, removed) 30 | :ok 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/poisson_colors/style.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColors.Style do 2 | @moduledoc """ 3 | Generates style of SVG circle. 4 | """ 5 | def random(%{color: color} = settings) do 6 | %{ 7 | radius: random_radius(settings), 8 | hue: random_hue(color.hue, color.hue_variation), 9 | saturation: random_saturation(color.saturation, color.saturation_variation), 10 | lightness: random_lightness(color.lightness, color.lightness_variation), 11 | opacity: random_opacity(color.opacity, color.opacity_variation) 12 | } 13 | end 14 | 15 | def random_hue(hue, variation) do 16 | hue_min = max(hue - variation, 0) 17 | hue_max = min(hue + variation, 360) 18 | random(hue_min, hue_max) 19 | end 20 | 21 | def random_saturation(value, variation), do: random_saturation_lightness(value, variation) 22 | def random_lightness(value, variation), do: random_saturation_lightness(value, variation) 23 | 24 | def random_saturation_lightness(value, variation) do 25 | value_min = max(value - variation, 0) 26 | value_max = min(value + variation, 100) 27 | random(value_min, value_max) 28 | end 29 | 30 | def random_opacity(opacity, variation) do 31 | min = max(opacity - variation, 0) 32 | max = min(opacity + variation, 1) 33 | min = floor(min * 10) 34 | max = floor(max * 10) 35 | random(min, max) / 10 36 | end 37 | 38 | def random_radius(%{ 39 | size: size, 40 | size_variation: variation, 41 | size_min: size_min, 42 | size_max: size_max 43 | }) do 44 | min = max(size - variation, size_min) 45 | max = min(size + variation, size_max) 46 | random(div(min, 2), div(max, 2)) 47 | end 48 | 49 | defp random(from, to) do 50 | :rand.uniform(to - from + 1) + from - 1 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/poisson_colors_web.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb do 2 | @moduledoc """ 3 | The entrypoint for defining your web interface, such 4 | as controllers, views, channels and so on. 5 | 6 | This can be used in your application as: 7 | 8 | use PoissonColorsWeb, :controller 9 | use PoissonColorsWeb, :view 10 | 11 | The definitions below will be executed for every view, 12 | controller, etc, so keep them short and clean, focused 13 | on imports, uses and aliases. 14 | 15 | Do NOT define functions inside the quoted expressions 16 | below. Instead, define any helper function in modules 17 | and import those modules here. 18 | """ 19 | 20 | def controller do 21 | quote do 22 | use Phoenix.Controller, namespace: PoissonColorsWeb 23 | 24 | import Plug.Conn 25 | import PoissonColorsWeb.Gettext 26 | alias PoissonColorsWeb.Router.Helpers, as: Routes 27 | end 28 | end 29 | 30 | def view do 31 | quote do 32 | use Phoenix.View, 33 | root: "lib/poisson_colors_web/templates", 34 | namespace: PoissonColorsWeb 35 | 36 | # Import convenience functions from controllers 37 | import Phoenix.Controller, 38 | only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1] 39 | 40 | # Include shared imports and aliases for views 41 | unquote(view_helpers()) 42 | end 43 | end 44 | 45 | def live_view do 46 | quote do 47 | use Phoenix.LiveView, 48 | layout: {PoissonColorsWeb.LayoutView, "live.html"} 49 | 50 | unquote(view_helpers()) 51 | end 52 | end 53 | 54 | def live_view_fullscreen do 55 | quote do 56 | use Phoenix.LiveView, 57 | layout: {PoissonColorsWeb.LayoutView, "live_fullscreen.html"} 58 | 59 | unquote(view_helpers()) 60 | end 61 | end 62 | 63 | def live_component do 64 | quote do 65 | use Phoenix.LiveComponent 66 | 67 | unquote(view_helpers()) 68 | end 69 | end 70 | 71 | def router do 72 | quote do 73 | use Phoenix.Router 74 | 75 | import Plug.Conn 76 | import Phoenix.Controller 77 | import Phoenix.LiveView.Router 78 | end 79 | end 80 | 81 | def channel do 82 | quote do 83 | use Phoenix.Channel 84 | import PoissonColorsWeb.Gettext 85 | end 86 | end 87 | 88 | defp view_helpers do 89 | quote do 90 | # Use all HTML functionality (forms, tags, etc) 91 | use Phoenix.HTML 92 | 93 | # Import LiveView helpers (live_render, live_component, live_patch, etc) 94 | import Phoenix.LiveView.Helpers 95 | 96 | # Import basic rendering functionality (render, render_layout, etc) 97 | import Phoenix.View 98 | 99 | import PoissonColorsWeb.ErrorHelpers 100 | import PoissonColorsWeb.Gettext 101 | alias PoissonColorsWeb.Router.Helpers, as: Routes 102 | end 103 | end 104 | 105 | @doc """ 106 | When used, dispatch to the appropriate controller/view/etc. 107 | """ 108 | defmacro __using__(which) when is_atom(which) do 109 | apply(__MODULE__, which, []) 110 | end 111 | end 112 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/channels/user_socket.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.UserSocket do 2 | use Phoenix.Socket 3 | 4 | ## Channels 5 | # channel "room:*", PoissonColorsWeb.RoomChannel 6 | 7 | # Socket params are passed from the client and can 8 | # be used to verify and authenticate a user. After 9 | # verification, you can put default assigns into 10 | # the socket that will be set for all channels, ie 11 | # 12 | # {:ok, assign(socket, :user_id, verified_user_id)} 13 | # 14 | # To deny connection, return `:error`. 15 | # 16 | # See `Phoenix.Token` documentation for examples in 17 | # performing token verification on connect. 18 | @impl true 19 | def connect(_params, socket, _connect_info) do 20 | {:ok, socket} 21 | end 22 | 23 | # Socket id's are topics that allow you to identify all sockets for a given user: 24 | # 25 | # def id(socket), do: "user_socket:#{socket.assigns.user_id}" 26 | # 27 | # Would allow you to broadcast a "disconnect" event and terminate 28 | # all active sockets and channels for a given user: 29 | # 30 | # PoissonColorsWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{}) 31 | # 32 | # Returning `nil` makes this socket anonymous. 33 | @impl true 34 | def id(_socket), do: nil 35 | end 36 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/endpoint.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.Endpoint do 2 | use Phoenix.Endpoint, otp_app: :poisson_colors 3 | 4 | # The session will be stored in the cookie and signed, 5 | # this means its contents can be read but not tampered with. 6 | # Set :encryption_salt if you would also like to encrypt it. 7 | @session_options [ 8 | store: :cookie, 9 | key: "_poisson_colors_key", 10 | signing_salt: "tw1xF3Tq" 11 | ] 12 | 13 | socket "/socket", PoissonColorsWeb.UserSocket, 14 | websocket: true, 15 | longpoll: false 16 | 17 | socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] 18 | 19 | # Serve at "/" the static files from "priv/static" directory. 20 | # 21 | # You should set gzip to true if you are running phx.digest 22 | # when deploying your static files in production. 23 | plug Plug.Static, 24 | at: "/", 25 | from: :poisson_colors, 26 | gzip: false, 27 | only: ~w(css fonts images js favicon.ico robots.txt) 28 | 29 | plug Plug.Static, 30 | at: "/", 31 | from: {:poisson_colors, "priv/output"}, 32 | gzip: false 33 | 34 | # Code reloading can be explicitly enabled under the 35 | # :code_reloader configuration of your endpoint. 36 | if code_reloading? do 37 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket 38 | plug Phoenix.LiveReloader 39 | plug Phoenix.CodeReloader 40 | end 41 | 42 | plug Phoenix.LiveDashboard.RequestLogger, 43 | param_key: "request_logger", 44 | cookie_key: "request_logger" 45 | 46 | plug Plug.RequestId 47 | plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] 48 | 49 | plug Plug.Parsers, 50 | parsers: [:urlencoded, :multipart, :json], 51 | pass: ["*/*"], 52 | json_decoder: Phoenix.json_library() 53 | 54 | plug Plug.MethodOverride 55 | plug Plug.Head 56 | plug Plug.Session, @session_options 57 | plug PoissonColorsWeb.Router 58 | end 59 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/gettext.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.Gettext do 2 | @moduledoc """ 3 | A module providing Internationalization with a gettext-based API. 4 | 5 | By using [Gettext](https://hexdocs.pm/gettext), 6 | your module gains a set of macros for translations, for example: 7 | 8 | import PoissonColorsWeb.Gettext 9 | 10 | # Simple translation 11 | gettext("Here is the string to translate") 12 | 13 | # Plural translation 14 | ngettext("Here is the string to translate", 15 | "Here are the strings to translate", 16 | 3) 17 | 18 | # Domain-based translation 19 | dgettext("errors", "Here is the error message to translate") 20 | 21 | See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. 22 | """ 23 | use Gettext, otp_app: :poisson_colors 24 | end 25 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/live/circles_live.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.CirclesLive do 2 | @moduledoc """ 3 | Generates colorful circles using Poisson Disc Sampling algorithm. 4 | """ 5 | use PoissonColorsWeb, :live_view_fullscreen 6 | alias PoissonColors.Style 7 | alias PoissonDiscSampling 8 | 9 | @export_template "lib/poisson_colors_web/templates/svg_template.eex" 10 | @path "priv/output/" 11 | 12 | @canvas_w 1920 13 | @canvas_h 1080 14 | @samples 10 15 | @color %{ 16 | hue: 180, 17 | hue_variation: 180, 18 | saturation: 75, 19 | saturation_variation: 25, 20 | lightness: 65, 21 | lightness_variation: 13, 22 | opacity: 0.5, 23 | opacity_variation: 1.0 24 | } 25 | 26 | def mount(_params, _session, socket) do 27 | settings = %{ 28 | min_dist: 80, 29 | color: @color, 30 | size: 60, 31 | size_variation: 60, 32 | size_min: 5, 33 | size_max: 250 34 | } 35 | 36 | socket = 37 | assign(socket, 38 | canvas_w: @canvas_w, 39 | canvas_h: @canvas_h, 40 | settings: settings, 41 | background: "white", 42 | page_title: "Poisson & Colors" 43 | ) 44 | 45 | if connected?(socket) do 46 | {:ok, assign(socket, objects: generate_objects(settings))} 47 | else 48 | {:ok, assign(socket, objects: [])} 49 | end 50 | end 51 | 52 | def handle_event("settings", %{"min_dist" => min_dist}, socket) do 53 | min_dist = String.to_integer(min_dist) 54 | settings = %{socket.assigns.settings | min_dist: min_dist} 55 | 56 | {:noreply, assign(socket, objects: generate_objects(settings), settings: settings)} 57 | end 58 | 59 | def handle_event("color", color, socket) do 60 | color = 61 | color 62 | |> Map.delete("_target") 63 | |> Map.new(fn {k, v} -> {String.to_existing_atom(k), parse_number(v)} end) 64 | 65 | settings = %{socket.assigns.settings | color: Map.merge(socket.assigns.settings.color, color)} 66 | 67 | {:noreply, 68 | assign(socket, 69 | settings: settings, 70 | objects: re_generate_objects(socket.assigns.objects, settings) 71 | )} 72 | end 73 | 74 | def handle_event("size", %{"size" => size, "size_variation" => size_variation}, socket) do 75 | size = String.to_integer(size) 76 | size_variation = String.to_integer(size_variation) 77 | settings = %{socket.assigns.settings | size: size, size_variation: size_variation} 78 | 79 | {:noreply, 80 | assign(socket, 81 | objects: re_generate_objects(socket.assigns.objects, settings), 82 | settings: settings 83 | )} 84 | end 85 | 86 | def handle_event("background", %{"background" => color}, socket) do 87 | {:noreply, assign(socket, background: color)} 88 | end 89 | 90 | def handle_event("save", _, socket) do 91 | file_id = UUID.uuid1() 92 | 93 | file = @path <> file_id 94 | generate_image(socket, file) 95 | 96 | {:noreply, 97 | socket 98 | |> put_flash( 99 | :info, 100 | Phoenix.HTML.raw( 101 | ~s(Image exported: download link.) 102 | ) 103 | )} 104 | end 105 | 106 | defp generate_image(socket, file) do 107 | svg = 108 | EEx.eval_file(@export_template, 109 | objects: socket.assigns.objects, 110 | canvas_w: socket.assigns.canvas_w, 111 | canvas_h: socket.assigns.canvas_h, 112 | background: socket.assigns.background 113 | ) 114 | 115 | File.write!(file <> ".svg", svg) 116 | System.cmd("convert", [file <> ".svg", file <> ".jpg"]) 117 | File.rm!(file <> ".svg") 118 | end 119 | 120 | defp generate_objects(settings) do 121 | PoissonDiscSampling.generate(settings.min_dist, @canvas_w, @canvas_h, @samples) 122 | |> Enum.map(fn {x, y} -> %{x: x, y: y, style: Style.random(settings)} end) 123 | end 124 | 125 | defp re_generate_objects(objects, settings) do 126 | Enum.map(objects, fn object -> %{object | style: Style.random(settings)} end) 127 | end 128 | 129 | defp parse_number(number) do 130 | case Integer.parse(number) do 131 | {number, ""} -> number 132 | _ -> String.to_float(number) 133 | end 134 | end 135 | end 136 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/live/circles_live.html.leex: -------------------------------------------------------------------------------- 1 |
2 | 4 | 5 | <%= for object <- @objects do %> 6 | 10 | <% end %> 11 | 12 |
13 | 84 | 89 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/live/page_live.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.PageLive do 2 | use PoissonColorsWeb, :live_view 3 | 4 | @impl true 5 | def mount(_params, _session, socket) do 6 | {:ok, assign(socket, query: "", results: %{})} 7 | end 8 | 9 | @impl true 10 | def handle_event("suggest", %{"q" => query}, socket) do 11 | {:noreply, assign(socket, results: search(query), query: query)} 12 | end 13 | 14 | @impl true 15 | def handle_event("search", %{"q" => query}, socket) do 16 | case search(query) do 17 | %{^query => vsn} -> 18 | {:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")} 19 | 20 | _ -> 21 | {:noreply, 22 | socket 23 | |> put_flash(:error, "No dependencies found matching \"#{query}\"") 24 | |> assign(results: %{}, query: query)} 25 | end 26 | end 27 | 28 | defp search(query) do 29 | if not PoissonColorsWeb.Endpoint.config(:code_reloader) do 30 | raise "action disabled when not in development" 31 | end 32 | 33 | for {app, desc, vsn} <- Application.started_applications(), 34 | app = to_string(app), 35 | String.starts_with?(app, query) and not List.starts_with?(desc, ~c"ERTS"), 36 | into: %{}, 37 | do: {app, vsn} 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/live/page_live.html.leex: -------------------------------------------------------------------------------- 1 |
2 |

<%= gettext "Welcome to %{name}!", name: "Phoenix" %>

3 |

Peace-of-mind from prototype to production

4 | 5 |
6 | 7 | 8 | <%= for {app, _vsn} <- @results do %> 9 | 10 | <% end %> 11 | 12 | 13 |
14 |
15 | 16 |
17 | 31 | 48 |
49 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/router.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.Router do 2 | use PoissonColorsWeb, :router 3 | 4 | pipeline :browser do 5 | plug :accepts, ["html"] 6 | plug :fetch_session 7 | plug :fetch_live_flash 8 | plug :put_root_layout, {PoissonColorsWeb.LayoutView, :root} 9 | plug :protect_from_forgery 10 | plug :put_secure_browser_headers 11 | end 12 | 13 | pipeline :api do 14 | plug :accepts, ["json"] 15 | end 16 | 17 | scope "/", PoissonColorsWeb do 18 | pipe_through :browser 19 | 20 | live "/", CirclesLive, :index 21 | end 22 | 23 | # Other scopes may use custom stacks. 24 | # scope "/api", PoissonColorsWeb do 25 | # pipe_through :api 26 | # end 27 | 28 | # Enables LiveDashboard only for development 29 | # 30 | # If you want to use the LiveDashboard in production, you should put 31 | # it behind authentication and allow only admins to access it. 32 | # If your application does not have an admins-only section yet, 33 | # you can use Plug.BasicAuth to set up some basic authentication 34 | # as long as you are also using SSL (which you should anyway). 35 | if Mix.env() in [:dev, :test] do 36 | import Phoenix.LiveDashboard.Router 37 | 38 | scope "/" do 39 | pipe_through :browser 40 | live_dashboard "/dashboard", metrics: PoissonColorsWeb.Telemetry 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/telemetry.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.Telemetry do 2 | use Supervisor 3 | import Telemetry.Metrics 4 | 5 | def start_link(arg) do 6 | Supervisor.start_link(__MODULE__, arg, name: __MODULE__) 7 | end 8 | 9 | @impl true 10 | def init(_arg) do 11 | children = [ 12 | # Telemetry poller will execute the given period measurements 13 | # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics 14 | {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} 15 | # Add reporters as children of your supervision tree. 16 | # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} 17 | ] 18 | 19 | Supervisor.init(children, strategy: :one_for_one) 20 | end 21 | 22 | def metrics do 23 | [ 24 | # Phoenix Metrics 25 | summary("phoenix.endpoint.stop.duration", 26 | unit: {:native, :millisecond} 27 | ), 28 | summary("phoenix.router_dispatch.stop.duration", 29 | tags: [:route], 30 | unit: {:native, :millisecond} 31 | ), 32 | 33 | # VM Metrics 34 | summary("vm.memory.total", unit: {:byte, :kilobyte}), 35 | summary("vm.total_run_queue_lengths.total"), 36 | summary("vm.total_run_queue_lengths.cpu"), 37 | summary("vm.total_run_queue_lengths.io") 38 | ] 39 | end 40 | 41 | defp periodic_measurements do 42 | [ 43 | # A module, function and arguments to be invoked periodically. 44 | # This function must call :telemetry.execute/3 and a metric must be added above. 45 | # {PoissonColorsWeb, :count_users, []} 46 | ] 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/templates/layout/app.html.eex: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | <%= @inner_content %> 5 |
6 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/templates/layout/live.html.leex: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 | 9 | 10 | <%= @inner_content %> 11 |
12 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/templates/layout/live_fullscreen.html.leex: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 | 9 | 10 | <%= @inner_content %> 11 |
12 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/templates/layout/root.html.leex: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= csrf_meta_tag() %> 8 | <%= live_title_tag assigns[:page_title] || "PoissonColors", suffix: " · Phoenix Framework" %> 9 | "/> 10 | 11 | 12 | 13 | <%= @inner_content %> 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/templates/svg_template.eex: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | <%= for object <- objects do %> 8 | 13 | <% end %> 14 | 15 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/views/error_helpers.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.ErrorHelpers do 2 | @moduledoc """ 3 | Conveniences for translating and building error messages. 4 | """ 5 | 6 | use Phoenix.HTML 7 | 8 | @doc """ 9 | Generates tag for inlined form input errors. 10 | """ 11 | def error_tag(form, field) do 12 | Enum.map(Keyword.get_values(form.errors, field), fn error -> 13 | content_tag(:span, translate_error(error), 14 | class: "invalid-feedback", 15 | phx_feedback_for: input_id(form, field) 16 | ) 17 | end) 18 | end 19 | 20 | @doc """ 21 | Translates an error message using gettext. 22 | """ 23 | def translate_error({msg, opts}) do 24 | # When using gettext, we typically pass the strings we want 25 | # to translate as a static argument: 26 | # 27 | # # Translate "is invalid" in the "errors" domain 28 | # dgettext("errors", "is invalid") 29 | # 30 | # # Translate the number of files with plural rules 31 | # dngettext("errors", "1 file", "%{count} files", count) 32 | # 33 | # Because the error messages we show in our forms and APIs 34 | # are defined inside Ecto, we need to translate them dynamically. 35 | # This requires us to call the Gettext module passing our gettext 36 | # backend as first argument. 37 | # 38 | # Note we use the "errors" domain, which means translations 39 | # should be written to the errors.po file. The :count option is 40 | # set by Ecto and indicates we should also apply plural rules. 41 | if count = opts[:count] do 42 | Gettext.dngettext(PoissonColorsWeb.Gettext, "errors", msg, msg, count, opts) 43 | else 44 | Gettext.dgettext(PoissonColorsWeb.Gettext, "errors", msg, opts) 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/views/error_view.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.ErrorView do 2 | use PoissonColorsWeb, :view 3 | 4 | # If you want to customize a particular status code 5 | # for a certain format, you may uncomment below. 6 | # def render("500.html", _assigns) do 7 | # "Internal Server Error" 8 | # end 9 | 10 | # By default, Phoenix returns the status message from 11 | # the template name. For example, "404.html" becomes 12 | # "Not Found". 13 | def template_not_found(template, _assigns) do 14 | Phoenix.Controller.status_message_from_template(template) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/poisson_colors_web/views/layout_view.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.LayoutView do 2 | use PoissonColorsWeb, :view 3 | end 4 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule PoissonColors.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :poisson_colors, 7 | version: "0.1.0", 8 | elixir: "~> 1.7", 9 | elixirc_paths: elixirc_paths(Mix.env()), 10 | compilers: [:phoenix, :gettext] ++ Mix.compilers(), 11 | start_permanent: Mix.env() == :prod, 12 | aliases: aliases(), 13 | deps: deps() 14 | ] 15 | end 16 | 17 | # Configuration for the OTP application. 18 | # 19 | # Type `mix help compile.app` for more information. 20 | def application do 21 | [ 22 | mod: {PoissonColors.Application, []}, 23 | extra_applications: [:logger, :runtime_tools] 24 | ] 25 | end 26 | 27 | # Specifies which paths to compile per environment. 28 | defp elixirc_paths(:test), do: ["lib", "test/support"] 29 | defp elixirc_paths(_), do: ["lib"] 30 | 31 | # Specifies your project dependencies. 32 | # 33 | # Type `mix help deps` for examples and options. 34 | defp deps do 35 | [ 36 | {:phoenix, "~> 1.5.3"}, 37 | {:phoenix_live_view, "~> 0.13.0"}, 38 | {:floki, ">= 0.0.0", only: :test}, 39 | {:phoenix_html, "~> 2.11"}, 40 | {:phoenix_live_reload, "~> 1.2", only: :dev}, 41 | {:phoenix_live_dashboard, "~> 0.2.0"}, 42 | {:telemetry_metrics, "~> 0.4"}, 43 | {:telemetry_poller, "~> 0.4"}, 44 | {:gettext, "~> 0.11"}, 45 | {:jason, "~> 1.0"}, 46 | {:plug_cowboy, "~> 2.0"}, 47 | {:poisson_disc_sampling, 48 | git: "https://github.com/miladamilli/poisson_disc_sampling.git", tag: "1.0"}, 49 | {:uuid, "~> 1.1"} 50 | ] 51 | end 52 | 53 | # Aliases are shortcuts or tasks specific to the current project. 54 | # For example, to install project dependencies and perform other setup tasks, run: 55 | # 56 | # $ mix setup 57 | # 58 | # See the documentation for `Mix` for more info on aliases. 59 | defp aliases do 60 | [ 61 | setup: ["deps.get", "cmd npm install --prefix assets"] 62 | ] 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"}, 3 | "cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"}, 4 | "file_system": {:hex, :file_system, "0.2.8", "f632bd287927a1eed2b718f22af727c5aeaccc9a98d8c2bd7bff709e851dc986", [:mix], [], "hexpm", "97a3b6f8d63ef53bd0113070102db2ce05352ecf0d25390eb8d747c2bde98bca"}, 5 | "floki": {:hex, :floki, "0.26.0", "4df88977e2e357c6720e1b650f613444bfb48c5acfc6a0c646ab007d08ad13bf", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "e7b66ce7feef5518a9cd9fc7b52dd62a64028bd9cb6d6ad282a0f0fc90a4ae52"}, 6 | "gettext": {:hex, :gettext, "0.18.0", "406d6b9e0e3278162c2ae1de0a60270452c553536772167e2d701f028116f870", [:mix], [], "hexpm", "c3f850be6367ebe1a08616c2158affe4a23231c70391050bf359d5f92f66a571"}, 7 | "html_entities": {:hex, :html_entities, "0.5.1", "1c9715058b42c35a2ab65edc5b36d0ea66dd083767bef6e3edb57870ef556549", [:mix], [], "hexpm", "30efab070904eb897ff05cd52fa61c1025d7f8ef3a9ca250bc4e6513d16c32de"}, 8 | "jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"}, 9 | "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"}, 10 | "phoenix": {:hex, :phoenix, "1.5.3", "bfe0404e48ea03dfe17f141eff34e1e058a23f15f109885bbdcf62be303b49ff", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8e16febeb9640d8b33895a691a56481464b82836d338bb3a23125cd7b6157c25"}, 11 | "phoenix_html": {:hex, :phoenix_html, "2.14.2", "b8a3899a72050f3f48a36430da507dd99caf0ac2d06c77529b1646964f3d563e", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "58061c8dfd25da5df1ea0ca47c972f161beb6c875cd293917045b92ffe1bf617"}, 12 | "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.2.6", "1b4e1b7d797386b7f9d70d2af931dc9843a5f2f2423609d22cef1eec4e4dba7d", [:mix], [{:phoenix_html, "~> 2.14.1 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.13.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.4.0 or ~> 0.5.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "b20dcad98c4ca63d38a7f5e7a40936e1e8e9da983d3d722b88ae33afb866c9ca"}, 13 | "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.4", "940c0344b1d66a2e46eef02af3a70e0c5bb45a4db0bf47917add271b76cd3914", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "38f9308357dea4cc77f247e216da99fcb0224e05ada1469167520bed4cb8cccd"}, 14 | "phoenix_live_view": {:hex, :phoenix_live_view, "0.13.3", "2186c55cc7c54ca45b97c6f28cfd267d1c61b5f205f3c83533704cd991bdfdec", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.4.17 or ~> 1.5.2", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "c6309a7da2e779cb9cdf2fb603d75f38f49ef324bedc7a81825998bd1744ff8a"}, 15 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"}, 16 | "plug": {:hex, :plug, "1.10.3", "c9cebe917637d8db0e759039cc106adca069874e1a9034fd6e3fdd427fd3c283", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "01f9037a2a1de1d633b5a881101e6a444bcabb1d386ca1e00bb273a1f1d9d939"}, 17 | "plug_cowboy": {:hex, :plug_cowboy, "2.3.0", "149a50e05cb73c12aad6506a371cd75750c0b19a32f81866e1a323dda9e0e99d", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bc595a1870cef13f9c1e03df56d96804db7f702175e4ccacdb8fc75c02a7b97e"}, 18 | "plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"}, 19 | "poisson_disc_sampling": {:git, "https://github.com/miladamilli/poisson_disc_sampling.git", "3150a19bf72a7f6ca7300b2548610f7ff000aee5", [tag: "1.0"]}, 20 | "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"}, 21 | "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, 22 | "telemetry_metrics": {:hex, :telemetry_metrics, "0.5.0", "1b796e74add83abf844e808564275dfb342bcc930b04c7577ab780e262b0d998", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31225e6ce7a37a421a0a96ec55244386aec1c190b22578bd245188a4a33298fd"}, 23 | "telemetry_poller": {:hex, :telemetry_poller, "0.5.0", "4770888ef85599ead39c7f51d6b4b62306e602d96c69b2625d54dea3d9a5204b", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69e4e8e65b0ae077c9e14cd5f42c7cc486de0e07ac6e3409e6f0e52699a7872c"}, 24 | "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm", "c790593b4c3b601f5dc2378baae7efaf5b3d73c4c6456ba85759905be792f2ac"}, 25 | } 26 | -------------------------------------------------------------------------------- /priv/gettext/en/LC_MESSAGES/errors.po: -------------------------------------------------------------------------------- 1 | ## `msgid`s in this file come from POT (.pot) files. 2 | ## 3 | ## Do not add, change, or remove `msgid`s manually here as 4 | ## they're tied to the ones in the corresponding POT file 5 | ## (with the same domain). 6 | ## 7 | ## Use `mix gettext.extract --merge` or `mix gettext.merge` 8 | ## to merge POT files into PO files. 9 | msgid "" 10 | msgstr "" 11 | "Language: en\n" 12 | -------------------------------------------------------------------------------- /priv/gettext/errors.pot: -------------------------------------------------------------------------------- 1 | ## This is a PO Template file. 2 | ## 3 | ## `msgid`s here are often extracted from source code. 4 | ## Add new translations manually only if they're dynamic 5 | ## translations that can't be statically extracted. 6 | ## 7 | ## Run `mix gettext.extract` to bring this file up to 8 | ## date. Leave `msgstr`s empty as changing them here has no 9 | ## effect: edit them in PO (`.po`) files instead. 10 | 11 | -------------------------------------------------------------------------------- /priv/output/.output_dir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miladamilli/artcode_poisson_colors/98249b20a9ef085c393f2c58aa81986d38e35201/priv/output/.output_dir -------------------------------------------------------------------------------- /test/poisson_colors_web/views/error_view_test.exs: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.ErrorViewTest do 2 | use PoissonColorsWeb.ConnCase, async: true 3 | 4 | # Bring render/3 and render_to_string/3 for testing custom views 5 | import Phoenix.View 6 | 7 | test "renders 404.html" do 8 | assert render_to_string(PoissonColorsWeb.ErrorView, "404.html", []) == "Not Found" 9 | end 10 | 11 | test "renders 500.html" do 12 | assert render_to_string(PoissonColorsWeb.ErrorView, "500.html", []) == "Internal Server Error" 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /test/poisson_colors_web/views/layout_view_test.exs: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.LayoutViewTest do 2 | use PoissonColorsWeb.ConnCase, async: true 3 | 4 | # When testing helpers, you may want to import Phoenix.HTML and 5 | # use functions such as safe_to_string() to convert the helper 6 | # result into an HTML string. 7 | # import Phoenix.HTML 8 | end 9 | -------------------------------------------------------------------------------- /test/support/channel_case.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.ChannelCase do 2 | @moduledoc """ 3 | This module defines the test case to be used by 4 | channel tests. 5 | 6 | Such tests rely on `Phoenix.ChannelTest` and also 7 | import other functionality to make it easier 8 | to build common data structures and query the data layer. 9 | 10 | Finally, if the test case interacts with the database, 11 | we enable the SQL sandbox, so changes done to the database 12 | are reverted at the end of every test. If you are using 13 | PostgreSQL, you can even run database tests asynchronously 14 | by setting `use PoissonColorsWeb.ChannelCase, async: true`, although 15 | this option is not recommended for other databases. 16 | """ 17 | 18 | use ExUnit.CaseTemplate 19 | 20 | using do 21 | quote do 22 | # Import conveniences for testing with channels 23 | import Phoenix.ChannelTest 24 | import PoissonColorsWeb.ChannelCase 25 | 26 | # The default endpoint for testing 27 | @endpoint PoissonColorsWeb.Endpoint 28 | end 29 | end 30 | 31 | setup _tags do 32 | :ok 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /test/support/conn_case.ex: -------------------------------------------------------------------------------- 1 | defmodule PoissonColorsWeb.ConnCase do 2 | @moduledoc """ 3 | This module defines the test case to be used by 4 | tests that require setting up a connection. 5 | 6 | Such tests rely on `Phoenix.ConnTest` and also 7 | import other functionality to make it easier 8 | to build common data structures and query the data layer. 9 | 10 | Finally, if the test case interacts with the database, 11 | we enable the SQL sandbox, so changes done to the database 12 | are reverted at the end of every test. If you are using 13 | PostgreSQL, you can even run database tests asynchronously 14 | by setting `use PoissonColorsWeb.ConnCase, async: true`, although 15 | this option is not recommended for other databases. 16 | """ 17 | 18 | use ExUnit.CaseTemplate 19 | 20 | using do 21 | quote do 22 | # Import conveniences for testing with connections 23 | import Plug.Conn 24 | import Phoenix.ConnTest 25 | import PoissonColorsWeb.ConnCase 26 | 27 | alias PoissonColorsWeb.Router.Helpers, as: Routes 28 | 29 | # The default endpoint for testing 30 | @endpoint PoissonColorsWeb.Endpoint 31 | end 32 | end 33 | 34 | setup _tags do 35 | {:ok, conn: Phoenix.ConnTest.build_conn()} 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | --------------------------------------------------------------------------------