├── .gitignore ├── Day10 ├── IcoSphere.elm ├── Main.elm ├── index.html └── screenshot.mp4 ├── Day11 ├── Main.elm ├── index.html └── screenshot.mp4 ├── Day12 ├── Main.elm ├── index.html └── screenshot.gif ├── Day13 ├── Eye.elm ├── Main.elm ├── Shapes.elm ├── TrippyBackground.elm ├── index.html └── screenshot.mp4 ├── Day14 ├── Main.elm ├── TileGrid.elm ├── index.html └── screenshot.gif ├── Day15 ├── Main.elm ├── Vibrant.min.js ├── beard-color.jpg ├── beard-silhouette.png ├── color-thief.min.js ├── crow-color.jpg ├── crow-silhouette.png ├── dragon-color.jpg ├── dragon-silhouette.png ├── fish-color.jpg ├── fish-silhouette.png ├── index.html ├── main.js ├── quill-color.png ├── quill-silhouette.png ├── reindeer-color.jpg ├── reindeer-silhouette.png ├── rhino-color.jpg ├── rhino-silhoutte.png ├── saxophone-color.jpg ├── saxophone-silhouette.png ├── screenshot.mp4 ├── stork-color.jpg ├── stork-silhouette.png ├── swan-color.jpg ├── swan-silhouette.png ├── tea-color.jpg ├── tea-silhouette.png ├── unicorn-color.jpg └── unicorn-silhouette.png ├── Day16 ├── .gitignore ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day17 ├── .gitignore ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day18 ├── .gitignore ├── Main.elm ├── Shapes.elm ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day19 ├── .gitignore ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day20 ├── .gitignore ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day21 ├── .gitignore ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day22 ├── .gitignore ├── DrawTree.elm ├── Main.elm ├── elm-tree-diagram │ ├── LICENSE │ └── src │ │ ├── TreeDiagram.elm │ │ └── TreeDiagram │ │ ├── Canvas.elm │ │ └── Svg.elm ├── index.html └── screenshot.png ├── Day23 ├── .gitignore ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day24 ├── .gitignore ├── Board.elm ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day25 ├── .gitignore ├── Board.elm ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day26 ├── .gitignore ├── Board.elm ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day27 ├── .gitignore ├── Coin.elm ├── Main.elm ├── Svg │ └── Util.elm ├── elm-package.json ├── index.html └── screenshot.gif ├── Day28 ├── .gitignore ├── Main.elm ├── Particle.elm ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day29 ├── .gitignore ├── Main.elm ├── Particle.elm ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day30 ├── .gitignore ├── Main.elm ├── PlanetCute PNG │ ├── Brown Block.png │ ├── Character Boy.png │ ├── Character Cat Girl.png │ ├── Character Horn Girl.png │ ├── Character Pink Girl.png │ ├── Character Princess Girl.png │ ├── Chest Closed.png │ ├── Chest Lid.png │ ├── Chest Open.png │ ├── Dirt Block.png │ ├── Door Tall Closed.png │ ├── Door Tall Open.png │ ├── Enemy Bug.png │ ├── Gem Blue.png │ ├── Gem Green.png │ ├── Gem Orange.png │ ├── Grass Block.png │ ├── Heart.png │ ├── Key.png │ ├── Plain Block.png │ ├── PlanetCuteShadowMockup.jpg │ ├── PlanetCuteShadowTest.png │ ├── Ramp East.png │ ├── Ramp North.png │ ├── Ramp South.png │ ├── Ramp West.png │ ├── Rock.png │ ├── Roof East.png │ ├── Roof North East.png │ ├── Roof North West.png │ ├── Roof North.png │ ├── Roof South East.png │ ├── Roof South West.png │ ├── Roof South.png │ ├── Roof West.png │ ├── Selector.png │ ├── Shadow East.png │ ├── Shadow North East.png │ ├── Shadow North West.png │ ├── Shadow North.png │ ├── Shadow Side West.png │ ├── Shadow South East.png │ ├── Shadow South West.png │ ├── Shadow South.png │ ├── Shadow West.png │ ├── SpeechBubble.png │ ├── Star.png │ ├── Stone Block Tall.png │ ├── Stone Block.png │ ├── Thumbs.db │ ├── Tree Short.png │ ├── Tree Tall.png │ ├── Tree Ugly.png │ ├── Wall Block Tall.png │ ├── Wall Block.png │ ├── Water Block.png │ ├── Window Tall.png │ └── Wood Block.png ├── elm-package.json ├── index.html └── screenshot.mp4 ├── Day6 ├── Main.elm ├── Meshes.elm ├── index.html └── screenshot.gif ├── Day7 ├── Main.elm ├── index.html └── screenshot.gif ├── Day8 ├── Main.elm ├── Street_intersection_diagram.svg ├── index.html └── screenshot.gif ├── Day9 ├── Main.elm ├── index.html └── screenshot.mp4 ├── day-1 ├── Main.elm ├── elm-package.json ├── index.html └── screenshot.png ├── day-2 ├── Main.elm ├── index.html └── screenshot.gif ├── day-3 ├── Main.elm ├── index.html └── screenshot.gif ├── day-4 ├── Main.elm ├── index.html └── screenshot.gif ├── day-5 ├── Main.elm ├── index.html └── screenshot.gif └── elm-package.json /.gitignore: -------------------------------------------------------------------------------- 1 | elm-stuff 2 | node_modules 3 | -------------------------------------------------------------------------------- /Day10/IcoSphere.elm: -------------------------------------------------------------------------------- 1 | module Day10.IcoSphere exposing (sphere) 2 | 3 | import Math.Vector3 exposing (..) 4 | 5 | 6 | sphere : Int -> List ( Vec3, Vec3, Vec3 ) 7 | sphere subdivisions = 8 | icotris_v1 9 | |> subdivide subdivisions 10 | |> List.map normalizeTri 11 | 12 | 13 | normalizeTri : ( Vec3, Vec3, Vec3 ) -> ( Vec3, Vec3, Vec3 ) 14 | normalizeTri ( a, b, c ) = 15 | ( normalize a 16 | , normalize b 17 | , normalize c 18 | ) 19 | 20 | 21 | normalize : Vec3 -> Vec3 22 | normalize p = 23 | let 24 | l = 25 | length p 26 | 27 | ( x, y, z ) = 28 | toTuple p 29 | in 30 | vec3 (x / l) (y / l) (z / l) 31 | 32 | 33 | midpoint : Vec3 -> Vec3 -> Vec3 34 | midpoint a b = 35 | let 36 | ( x, y, z ) = 37 | toTuple a 38 | 39 | ( x', y', z' ) = 40 | toTuple b 41 | in 42 | vec3 ((x + x') / 2) ((y + y') / 2) ((z + z') / 2) 43 | 44 | 45 | subdivide : Int -> List ( Vec3, Vec3, Vec3 ) -> List ( Vec3, Vec3, Vec3 ) 46 | subdivide frequency tris = 47 | let 48 | subdivideTri ( v1, v2, v3 ) = 49 | let 50 | a = 51 | midpoint v1 v2 52 | 53 | b = 54 | midpoint v2 v3 55 | 56 | c = 57 | midpoint v3 v1 58 | in 59 | [ ( v1, a, c ) 60 | , ( v2, b, a ) 61 | , ( v3, c, b ) 62 | , ( a, b, c ) 63 | ] 64 | in 65 | if frequency <= 0 then 66 | tris 67 | else 68 | subdivide (frequency - 1) (List.concatMap subdivideTri tris) 69 | 70 | 71 | icotris_v1 : List ( Vec3, Vec3, Vec3 ) 72 | icotris_v1 = 73 | let 74 | t = 75 | (1.0 + sqrt (5.0)) / 2.0 76 | 77 | vertex_0 = 78 | vec3 (-1) t 0 79 | 80 | vertex_1 = 81 | vec3 1 t 0 82 | 83 | vertex_2 = 84 | vec3 (-1) (-t) 0 85 | 86 | vertex_3 = 87 | vec3 1 (-t) 0 88 | 89 | vertex_4 = 90 | vec3 0 (-1) t 91 | 92 | vertex_5 = 93 | vec3 0 1 t 94 | 95 | vertex_6 = 96 | vec3 0 (-1) (-t) 97 | 98 | vertex_7 = 99 | vec3 0 1 (-t) 100 | 101 | vertex_8 = 102 | vec3 t 0 (-1) 103 | 104 | vertex_9 = 105 | vec3 t 0 1 106 | 107 | vertex_10 = 108 | vec3 (-t) 0 (-1) 109 | 110 | vertex_11 = 111 | vec3 (-t) 0 1 112 | in 113 | [ -- faces around point 0 114 | ( vertex_0, vertex_11, vertex_5 ) 115 | , ( vertex_0, vertex_5, vertex_1 ) 116 | , ( vertex_0, vertex_1, vertex_7 ) 117 | {- 118 | , ( vertex_0 , vertex_1 , vertex_7 ) 119 | -} 120 | , ( vertex_0, vertex_7, vertex_10 ) 121 | , ( vertex_0, vertex_10, vertex_11 ) 122 | -- 5 adjacent faces 123 | , ( vertex_1, vertex_5, vertex_9 ) 124 | , ( vertex_5, vertex_11, vertex_4 ) 125 | , ( vertex_11, vertex_10, vertex_2 ) 126 | , ( vertex_10, vertex_7, vertex_6 ) 127 | , ( vertex_7, vertex_1, vertex_8 ) 128 | -- 5 adjacent faces around point 3 129 | , ( vertex_3, vertex_9, vertex_4 ) 130 | , ( vertex_3, vertex_4, vertex_2 ) 131 | , ( vertex_3, vertex_2, vertex_6 ) 132 | , ( vertex_3, vertex_6, vertex_8 ) 133 | , ( vertex_3, vertex_8, vertex_9 ) 134 | -- 5 adjacent faces 135 | , ( vertex_4, vertex_9, vertex_5 ) 136 | , ( vertex_2, vertex_4, vertex_11 ) 137 | , ( vertex_6, vertex_2, vertex_10 ) 138 | , ( vertex_8, vertex_6, vertex_7 ) 139 | , ( vertex_9, vertex_8, vertex_1 ) 140 | ] 141 | -------------------------------------------------------------------------------- /Day10/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day10/screenshot.mp4 -------------------------------------------------------------------------------- /Day11/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Html.App 5 | import Html.Attributes 6 | import WebGL 7 | 8 | 9 | -- 10 | 11 | import Math.Vector3 exposing (..) 12 | import Math.Matrix4 exposing (..) 13 | import WebGL exposing (..) 14 | import Html.App as Html 15 | import AnimationFrame 16 | import Html.Attributes exposing (width, height) 17 | 18 | 19 | -- type alias Model = 20 | -- () 21 | -- 22 | -- 23 | -- main : Program Never 24 | -- main = 25 | -- Html.App.beginnerProgram 26 | -- { model = () 27 | -- , update = \msg model -> model 28 | -- , view = view 29 | -- } 30 | -- 31 | -- 32 | -- view : Model -> Html msg 33 | -- view model = 34 | -- WebGL.toHtml 35 | -- [ Html.Attributes.width 750 36 | -- , Html.Attributes.height 500 37 | -- ] 38 | -- scene 39 | -- 40 | -- 41 | 42 | 43 | type alias VertexAttributes = 44 | { position : Vec3 45 | } 46 | 47 | 48 | type alias Uniforms = 49 | { camera : Mat4 50 | , time : Float 51 | } 52 | 53 | 54 | type alias Varyings = 55 | { vposition : Vec3 } 56 | 57 | 58 | 59 | -- 60 | -- scene : List WebGL.Renderable 61 | -- scene = 62 | -- [ WebGL.render vertexShader fragmentShader mesh uniforms 63 | -- ] 64 | -- 65 | -- 66 | -- uniforms : Uniforms 67 | -- uniforms = 68 | -- {} 69 | -- 70 | -- 71 | -- mesh : WebGL.Drawable VertexAttributes 72 | -- mesh = 73 | -- WebGL.Triangle 74 | -- [ ( VertexAttributes 0 0 75 | -- , VertexAttributes 1 0 76 | -- , VertexAttributes 1 1 77 | -- ) 78 | -- , ( VertexAttributes 0 0 79 | -- , VertexAttributes 0 1 80 | -- , VertexAttributes 1 1 81 | -- ) 82 | -- ] 83 | 84 | 85 | main : Program Never 86 | main = 87 | Html.program 88 | { init = ( 0, Cmd.none ) 89 | , view = scene >> WebGL.toHtml [ width 750, height 500 ] 90 | , subscriptions = (\model -> AnimationFrame.diffs Basics.identity) 91 | , update = (\dt theta -> ( theta + dt / 1000, Cmd.none )) 92 | } 93 | 94 | 95 | 96 | -- MESHES - create a cube in which each vertex has a position and color 97 | 98 | 99 | cube : Drawable VertexAttributes 100 | cube = 101 | let 102 | rft = 103 | vec3 1 1 0 104 | 105 | lft = 106 | vec3 -1 1 0 107 | 108 | lbt = 109 | vec3 -1 -1 0 110 | 111 | rbt = 112 | vec3 1 -1 0 113 | in 114 | Triangle 115 | << List.concat 116 | <| 117 | [ face rft lft lbt rbt 118 | ] 119 | 120 | 121 | face : Vec3 -> Vec3 -> Vec3 -> Vec3 -> List ( VertexAttributes, VertexAttributes, VertexAttributes ) 122 | face a b c d = 123 | let 124 | vertex position = 125 | VertexAttributes position 126 | in 127 | [ ( vertex a, vertex b, vertex c ) 128 | , ( vertex c, vertex d, vertex a ) 129 | ] 130 | 131 | 132 | 133 | -- VIEW 134 | 135 | 136 | scene : Float -> List Renderable 137 | scene t = 138 | [ render vertexShader fragmentShader cube (uniforms t) ] 139 | 140 | 141 | uniforms : Float -> Uniforms 142 | uniforms t = 143 | { camera = makeOrtho2D 0 1 0 0.66666 144 | , time = t 145 | } 146 | 147 | 148 | 149 | -- SHADERS 150 | 151 | 152 | vertexShader : Shader VertexAttributes Uniforms Varyings 153 | vertexShader = 154 | [glsl| 155 | 156 | attribute vec3 position; 157 | 158 | uniform mat4 camera; 159 | 160 | varying vec3 vposition; 161 | 162 | void main () { 163 | gl_Position = camera * vec4(position, 1.0); 164 | vposition = position; 165 | } 166 | 167 | |] 168 | 169 | 170 | fragmentShader : WebGL.Shader {} Uniforms Varyings 171 | fragmentShader = 172 | [glsl| 173 | 174 | precision mediump float; 175 | 176 | uniform float time; 177 | 178 | varying vec3 vposition; 179 | 180 | float hue2rgb(float f1, float f2, float hue) { 181 | if (hue < 0.0) 182 | hue += 1.0; 183 | else if (hue > 1.0) 184 | hue -= 1.0; 185 | float res; 186 | if ((6.0 * hue) < 1.0) 187 | res = f1 + (f2 - f1) * 6.0 * hue; 188 | else if ((2.0 * hue) < 1.0) 189 | res = f2; 190 | else if ((3.0 * hue) < 2.0) 191 | res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; 192 | else 193 | res = f1; 194 | return res; 195 | } 196 | 197 | vec3 hsl2rgb(vec3 hsl) { 198 | vec3 rgb; 199 | 200 | if (hsl.y == 0.0) { 201 | rgb = vec3(hsl.z); // Luminance 202 | } else { 203 | float f2; 204 | 205 | if (hsl.z < 0.5) 206 | f2 = hsl.z * (1.0 + hsl.y); 207 | else 208 | f2 = hsl.z + hsl.y - hsl.y * hsl.z; 209 | 210 | float f1 = 2.0 * hsl.z - f2; 211 | 212 | rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); 213 | rgb.g = hue2rgb(f1, f2, hsl.x); 214 | rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); 215 | } 216 | return rgb; 217 | } 218 | 219 | vec3 hsl2rgb(float h, float s, float l) { 220 | return hsl2rgb(vec3(h, s, l)); 221 | } 222 | 223 | 224 | 225 | 226 | void main () { 227 | float x = vposition.x + 0.02 * sin(vposition.y * 20.0 + time); 228 | float y = vposition.y + 0.02 * sin(vposition.x * 13.0 + time / 3.0); 229 | 230 | float u = fract(10.0 * (x - y)); 231 | float v = fract(10.0 * (x + y)); 232 | 233 | float uc = pow(2.0 * u - 1.0, 6.0); 234 | float uv = pow(2.0 * v - 1.0, 6.0); 235 | 236 | // float final = max(uc, uv); 237 | 238 | vec3 color1 = uc * hsl2rgb(vposition.y, 0.7, 0.5); 239 | vec3 color2 = uv * hsl2rgb(vposition.x, 0.6, 0.7); 240 | 241 | gl_FragColor = vec4(color1 + color2 , 1.0); 242 | } 243 | |] 244 | -------------------------------------------------------------------------------- /Day11/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day11/screenshot.mp4 -------------------------------------------------------------------------------- /Day12/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Html.App 5 | import Random 6 | import Random.Color 7 | import Random.Extra 8 | import Collage 9 | import Color exposing (Color) 10 | import Element 11 | import Time exposing (Time) 12 | import Window 13 | import Task 14 | 15 | 16 | smallShape : Collage.Shape -> Float -> Float -> Float -> Color -> Collage.Form 17 | smallShape shape x y s color = 18 | shape 19 | |> Collage.filled color 20 | |> Collage.scale s 21 | |> Collage.move ( x, y ) 22 | 23 | 24 | withBackground : Color -> List Collage.Form -> Collage.Form 25 | withBackground background content = 26 | Collage.group 27 | [ Collage.rect 750 500 |> Collage.filled background 28 | , Collage.group content 29 | ] 30 | 31 | 32 | shapesArt : 33 | Collage.Shape 34 | -> Int 35 | -> List Color 36 | -> ( Random.Generator Float, Random.Generator Float, Random.Generator Float ) 37 | -> Random.Generator Collage.Form 38 | shapesArt shape n pallette ( xgen, ygen, sgen ) = 39 | Random.map 40 | (List.head pallette |> Maybe.withDefault Color.black |> withBackground) 41 | (Random.list n 42 | (Random.map4 (smallShape shape) 43 | xgen 44 | ygen 45 | sgen 46 | (Random.Extra.sample (List.drop 1 pallette) 47 | |> Random.map (Maybe.withDefault Color.yellow) 48 | ) 49 | ) 50 | ) 51 | 52 | 53 | monochromePalette : Float -> Random.Generator (List Color) 54 | monochromePalette hue = 55 | Random.list 3 56 | (Random.map2 (Color.hsl hue) 57 | (Random.float 0.3 7) 58 | (Random.float 0 1) 59 | ) 60 | 61 | 62 | randomPalette : Random.Generator (List Color) 63 | randomPalette = 64 | Random.Extra.frequency 65 | [ ( 5, Random.list 5 (Random.Color.rgb) ) 66 | , ( 1, Random.list 3 (Random.Color.greyscale) ) 67 | , ( 1, Random.Extra.flatMap monochromePalette (Random.float 0 360) ) 68 | ] 69 | 70 | 71 | randomShape : Float -> Random.Generator Collage.Shape 72 | randomShape size = 73 | Random.Extra.choices 74 | [ Random.Extra.constant <| Collage.square size 75 | , Random.Extra.constant <| Collage.circle size 76 | , Random.Extra.constant <| Collage.ngon 3 size 77 | ] 78 | 79 | 80 | randomArt : Random.Generator Collage.Form 81 | randomArt = 82 | Random.Extra.choices 83 | [ -- Random.map Solid 84 | -- (Random.Color.rgb) 85 | -- , 86 | randomSmallShapesArt 87 | , randomLargeShapesArt 88 | ] 89 | 90 | 91 | randomLargeShapesArt : Random.Generator Collage.Form 92 | randomLargeShapesArt = 93 | Random.Extra.flatMap4 shapesArt 94 | (randomShape 200) 95 | (Random.int 1 3) 96 | randomPalette 97 | (Random.Extra.frequency 98 | [ ( 2 99 | , Random.Extra.constant 100 | ( (Random.float -175 175) 101 | , (Random.float -150 150) 102 | , (Random.float 0.1 3) 103 | ) 104 | ) 105 | ] 106 | ) 107 | 108 | 109 | randomSmallShapesArt : Random.Generator Collage.Form 110 | randomSmallShapesArt = 111 | Random.Extra.flatMap4 shapesArt 112 | (randomShape 20) 113 | (Random.int 1 200) 114 | randomPalette 115 | (Random.Extra.frequency 116 | [ ( 2 117 | , Random.Extra.constant 118 | ( (Random.float -375 375) 119 | , (Random.float -250 250) 120 | , (Random.float 0.1 3) 121 | ) 122 | ) 123 | , ( 1 124 | , Random.Extra.constant 125 | ( (Random.float -375 375) 126 | , (Random.float 0 0) 127 | , (Random.float 0.1 3) 128 | ) 129 | ) 130 | , ( 3 131 | , let 132 | gen p = 133 | ( Random.map (\i -> toFloat i * 375 / toFloat p) (Random.int -p p) 134 | , Random.map (\i -> toFloat i * 250 / toFloat p) (Random.int -p p) 135 | , Random.map (\i -> toFloat i) (Random.int 1 3) 136 | ) 137 | in 138 | Random.map gen (Random.int 1 5) 139 | ) 140 | ] 141 | ) 142 | 143 | 144 | type alias Model = 145 | { art : Collage.Form 146 | , size : Maybe Window.Size 147 | } 148 | 149 | 150 | view : Model -> Html msg 151 | view model = 152 | case model.size of 153 | Nothing -> 154 | Html.text "" 155 | 156 | Just { width, height } -> 157 | Collage.collage width 158 | height 159 | [ model.art ] 160 | |> Element.toHtml 161 | 162 | 163 | type Msg 164 | = NewArt Collage.Form 165 | | Tick Time 166 | | Resize Window.Size 167 | 168 | 169 | update : Msg -> Model -> ( Model, Cmd Msg ) 170 | update msg model = 171 | case msg of 172 | NewArt art -> 173 | ( { model | art = art }, Cmd.none ) 174 | 175 | Tick _ -> 176 | ( model, Random.generate NewArt randomArt ) 177 | 178 | Resize newSize -> 179 | ( { model | size = Just newSize }, Cmd.none ) 180 | 181 | 182 | main : Program Never 183 | main = 184 | Html.App.program 185 | { init = 186 | ( { art = Collage.group [] 187 | , size = Nothing 188 | } 189 | , Cmd.batch 190 | [ Random.generate NewArt randomArt 191 | , Window.size |> Task.perform Resize Resize 192 | ] 193 | ) 194 | , subscriptions = 195 | \_ -> 196 | Sub.batch 197 | [ Time.every 1000 Tick 198 | , Window.resizes Resize 199 | ] 200 | , update = update 201 | , view = view 202 | } 203 | -------------------------------------------------------------------------------- /Day12/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day12/screenshot.gif -------------------------------------------------------------------------------- /Day13/Eye.elm: -------------------------------------------------------------------------------- 1 | module Day13.Eye exposing (Eye, startBlink, view) 2 | 3 | import Collage 4 | import Color exposing (Color) 5 | import Day13.Shapes as Shapes 6 | import Time exposing (Time) 7 | import Animation 8 | import Color.Mixing 9 | 10 | 11 | -- MODEL 12 | 13 | 14 | type alias Eye = 15 | { eyeSize : Float 16 | , irisRatio : Float 17 | , pupilRatio : Float 18 | , blinkStart : Time 19 | , eyelidColor : Color 20 | , irisColor : Color 21 | , whitesColor : Color 22 | } 23 | 24 | 25 | 26 | -- UPDATE 27 | 28 | 29 | startBlink : Time -> Eye -> Eye 30 | startBlink now eye = 31 | { eye | blinkStart = now } 32 | 33 | 34 | 35 | -- VIEW 36 | 37 | 38 | view : Time -> Eye -> Collage.Form 39 | view now model = 40 | let 41 | irisSize = 42 | model.eyeSize * model.irisRatio 43 | 44 | pupilSize = 45 | model.eyeSize * model.irisRatio * model.pupilRatio 46 | 47 | closeAnimation = 48 | Animation.animation model.blinkStart 49 | |> Animation.from 1.0 50 | |> Animation.to 0 51 | |> Animation.duration 200 52 | 53 | openAnimation = 54 | Animation.animation model.blinkStart 55 | |> Animation.from 0.0 56 | |> Animation.to 1.0 57 | |> Animation.duration 200 58 | |> Animation.delay 200 59 | 60 | rotationT = 61 | now / 1000 62 | 63 | opened = 64 | (Animation.animate now closeAnimation) 65 | + (Animation.animate now openAnimation) 66 | in 67 | Collage.group 68 | [ whites model.whitesColor irisSize model.eyeSize 69 | , iris 70 | (Color.Mixing.lighten 0.3 model.irisColor) 71 | model.irisColor 72 | pupilSize 73 | irisSize 74 | (sin rotationT) 75 | (sin (rotationT * 3)) 76 | (sin (rotationT * 1.7)) 77 | , pupil pupilSize 78 | , eyelids model.eyelidColor irisSize model.eyeSize (opened * 0.9) 79 | ] 80 | 81 | 82 | iris : Color -> Color -> Float -> Float -> Float -> Float -> Float -> Collage.Form 83 | iris bgcolor fgcolor pupilRadius size outerOffset midOffset pupilOffset = 84 | let 85 | pointsInCircle = 86 | 40 87 | 88 | midRadius = 89 | (size + pupilRadius) / 2 90 | 91 | circlePoint r i = 92 | ( r * cos (degrees <| i * 360 / pointsInCircle) 93 | , r * sin (degrees <| i * 360 / pointsInCircle) 94 | ) 95 | 96 | makeLine size midRadius outerOffset outerIndex innerOffset innerIndex = 97 | Collage.segment 98 | (circlePoint size (outerIndex + outerOffset)) 99 | (circlePoint midRadius (innerIndex + innerOffset)) 100 | |> Collage.traced (Collage.solid fgcolor) 101 | 102 | makeLines size midRadius outerOffset innerOffset outerIndex = 103 | [(outerIndex)..(outerIndex + 5)] 104 | |> List.map (makeLine size midRadius outerOffset outerIndex innerOffset) 105 | |> Collage.group 106 | 107 | makeRing size midRadius outerOffset innerOffset = 108 | [0..pointsInCircle] 109 | |> List.map (makeLines size midRadius outerOffset innerOffset) 110 | |> Collage.group 111 | in 112 | Collage.group 113 | [ Collage.circle size 114 | |> Collage.filled bgcolor 115 | , makeRing size midRadius outerOffset midOffset 116 | , makeRing midRadius pupilRadius midOffset pupilOffset 117 | ] 118 | 119 | 120 | pupil : Float -> Collage.Form 121 | pupil size = 122 | Collage.circle size 123 | |> Collage.filled Color.black 124 | 125 | 126 | whites : Color -> Float -> Float -> Collage.Form 127 | whites color height width = 128 | Collage.polygon 129 | (Shapes.curve ( width, 0 ) ( 0, (height * 2) ) ( -width, 0 ) 20 130 | ++ Shapes.curve ( -width, 0 ) ( 0, -(height * 2) ) ( width, 0 ) 20 131 | ) 132 | |> Collage.filled color 133 | 134 | 135 | eyelids : Color -> Float -> Float -> Float -> Collage.Form 136 | eyelids color height width opened = 137 | Collage.group 138 | [ Collage.polygon 139 | (Shapes.curve ( -width, 0 ) ( 0, (height * 2 * opened) ) ( width, 0 ) 20 140 | ++ Shapes.curve ( width, 0 ) ( 0, (height * 2) ) ( -width, 0 ) 20 141 | ) 142 | |> Collage.filled color 143 | , Collage.polygon 144 | (Shapes.curve ( -width, 0 ) ( 0, -(height * 2) ) ( width, 0 ) 20 145 | ++ Shapes.curve ( width, 0 ) ( 0, -(height * 2 * opened) ) ( -width, 0 ) 20 146 | ) 147 | |> Collage.filled color 148 | ] 149 | -------------------------------------------------------------------------------- /Day13/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Collage 4 | import Element 5 | import Day13.Eye as Eye exposing (Eye) 6 | import Day13.TrippyBackground as TrippyBackground 7 | import Html exposing (Html) 8 | import Html.App 9 | import Html.Attributes 10 | import Time exposing (Time) 11 | import Random 12 | import Random.Extra 13 | import Color exposing (Color) 14 | import Animation 15 | import AnimationFrame 16 | 17 | 18 | appearTime : Float 19 | appearTime = 20 | 2000 21 | 22 | 23 | type alias Model = 24 | { eyes : List ( ( Float, Float ), Eye ) 25 | , disappearingEye : Maybe ( Time, ( Float, Float ), Eye ) 26 | , appearingEye : Maybe ( Time, ( Float, Float ), Eye ) 27 | , now : Time 28 | } 29 | 30 | 31 | initialModel : Model 32 | initialModel = 33 | { eyes = [] 34 | , disappearingEye = Nothing 35 | , appearingEye = Nothing 36 | , now = 0 37 | } 38 | 39 | 40 | type Msg 41 | = Tick Time 42 | | StartBlink 43 | | ChangeEye 44 | | ResetEyes (List ( ( Float, Float ), Eye )) 45 | | NewEye ( ( Float, Float ), Eye ) 46 | 47 | 48 | promoteAppearingEye : Model -> Model 49 | promoteAppearingEye model = 50 | case model.appearingEye of 51 | Nothing -> 52 | model 53 | 54 | Just ( startTime, ( x, y ), eye ) -> 55 | if startTime + appearTime <= model.now then 56 | { model 57 | | appearingEye = Nothing 58 | , eyes = model.eyes ++ [ ( ( x, y ), eye ) ] 59 | } 60 | else 61 | model 62 | 63 | 64 | update : Msg -> Model -> ( Model, Cmd Msg ) 65 | update msg model = 66 | case msg of 67 | Tick diff -> 68 | ( { model | now = model.now + diff } 69 | |> promoteAppearingEye 70 | , Cmd.none 71 | ) 72 | 73 | StartBlink -> 74 | ( { model 75 | | eyes = 76 | List.map (\( p, eye ) -> ( p, Eye.startBlink model.now eye )) 77 | model.eyes 78 | } 79 | , Cmd.none 80 | ) 81 | 82 | ResetEyes eyes -> 83 | ( { model | eyes = eyes } 84 | , Cmd.none 85 | ) 86 | 87 | NewEye ( ( x, y ), eye ) -> 88 | ( { model | appearingEye = Just ( model.now, ( x, y ), eye ) } 89 | , Cmd.none 90 | ) 91 | 92 | ChangeEye -> 93 | case model.eyes of 94 | [] -> 95 | ( model, Cmd.none ) 96 | 97 | ( point, eye ) :: rest -> 98 | ( { model 99 | | disappearingEye = Just ( model.now, point, eye ) 100 | , eyes = rest 101 | } 102 | , Random.generate NewEye randomEye 103 | ) 104 | 105 | 106 | view : Model -> Html msg 107 | view model = 108 | Html.div [ Html.Attributes.style [ ( "position", "relative" ) ] ] 109 | [ Html.div [ Html.Attributes.style [ ( "position", "absolute" ) ] ] 110 | [ TrippyBackground.view 750 500 (model.now / 1000) ] 111 | , Html.div [ Html.Attributes.style [ ( "position", "absolute" ) ] ] 112 | [ eyesView model ] 113 | ] 114 | 115 | 116 | eyesView : Model -> Html msg 117 | eyesView model = 118 | [ case model.disappearingEye of 119 | Nothing -> 120 | Collage.group [] 121 | 122 | Just ( startTime, ( x, y ), eye ) -> 123 | let 124 | alphaAnimation = 125 | Animation.animation startTime 126 | |> Animation.from 1.0 127 | |> Animation.to 0.0 128 | |> Animation.duration 2000 129 | in 130 | if Animation.isDone model.now alphaAnimation then 131 | Collage.group [] 132 | else 133 | Eye.view model.now eye 134 | |> Collage.scale (0.7 + 0.3 * Animation.animate model.now alphaAnimation) 135 | |> Collage.move ( x, y ) 136 | |> Collage.alpha 137 | (Animation.animate model.now alphaAnimation) 138 | , model.eyes 139 | |> List.map 140 | (\( ( x, y ), eye ) -> 141 | Eye.view model.now eye 142 | |> Collage.move ( x, y ) 143 | ) 144 | |> Collage.group 145 | , case model.appearingEye of 146 | Nothing -> 147 | Collage.group [] 148 | 149 | Just ( startTime, ( x, y ), eye ) -> 150 | let 151 | alphaAnimation = 152 | Animation.animation startTime 153 | |> Animation.from 0.0 154 | |> Animation.to 1.0 155 | |> Animation.duration appearTime 156 | in 157 | if Animation.isScheduled model.now alphaAnimation then 158 | Collage.group [] 159 | else 160 | Eye.view model.now eye 161 | |> Collage.scale (0.7 + 0.3 * Animation.animate model.now alphaAnimation) 162 | |> Collage.move ( x, y ) 163 | |> Collage.alpha 164 | (alphaAnimation |> Animation.animate model.now) 165 | ] 166 | |> Collage.collage 750 500 167 | |> Element.toHtml 168 | 169 | 170 | map7 : 171 | (a -> b -> c -> d -> e -> f -> g -> h) 172 | -> Random.Generator a 173 | -> Random.Generator b 174 | -> Random.Generator c 175 | -> Random.Generator d 176 | -> Random.Generator e 177 | -> Random.Generator f 178 | -> Random.Generator g 179 | -> Random.Generator h 180 | map7 f genA genB genC genD genE genF genG = 181 | Random.Extra.map6 f genA genB genC genD genE genF 182 | |> flip Random.Extra.andMap genG 183 | 184 | 185 | whitesColorGenerator : Random.Generator Color 186 | whitesColorGenerator = 187 | Random.map3 Color.hsl 188 | (Random.float (degrees -50) (degrees 60)) 189 | (Random.float 0 1) 190 | (Random.float 0.9 1.0) 191 | 192 | 193 | irisColorGenerator : Random.Generator Color 194 | irisColorGenerator = 195 | Random.map3 Color.hsl 196 | (Random.float (degrees 0) (degrees 360)) 197 | (Random.float 0.5 0.7) 198 | (Random.float 0.1 0.7) 199 | 200 | 201 | skinColorGenerator : Random.Generator Color 202 | skinColorGenerator = 203 | Random.map3 Color.hsl 204 | (Random.float (degrees 25) (degrees 45)) 205 | (Random.Extra.constant 0.55) 206 | (Random.float 0.2 0.7) 207 | 208 | 209 | randomEye : Random.Generator ( ( Float, Float ), Eye ) 210 | randomEye = 211 | Random.map2 (,) 212 | (Random.map2 (,) (Random.float -250 250) (Random.float -150 150)) 213 | (map7 Eye 214 | (Random.float 50 250) 215 | (Random.float 0.2 0.7) 216 | (Random.float 0.2 0.8) 217 | (Random.Extra.constant 0) 218 | skinColorGenerator 219 | irisColorGenerator 220 | whitesColorGenerator 221 | ) 222 | 223 | 224 | main : Program Never 225 | main = 226 | Html.App.program 227 | { init = 228 | ( initialModel 229 | , Random.generate ResetEyes (Random.list 3 randomEye) 230 | ) 231 | , subscriptions = 232 | \_ -> 233 | Sub.batch 234 | [ AnimationFrame.diffs Tick 235 | , Time.every 3000 (always StartBlink) 236 | , Time.every 10000 (always ChangeEye) 237 | ] 238 | , update = update 239 | , view = view 240 | } 241 | -------------------------------------------------------------------------------- /Day13/Shapes.elm: -------------------------------------------------------------------------------- 1 | module Day13.Shapes exposing (curve) 2 | 3 | 4 | type alias Point = 5 | ( Float, Float ) 6 | 7 | 8 | curve : Point -> Point -> Point -> Float -> List ( Float, Float ) 9 | curve start control end n = 10 | let 11 | ( start_x, start_y ) = 12 | start 13 | 14 | ( control_x, control_y ) = 15 | control 16 | 17 | ( end_x, end_y ) = 18 | end 19 | 20 | x t = 21 | ((1 - t) * (1 - t) * start_x) 22 | + (2 * (1 - t) * t * control_x) 23 | + (t * t * end_x) 24 | 25 | y t = 26 | ((1 - t) * (1 - t) * start_y) 27 | + (2 * (1 - t) * t * control_y) 28 | + (t * t * end_y) 29 | in 30 | [0..n] 31 | |> List.map (\i -> ( x (i / n), y (i / n) )) 32 | -------------------------------------------------------------------------------- /Day13/TrippyBackground.elm: -------------------------------------------------------------------------------- 1 | module Day13.TrippyBackground exposing (view) 2 | 3 | import Html.Attributes 4 | import WebGL 5 | import Math.Vector3 exposing (..) 6 | import Math.Matrix4 exposing (..) 7 | import WebGL exposing (..) 8 | import Html.Attributes exposing (width, height) 9 | 10 | 11 | type alias VertexAttributes = 12 | { position : Vec3 13 | } 14 | 15 | 16 | type alias Uniforms = 17 | { camera : Mat4 18 | , time : Float 19 | } 20 | 21 | 22 | type alias Varyings = 23 | { vposition : Vec3 } 24 | 25 | 26 | view w h t = 27 | scene t 28 | |> WebGL.toHtml [ width w, height h ] 29 | 30 | 31 | 32 | -- MESHES - create a cube in which each vertex has a position and color 33 | 34 | 35 | cube : Drawable VertexAttributes 36 | cube = 37 | let 38 | rft = 39 | vec3 1 1 0 40 | 41 | lft = 42 | vec3 -1 1 0 43 | 44 | lbt = 45 | vec3 -1 -1 0 46 | 47 | rbt = 48 | vec3 1 -1 0 49 | in 50 | Triangle 51 | << List.concat 52 | <| 53 | [ face rft lft lbt rbt 54 | ] 55 | 56 | 57 | face : Vec3 -> Vec3 -> Vec3 -> Vec3 -> List ( VertexAttributes, VertexAttributes, VertexAttributes ) 58 | face a b c d = 59 | let 60 | vertex position = 61 | VertexAttributes position 62 | in 63 | [ ( vertex a, vertex b, vertex c ) 64 | , ( vertex c, vertex d, vertex a ) 65 | ] 66 | 67 | 68 | 69 | -- VIEW 70 | 71 | 72 | scene : Float -> List Renderable 73 | scene t = 74 | [ render vertexShader fragmentShader cube (uniforms t) ] 75 | 76 | 77 | uniforms : Float -> Uniforms 78 | uniforms t = 79 | { camera = makeOrtho2D 0 1 0 0.66666 80 | , time = t 81 | } 82 | 83 | 84 | 85 | -- SHADERS 86 | 87 | 88 | vertexShader : Shader VertexAttributes Uniforms Varyings 89 | vertexShader = 90 | [glsl| 91 | 92 | attribute vec3 position; 93 | 94 | uniform mat4 camera; 95 | 96 | varying vec3 vposition; 97 | 98 | void main () { 99 | gl_Position = camera * vec4(position, 1.0); 100 | vposition = position; 101 | } 102 | 103 | |] 104 | 105 | 106 | fragmentShader : WebGL.Shader {} Uniforms Varyings 107 | fragmentShader = 108 | [glsl| 109 | 110 | precision mediump float; 111 | 112 | uniform float time; 113 | 114 | varying vec3 vposition; 115 | 116 | float hue2rgb(float f1, float f2, float hue) { 117 | if (hue < 0.0) 118 | hue += 1.0; 119 | else if (hue > 1.0) 120 | hue -= 1.0; 121 | float res; 122 | if ((6.0 * hue) < 1.0) 123 | res = f1 + (f2 - f1) * 6.0 * hue; 124 | else if ((2.0 * hue) < 1.0) 125 | res = f2; 126 | else if ((3.0 * hue) < 2.0) 127 | res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; 128 | else 129 | res = f1; 130 | return res; 131 | } 132 | 133 | vec3 hsl2rgb(vec3 hsl) { 134 | vec3 rgb; 135 | 136 | if (hsl.y == 0.0) { 137 | rgb = vec3(hsl.z); // Luminance 138 | } else { 139 | float f2; 140 | 141 | if (hsl.z < 0.5) 142 | f2 = hsl.z * (1.0 + hsl.y); 143 | else 144 | f2 = hsl.z + hsl.y - hsl.y * hsl.z; 145 | 146 | float f1 = 2.0 * hsl.z - f2; 147 | 148 | rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); 149 | rgb.g = hue2rgb(f1, f2, hsl.x); 150 | rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); 151 | } 152 | return rgb; 153 | } 154 | 155 | vec3 hsl2rgb(float h, float s, float l) { 156 | return hsl2rgb(vec3(h, s, l)); 157 | } 158 | 159 | 160 | 161 | 162 | void main () { 163 | float x = vposition.x + 0.02 * sin(vposition.y * 20.0 + time); 164 | float y = vposition.y + 0.02 * sin(vposition.x * 13.0 + time / 3.0); 165 | 166 | float u = fract(10.0 * (x - y)); 167 | float v = fract(10.0 * (x + y)); 168 | 169 | float uc = pow(2.0 * u - 1.0, 6.0); 170 | float uv = pow(2.0 * v - 1.0, 6.0); 171 | 172 | // float final = max(uc, uv); 173 | 174 | vec3 color1 = uc * hsl2rgb(vposition.y, 0.7, 0.5); 175 | vec3 color2 = uv * hsl2rgb(vposition.x, 0.6, 0.7); 176 | 177 | gl_FragColor = vec4(color1 + color2 , 1.0); 178 | } 179 | |] 180 | -------------------------------------------------------------------------------- /Day13/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day13/screenshot.mp4 -------------------------------------------------------------------------------- /Day14/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Html.App 5 | import Html.Events 6 | import Html.Attributes 7 | import Color exposing (Color) 8 | import Time exposing (Time) 9 | import Collage 10 | import Element 11 | import AnimationFrame 12 | import Day14.TileGrid as TileGrid 13 | import Random 14 | import Random.Extra 15 | 16 | 17 | type alias Model = 18 | { tileGrid : TileGrid.Model 19 | , now : Time 20 | } 21 | 22 | 23 | initialModel : Model 24 | initialModel = 25 | { tileGrid = TileGrid.init [ Color.red, Color.green, Color.blue, Color.orange, Color.brown ] 26 | , now = 0 27 | } 28 | 29 | 30 | type Msg 31 | = Tick Time 32 | | NewColors 33 | | ChangeColors (List Color) 34 | 35 | 36 | randomColor : Random.Generator Color 37 | randomColor = 38 | Random.Extra.choices 39 | [ Random.Extra.constant Color.red 40 | , Random.Extra.constant Color.blue 41 | , Random.Extra.constant Color.green 42 | , Random.Extra.constant Color.yellow 43 | , Random.Extra.constant Color.orange 44 | , Random.Extra.constant Color.purple 45 | , Random.Extra.constant Color.charcoal 46 | , Random.Extra.constant Color.brown 47 | ] 48 | 49 | 50 | update : Msg -> Model -> ( Model, Cmd Msg ) 51 | update msg model = 52 | case msg of 53 | Tick now -> 54 | ( { model 55 | | now = now 56 | , tileGrid = TileGrid.update now model.tileGrid 57 | } 58 | , Cmd.none 59 | ) 60 | 61 | NewColors -> 62 | ( model 63 | , Random.generate ChangeColors (Random.list 3 randomColor) 64 | ) 65 | 66 | ChangeColors newColors -> 67 | ( { model 68 | | tileGrid = 69 | TileGrid.changeColors model.now 70 | newColors 71 | model.tileGrid 72 | } 73 | , Cmd.none 74 | ) 75 | 76 | 77 | view : Model -> Html Msg 78 | view model = 79 | Html.div [] 80 | [ Html.button [ Html.Events.onClick NewColors, Html.Attributes.style [ ( "font-size", "300%" ) ] ] [ Html.text "Flip!" ] 81 | , [ TileGrid.view model.now model.tileGrid ] 82 | |> Collage.collage 750 400 83 | |> Element.toHtml 84 | ] 85 | 86 | 87 | main : Program Never 88 | main = 89 | Html.App.program 90 | { init = ( initialModel, Cmd.none ) 91 | , subscriptions = \_ -> AnimationFrame.times Tick 92 | , update = update 93 | , view = view 94 | } 95 | -------------------------------------------------------------------------------- /Day14/TileGrid.elm: -------------------------------------------------------------------------------- 1 | module Day14.TileGrid exposing (Model, init, changeColors, update, view) 2 | 3 | import Color exposing (Color) 4 | import Collage 5 | import Dict exposing (Dict) 6 | import Time exposing (Time) 7 | import Fifo exposing (Fifo) 8 | import Animation 9 | import Array 10 | import Random 11 | import Random.Array 12 | 13 | 14 | outAnimation startTime = 15 | Animation.animation startTime 16 | |> Animation.from 1.0 17 | |> Animation.to 0.0 18 | |> Animation.duration 400 19 | 20 | 21 | inAnimation startTime = 22 | Animation.animation startTime 23 | |> Animation.from 0.0 24 | |> Animation.to 1.0 25 | |> Animation.duration 400 26 | |> Animation.delay 400 27 | 28 | 29 | type Model 30 | = Model 31 | { tiles : Dict ( Int, Int ) Color 32 | , currentAnimations : Dict ( Int, Int ) ( Time, Color ) 33 | , pendingAnimations : Fifo ( ( Int, Int ), Color ) 34 | , lastStartTime : Time 35 | } 36 | 37 | 38 | fold : (Int -> Int -> a -> a) -> a -> a 39 | fold step initial = 40 | let 41 | foldRow y acc = 42 | List.foldl (step y) acc [-2..2] 43 | in 44 | List.foldl foldRow initial [-2..2] 45 | 46 | 47 | init : List Color -> Model 48 | init colors = 49 | let 50 | colorFor x y = 51 | colors 52 | |> List.drop ((x + y) % List.length colors) 53 | |> List.head 54 | |> Maybe.withDefault Color.black 55 | 56 | insertTile y x dict = 57 | Dict.insert ( x, y ) (colorFor x y) dict 58 | in 59 | Model 60 | { tiles = 61 | fold insertTile Dict.empty 62 | , pendingAnimations = Fifo.empty 63 | , currentAnimations = Dict.empty 64 | , lastStartTime = 0 65 | } 66 | 67 | 68 | changeColors : Time -> List Color -> Model -> Model 69 | changeColors now newColors (Model model) = 70 | let 71 | colorFor x y = 72 | newColors 73 | |> List.drop ((x + y) % List.length newColors) 74 | |> List.head 75 | |> Maybe.withDefault Color.black 76 | 77 | newAnimations = 78 | fold 79 | (\x y acc -> Array.push ( ( x, y ), colorFor x y ) acc) 80 | Array.empty 81 | 82 | ( shuffledAnimations, newSeed ) = 83 | Random.step (Random.Array.shuffle newAnimations) 84 | (Random.initialSeed <| floor now) 85 | in 86 | Model 87 | { model 88 | | pendingAnimations = 89 | Array.foldl 90 | Fifo.insert 91 | model.pendingAnimations 92 | shuffledAnimations 93 | } 94 | |> startNewAnimations now 95 | 96 | 97 | startNextTileAnimation : Time -> Model -> Model 98 | startNextTileAnimation now (Model model) = 99 | case Fifo.remove model.pendingAnimations of 100 | ( Just ( ( x, y ), newColor ), remainingPendingsAnimations ) -> 101 | if Dict.member ( x, y ) model.currentAnimations then 102 | -- Don't start a new animation for a tile that is currently animating 103 | (Model model) 104 | else 105 | Model 106 | { model 107 | | currentAnimations = 108 | Dict.insert ( x, y ) ( now, newColor ) model.currentAnimations 109 | , pendingAnimations = remainingPendingsAnimations 110 | } 111 | 112 | ( Nothing, remainingPendingsAnimations ) -> 113 | Model { model | pendingAnimations = remainingPendingsAnimations } 114 | 115 | 116 | clearFinishedAnimations : Time -> Model -> Model 117 | clearFinishedAnimations now (Model model) = 118 | let 119 | isDone key ( startTime, newColor ) = 120 | Animation.isDone now (inAnimation startTime) 121 | 122 | ( finishedAnimations, remainingAnimations ) = 123 | Dict.partition isDone model.currentAnimations 124 | 125 | finalizeColor ( x, y ) ( startTime, newColor ) acc = 126 | Dict.insert ( x, y ) newColor acc 127 | in 128 | Model 129 | { model 130 | | currentAnimations = remainingAnimations 131 | , tiles = Dict.foldl finalizeColor model.tiles finishedAnimations 132 | } 133 | 134 | 135 | startNewAnimations : Time -> Model -> Model 136 | startNewAnimations now (Model model) = 137 | if model.lastStartTime + 100 < now then 138 | Model { model | lastStartTime = now } 139 | |> startNextTileAnimation now 140 | |> startNextTileAnimation now 141 | |> startNextTileAnimation now 142 | else 143 | Model model 144 | 145 | 146 | update : Time -> Model -> Model 147 | update now (Model model) = 148 | (Model model) 149 | |> clearFinishedAnimations now 150 | |> startNewAnimations now 151 | 152 | 153 | viewTile : Time -> Maybe ( Time, Color ) -> Color -> Collage.Form 154 | viewTile now animation color = 155 | case animation of 156 | Nothing -> 157 | Collage.square 60 158 | |> Collage.filled color 159 | 160 | Just ( startTime, newColor ) -> 161 | Collage.group 162 | [ let 163 | h = 164 | 30 * (Animation.animate now <| outAnimation startTime) 165 | 166 | fw = 167 | 30 + 7 * (cos <| degrees 90 * (Animation.animate now <| outAnimation startTime)) 168 | 169 | bw = 170 | 30 - 7 * (cos <| degrees 90 * (Animation.animate now <| outAnimation startTime)) 171 | in 172 | Collage.polygon [ ( -fw, -h ), ( -bw, h ), ( bw, h ), ( fw, -h ) ] 173 | |> Collage.filled color 174 | , let 175 | h = 176 | 30 * (Animation.animate now <| inAnimation startTime) 177 | 178 | fw = 179 | 30 - 7 * (cos <| degrees 90 * (Animation.animate now <| inAnimation startTime)) 180 | 181 | bw = 182 | 30 + 7 * (cos <| degrees 90 * (Animation.animate now <| inAnimation startTime)) 183 | in 184 | Collage.polygon [ ( -fw, -h ), ( -bw, h ), ( bw, h ), ( fw, -h ) ] |> Collage.filled newColor 185 | ] 186 | 187 | 188 | view : Time -> Model -> Collage.Form 189 | view now (Model model) = 190 | let 191 | tile y x = 192 | model.tiles 193 | |> Dict.get ( x, y ) 194 | |> Maybe.map (viewTile now (Dict.get ( x, y ) model.currentAnimations)) 195 | |> Maybe.withDefault (Collage.group []) 196 | |> Collage.move ( toFloat x * 70, 0 ) 197 | 198 | tileRow y = 199 | [-2..2] 200 | |> List.map (tile y) 201 | |> Collage.group 202 | |> Collage.move ( 0, toFloat y * 70 ) 203 | in 204 | [-2..2] 205 | |> List.map tileRow 206 | |> Collage.group 207 | -------------------------------------------------------------------------------- /Day14/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day14/screenshot.gif -------------------------------------------------------------------------------- /Day15/Main.elm: -------------------------------------------------------------------------------- 1 | port module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Html.App 5 | import Html.Events 6 | import Html.Attributes 7 | import Color exposing (Color) 8 | import Time exposing (Time) 9 | import Collage 10 | import Element 11 | import AnimationFrame 12 | import Day14.TileGrid as TileGrid 13 | import Random 14 | import Random.Extra 15 | import Json.Decode 16 | 17 | 18 | port requestImageColors : String -> Cmd msg 19 | 20 | 21 | port imageColorResults : (List ( Int, Int, Int ) -> msg) -> Sub msg 22 | 23 | 24 | type alias Model = 25 | { tileGrid : TileGrid.Model 26 | , now : Time 27 | , colorImage : String 28 | , silhouetteImage : String 29 | } 30 | 31 | 32 | imageSet : List ( String, String ) 33 | imageSet = 34 | [ ( "rhino-color.jpg", "rhino-silhoutte.png" ) 35 | , ( "crow-color.jpg", "crow-silhouette.png" ) 36 | , ( "fish-color.jpg", "fish-silhouette.png" ) 37 | , ( "dragon-color.jpg", "dragon-silhouette.png" ) 38 | , ( "quill-color.png", "quill-silhouette.png" ) 39 | , ( "reindeer-color.jpg", "reindeer-silhouette.png" ) 40 | , ( "saxophone-color.jpg", "saxophone-silhouette.png" ) 41 | , ( "stork-color.jpg", "stork-silhouette.png" ) 42 | , ( "tea-color.jpg", "tea-silhouette.png" ) 43 | , ( "swan-color.jpg", "swan-silhouette.png" ) 44 | , ( "unicorn-color.jpg", "unicorn-silhouette.png" ) 45 | , ( "beard-color.jpg", "beard-silhouette.png" ) 46 | ] 47 | 48 | 49 | initialModel : Model 50 | initialModel = 51 | { tileGrid = TileGrid.init [ Color.grey ] 52 | , now = 0 53 | , colorImage = "rhino-color.jpg" 54 | , silhouetteImage = "rhino-silhoutte.png" 55 | } 56 | 57 | 58 | type Msg 59 | = Tick Time 60 | | NewColors 61 | | ChangeColors (List Color) 62 | | ColorImageLoaded 63 | | AnalyzedColors (List ( Int, Int, Int )) 64 | | NewImage Time 65 | | ChangeImage (Maybe ( String, String )) 66 | 67 | 68 | randomColor : Random.Generator Color 69 | randomColor = 70 | Random.Extra.choices 71 | [ Random.Extra.constant Color.red 72 | , Random.Extra.constant Color.blue 73 | , Random.Extra.constant Color.green 74 | , Random.Extra.constant Color.yellow 75 | , Random.Extra.constant Color.orange 76 | , Random.Extra.constant Color.purple 77 | , Random.Extra.constant Color.charcoal 78 | , Random.Extra.constant Color.brown 79 | ] 80 | 81 | 82 | update : Msg -> Model -> ( Model, Cmd Msg ) 83 | update msg model = 84 | case msg of 85 | Tick now -> 86 | ( { model 87 | | now = now 88 | , tileGrid = TileGrid.update now model.tileGrid 89 | } 90 | , Cmd.none 91 | ) 92 | 93 | NewColors -> 94 | ( model 95 | , Random.generate ChangeColors (Random.list 3 randomColor) 96 | ) 97 | 98 | NewImage now -> 99 | ( model 100 | , Random.generate ChangeImage (Random.Extra.sample imageSet) 101 | ) 102 | 103 | ChangeColors newColors -> 104 | ( { model 105 | | tileGrid = 106 | TileGrid.changeColors model.now 107 | newColors 108 | model.tileGrid 109 | } 110 | , Cmd.none 111 | ) 112 | 113 | ChangeImage Nothing -> 114 | ( model, Cmd.none ) 115 | 116 | ChangeImage (Just ( colorImage, silhouetteImage )) -> 117 | ( { model | colorImage = colorImage, silhouetteImage = silhouetteImage } 118 | , Cmd.none 119 | ) 120 | 121 | ColorImageLoaded -> 122 | ( model 123 | , requestImageColors "mainImage" 124 | ) 125 | 126 | AnalyzedColors rgbTuples -> 127 | let 128 | newColors = 129 | rgbTuples 130 | |> List.map (\( r, g, b ) -> Color.rgb r g b) 131 | in 132 | update (ChangeColors newColors) model 133 | 134 | 135 | view : Model -> Html Msg 136 | view model = 137 | Html.div 138 | [ Html.Attributes.style 139 | [ ( "position", "relative" ) 140 | , ( "width", "750px" ) 141 | , ( "height", "500px" ) 142 | ] 143 | ] 144 | [ Html.img 145 | [ Html.Attributes.style [ ( "display", "none" ) ] 146 | , Html.Attributes.id "mainImage" 147 | , Html.Attributes.src model.colorImage 148 | , Html.Events.on "load" (Json.Decode.succeed ColorImageLoaded) 149 | ] 150 | [] 151 | , Html.div [ Html.Attributes.style [ ( "position", "absolute" ) ] ] 152 | [ Element.layers 153 | [ [ TileGrid.view model.now model.tileGrid 154 | |> Collage.rotate (degrees 45) 155 | ] 156 | |> Collage.collage 750 500 157 | ] 158 | |> Element.toHtml 159 | ] 160 | , Html.div 161 | [ Html.Attributes.style 162 | [ ( "position", "absolute" ) 163 | , ( "width", "280px" ) 164 | , ( "height", "250px" ) 165 | , ( "top", "50%" ) 166 | , ( "left", "50%" ) 167 | , ( "transform", "translateX(-50%) translateY(-50%)" ) 168 | ] 169 | ] 170 | [ Html.img 171 | [ Html.Attributes.style 172 | [ ( "margin", "auto" ) 173 | , ( "position", "absolute" ) 174 | , ( "top", "50%" ) 175 | , ( "left", "50%" ) 176 | , ( "object-fit", "contain" ) 177 | , ( "transform", "translateX(-50%) translateY(-50%)" ) 178 | , ( "max-width", "100%" ) 179 | , ( "max-height", "100%" ) 180 | , ( "-webkit-filter", "drop-shadow(0 0 50px rgba(255,255,255,1.0))" ) 181 | ] 182 | , Html.Attributes.src model.silhouetteImage 183 | , Html.Attributes.width 300 184 | ] 185 | [] 186 | ] 187 | ] 188 | 189 | 190 | main : Program Never 191 | main = 192 | Html.App.program 193 | { init = ( initialModel, Cmd.none ) 194 | , subscriptions = 195 | \_ -> 196 | Sub.batch 197 | [ AnimationFrame.times Tick 198 | , imageColorResults AnalyzedColors 199 | , Time.every 5000 NewImage 200 | ] 201 | , update = update 202 | , view = view 203 | } 204 | -------------------------------------------------------------------------------- /Day15/beard-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/beard-color.jpg -------------------------------------------------------------------------------- /Day15/beard-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/beard-silhouette.png -------------------------------------------------------------------------------- /Day15/color-thief.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Color Thief v2.0 3 | * by Lokesh Dhakar - http://www.lokeshdhakar.com 4 | * 5 | * Thanks 6 | * ------ 7 | * Nick Rabinowitz - For creating quantize.js. 8 | * John Schulz - For clean up and optimization. @JFSIII 9 | * Nathan Spady - For adding drag and drop support to the demo page. 10 | * 11 | * License 12 | * ------- 13 | * Copyright 2011, 2015 Lokesh Dhakar 14 | * Released under the MIT license 15 | * https://raw.githubusercontent.com/lokesh/color-thief/master/LICENSE 16 | * 17 | * @license 18 | */ 19 | var CanvasImage=function(a){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),document.body.appendChild(this.canvas),this.width=this.canvas.width=a.width,this.height=this.canvas.height=a.height,this.context.drawImage(a,0,0,this.width,this.height)};CanvasImage.prototype.clear=function(){this.context.clearRect(0,0,this.width,this.height)},CanvasImage.prototype.update=function(a){this.context.putImageData(a,0,0)},CanvasImage.prototype.getPixelCount=function(){return this.width*this.height},CanvasImage.prototype.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)},CanvasImage.prototype.removeCanvas=function(){this.canvas.parentNode.removeChild(this.canvas)};var ColorThief=function(){};/*! 20 | * quantize.js Copyright 2008 Nick Rabinowitz. 21 | * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 22 | * @license 23 | */ 24 | /*! 25 | * Block below copied from Protovis: http://mbostock.github.com/protovis/ 26 | * Copyright 2010 Stanford Visualization Group 27 | * Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php 28 | * @license 29 | */ 30 | if(ColorThief.prototype.getColor=function(a,b){var c=this.getPalette(a,5,b),d=c[0];return d},ColorThief.prototype.getPalette=function(a,b,c){"undefined"==typeof b&&(b=10),("undefined"==typeof c||c<1)&&(c=10);for(var d,e,f,g,h,i=new CanvasImage(a),j=i.getImageData(),k=j.data,l=i.getPixelCount(),m=[],n=0;n=125&&(e>250&&f>250&&g>250||m.push([e,f,g]));var o=MMCQ.quantize(m,b),p=o?o.palette():null;return i.removeCanvas(),p},!pv)var pv={map:function(a,b){var c={};return b?a.map(function(a,d){return c.index=d,b.call(c,a)}):a.slice()},naturalOrder:function(a,b){return ab?1:0},sum:function(a,b){var c={};return a.reduce(b?function(a,d,e){return c.index=e,a+b.call(c,d)}:function(a,b){return a+b},0)},max:function(a,b){return Math.max.apply(null,b?pv.map(a,b):a)}};var MMCQ=function(){function a(a,b,c){return(a<<2*i)+(b<>j,e=b[1]>>j,f=b[2]>>j,c=a(d,e,f),h[c]=(h[c]||0)+1}),h}function f(a,b){var d,e,f,g=1e6,h=0,i=1e6,k=0,l=1e6,m=0;return a.forEach(function(a){d=a[0]>>j,e=a[1]>>j,f=a[2]>>j,dh&&(h=d),ek&&(k=e),fm&&(m=f)}),new c(g,h,i,k,l,m,b)}function g(b,c){function d(a){var b,d,e,f,g,h=a+"1",j=a+"2",k=0;for(i=c[h];i<=c[j];i++)if(o[i]>n/2){for(e=c.copy(),f=c.copy(),b=i-c[h],d=c[j]-i,g=b<=d?Math.min(c[j]-1,~~(i+d/2)):Math.max(c[h],~~(i-1-b/2));!o[g];)g++;for(k=p[g];!k&&o[g-1];)k=p[--g];return e[j]=g,f[h]=e[j]+1,[e,f]}}if(c.count()){var e=c.r2-c.r1+1,f=c.g2-c.g1+1,g=c.b2-c.b1+1,h=pv.max([e,f,g]);if(1==c.count())return[c.copy()];var i,j,k,l,m,n=0,o=[],p=[];if(h==e)for(i=c.r1;i<=c.r2;i++){for(l=0,j=c.g1;j<=c.g2;j++)for(k=c.b1;k<=c.b2;k++)m=a(i,j,k),l+=b[m]||0;n+=l,o[i]=n}else if(h==f)for(i=c.g1;i<=c.g2;i++){for(l=0,j=c.r1;j<=c.r2;j++)for(k=c.b1;k<=c.b2;k++)m=a(j,i,k),l+=b[m]||0;n+=l,o[i]=n}else for(i=c.b1;i<=c.b2;i++){for(l=0,j=c.r1;j<=c.r2;j++)for(k=c.g1;k<=c.g2;k++)m=a(j,k,i),l+=b[m]||0;n+=l,o[i]=n}return o.forEach(function(a,b){p[b]=n-a}),d(h==e?"r":h==f?"g":"b")}}function h(a,c){function h(a,b){for(var c,d=1,e=0;e=b)return;if(e++>k)return}else a.push(c),e++}if(!a.length||c<2||c>256)return!1;var i=e(a),j=0;i.forEach(function(){j++});var m=f(a,i),n=new b(function(a,b){return pv.naturalOrder(a.count(),b.count())});n.push(m),h(n,l*c);for(var o=new b(function(a,b){return pv.naturalOrder(a.count()*a.volume(),b.count()*b.volume())});n.size();)o.push(n.pop());h(o,c-o.size());for(var p=new d;o.size();)p.push(o.pop());return p}var i=5,j=8-i,k=1e3,l=.75;return c.prototype={volume:function(a){var b=this;return b._volume&&!a||(b._volume=(b.r2-b.r1+1)*(b.g2-b.g1+1)*(b.b2-b.b1+1)),b._volume},count:function(b){var c=this,d=c.histo;if(!c._count_set||b){var e,f,g,h=0;for(e=c.r1;e<=c.r2;e++)for(f=c.g1;f<=c.g2;f++)for(g=c.b1;g<=c.b2;g++)index=a(e,f,g),h+=d[index]||0;c._count=h,c._count_set=!0}return c._count},copy:function(){var a=this;return new c(a.r1,a.r2,a.g1,a.g2,a.b1,a.b2,a.histo)},avg:function(b){var c=this,d=c.histo;if(!c._avg||b){var e,f,g,h,j,k=0,l=1<<8-i,m=0,n=0,o=0;for(f=c.r1;f<=c.r2;f++)for(g=c.g1;g<=c.g2;g++)for(h=c.b1;h<=c.b2;h++)j=a(f,g,h),e=d[j]||0,k+=e,m+=e*(f+.5)*l,n+=e*(g+.5)*l,o+=e*(h+.5)*l;k?c._avg=[~~(m/k),~~(n/k),~~(o/k)]:c._avg=[~~(l*(c.r1+c.r2+1)/2),~~(l*(c.g1+c.g2+1)/2),~~(l*(c.b1+c.b2+1)/2)]}return c._avg},contains:function(a){var b=this,c=a[0]>>j;return gval=a[1]>>j,bval=a[2]>>j,c>=b.r1&&c<=b.r2&&gval>=b.g1&&gval<=b.g2&&bval>=b.b1&&bval<=b.b2}},d.prototype={push:function(a){this.vboxes.push({vbox:a,color:a.avg()})},palette:function(){return this.vboxes.map(function(a){return a.color})},size:function(){return this.vboxes.size()},map:function(a){for(var b=this.vboxes,c=0;c251&&d[1]>251&&d[2]>251&&(a[c].color=[255,255,255])}},{quantize:h}}(); -------------------------------------------------------------------------------- /Day15/crow-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/crow-color.jpg -------------------------------------------------------------------------------- /Day15/crow-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/crow-silhouette.png -------------------------------------------------------------------------------- /Day15/dragon-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/dragon-color.jpg -------------------------------------------------------------------------------- /Day15/dragon-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/dragon-silhouette.png -------------------------------------------------------------------------------- /Day15/fish-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/fish-color.jpg -------------------------------------------------------------------------------- /Day15/fish-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/fish-silhouette.png -------------------------------------------------------------------------------- /Day15/index.html: -------------------------------------------------------------------------------- 1 | 2 | Day 15 3 | 4 | 5 | 6 | 7 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Day15/quill-color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/quill-color.png -------------------------------------------------------------------------------- /Day15/quill-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/quill-silhouette.png -------------------------------------------------------------------------------- /Day15/reindeer-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/reindeer-color.jpg -------------------------------------------------------------------------------- /Day15/reindeer-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/reindeer-silhouette.png -------------------------------------------------------------------------------- /Day15/rhino-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/rhino-color.jpg -------------------------------------------------------------------------------- /Day15/rhino-silhoutte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/rhino-silhoutte.png -------------------------------------------------------------------------------- /Day15/saxophone-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/saxophone-color.jpg -------------------------------------------------------------------------------- /Day15/saxophone-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/saxophone-silhouette.png -------------------------------------------------------------------------------- /Day15/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/screenshot.mp4 -------------------------------------------------------------------------------- /Day15/stork-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/stork-color.jpg -------------------------------------------------------------------------------- /Day15/stork-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/stork-silhouette.png -------------------------------------------------------------------------------- /Day15/swan-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/swan-color.jpg -------------------------------------------------------------------------------- /Day15/swan-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/swan-silhouette.png -------------------------------------------------------------------------------- /Day15/tea-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/tea-color.jpg -------------------------------------------------------------------------------- /Day15/tea-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/tea-silhouette.png -------------------------------------------------------------------------------- /Day15/unicorn-color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/unicorn-color.jpg -------------------------------------------------------------------------------- /Day15/unicorn-silhouette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day15/unicorn-silhouette.png -------------------------------------------------------------------------------- /Day16/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day16/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Collage 5 | import Element 6 | import Color 7 | import Transform 8 | import AnimationFrame 9 | import Time exposing (Time) 10 | 11 | 12 | type alias Model = 13 | { now : Time } 14 | 15 | 16 | initialModel : Model 17 | initialModel = 18 | { now = 0 } 19 | 20 | 21 | type Msg 22 | = Tick Time 23 | 24 | 25 | update : Msg -> Model -> ( Model, Cmd Msg ) 26 | update msg model = 27 | case msg of 28 | Tick now -> 29 | ( { model | now = now }, Cmd.none ) 30 | 31 | 32 | type alias Wheel = 33 | { width : Float 34 | , height : Float 35 | } 36 | 37 | 38 | wheel : Wheel -> Collage.Form 39 | wheel model = 40 | Collage.group 41 | [ Collage.oval model.width model.height |> Collage.filled Color.white 42 | , Collage.oval (model.width - 50) (model.height - 50) |> Collage.filled Color.green 43 | , Collage.rect 10 model.height |> Collage.filled Color.green 44 | ] 45 | 46 | 47 | type alias Biker = 48 | { torsoWidth : Float 49 | , torsoHeight : Float 50 | , torsoAngle : Float 51 | , headSize : Float 52 | , headTilt : Float 53 | , t : Float 54 | } 55 | 56 | 57 | biker : Biker -> Collage.Form 58 | biker model = 59 | let 60 | head color = 61 | Collage.group 62 | [ [ Collage.circle (model.headSize / 2 + 10) 63 | |> Collage.filled color 64 | , Collage.rect (model.headSize + 20) (model.headSize / 2 + 10) 65 | |> Collage.filled Color.green 66 | |> Collage.move ( 0, -(model.headSize / 2 + 10) / 2 ) 67 | ] 68 | |> Collage.groupTransform 69 | (Transform.rotation -model.headTilt) 70 | , Collage.circle (model.headSize / 2) 71 | |> Collage.filled color 72 | ] 73 | 74 | body color = 75 | [ head color 76 | |> Collage.move ( 0, model.torsoHeight / 2 + (model.headSize / 2) + 10 ) 77 | , Collage.rect model.torsoWidth model.torsoHeight 78 | |> Collage.filled color 79 | , Collage.rect 20 40 80 | |> Collage.filled color 81 | |> Collage.rotate (degrees 80) 82 | |> Collage.move ( model.torsoWidth / 2, model.torsoHeight * 0.35 ) 83 | ] 84 | |> Collage.groupTransform 85 | (Transform.identity 86 | |> Transform.multiply (Transform.translation 0 (model.torsoHeight / 2)) 87 | |> Transform.multiply (Transform.rotation -model.torsoAngle) 88 | ) 89 | 90 | leg movement = 91 | [ Collage.group 92 | [ Collage.rect 20 60 |> Collage.filled Color.white 93 | , [ Collage.rect 20 40 94 | |> Collage.filled Color.white 95 | |> Collage.move ( 0, -20 ) 96 | ] 97 | |> Collage.groupTransform 98 | (Transform.identity 99 | |> Transform.multiply (Transform.rotation (degrees -(2 * movement))) 100 | |> Transform.multiply (Transform.translation 0 -30) 101 | ) 102 | ] 103 | |> Collage.move ( 0, -30 ) 104 | ] 105 | |> Collage.groupTransform 106 | (Transform.identity 107 | |> Transform.multiply (Transform.rotation (degrees movement)) 108 | |> Transform.multiply (Transform.rotation (degrees 30)) 109 | ) 110 | in 111 | Collage.group 112 | [ body Color.white 113 | , leg (25 + -(50 / 2) * sin (model.t / 200)) 114 | , leg (25 + (50 / 2) * sin (model.t / 200)) 115 | ] 116 | 117 | 118 | bike : Float -> Collage.Form 119 | bike t = 120 | let 121 | wheelModel = 122 | { width = 80, height = 120 } 123 | in 124 | Collage.group 125 | [ wheel wheelModel |> Collage.move ( -80, -wheelModel.height / 2 ) 126 | , wheel wheelModel |> Collage.move ( 80, -wheelModel.height / 2 ) 127 | , biker 128 | { torsoWidth = 35 129 | , torsoHeight = 100 130 | , torsoAngle = degrees 30 131 | , headSize = 30 132 | , headTilt = degrees -30 133 | , t = t 134 | } 135 | |> Collage.move ( -30, 0 ) 136 | ] 137 | 138 | 139 | view : Model -> Html msg 140 | view model = 141 | [ Collage.rect 300 400 142 | |> Collage.filled Color.green 143 | , bike model.now 144 | |> Collage.move ( 0, -60 ) 145 | , Collage.path [ ( -120, -30 ), ( 0, 0 ), ( 120, -30 ) ] 146 | |> Collage.traced 147 | { color = Color.white 148 | , width = 20 149 | , cap = Collage.Flat 150 | , join = Collage.Sharp 10 151 | , dashing = [] 152 | , dashOffset = 0 153 | } 154 | |> Collage.move ( 0, 170 + -10 * cos (0.3 + model.now / 1000) ) 155 | , Collage.path [ ( -120, -30 ), ( 0, 0 ), ( 120, -30 ) ] 156 | |> Collage.traced 157 | { color = Color.white 158 | , width = 20 159 | , cap = Collage.Flat 160 | , join = Collage.Sharp 10 161 | , dashing = [] 162 | , dashOffset = 0 163 | } 164 | |> Collage.move ( 0, 130 + -10 * cos (model.now / 1000) ) 165 | ] 166 | |> Collage.collage 750 500 167 | |> Element.toHtml 168 | 169 | 170 | main : Program Never Model Msg 171 | main = 172 | Html.program 173 | { init = ( initialModel, Cmd.none ) 174 | , subscriptions = \_ -> AnimationFrame.times Tick 175 | , update = update 176 | , view = view 177 | } 178 | -------------------------------------------------------------------------------- /Day16/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 12 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 13 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 14 | "evancz/elm-graphics": "1.0.1 <= v < 2.0.0" 15 | }, 16 | "elm-version": "0.18.0 <= v < 0.19.0" 17 | } 18 | -------------------------------------------------------------------------------- /Day16/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day16/screenshot.gif -------------------------------------------------------------------------------- /Day17/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day17/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Collage 5 | import Element 6 | import Color exposing (Color) 7 | import Color.Mixing 8 | import Time exposing (Time) 9 | import AnimationFrame 10 | import Char 11 | import Html.Attributes 12 | import Html.Events 13 | import Window 14 | import Task 15 | 16 | 17 | theShape : String -> Time -> Float -> Color -> Collage.Form 18 | theShape text t size color = 19 | if size <= 5 || text == "" then 20 | Collage.group [] 21 | else 22 | let 23 | scale = 24 | 0.4 25 | 26 | push = 27 | 0.55 28 | 29 | child index drop mixColor angle = 30 | let 31 | c = 32 | text 33 | |> String.dropLeft index 34 | |> String.uncons 35 | |> Maybe.map (\( char, _ ) -> char) 36 | |> Maybe.withDefault '.' 37 | 38 | newColor = 39 | if Char.isUpper c then 40 | color 41 | |> Color.Mixing.mix 0.5 mixColor 42 | |> Color.Mixing.fadeIn 0.2 43 | else if c == ' ' then 44 | color 45 | |> Color.Mixing.mix 0.5 Color.black 46 | |> Color.Mixing.fadeIn 0.2 47 | else 48 | color 49 | |> Color.Mixing.mix 0.2 mixColor 50 | |> Color.Mixing.fadeOut 0.2 51 | in 52 | theShape (String.dropLeft drop text) 53 | (t * 1.2) 54 | (size * scale) 55 | newColor 56 | |> Collage.move 57 | ( size * push * cos (degrees <| angle + 10 * sin (t / 1000)) 58 | , size * push * sin (degrees <| angle + 10 * sin (t / 1000)) 59 | ) 60 | in 61 | Collage.group 62 | [ Collage.circle size 63 | |> Collage.filled color 64 | , Collage.circle size 65 | |> Collage.outlined (Collage.solid Color.charcoal) 66 | , child 0 5 Color.red 30 67 | , child 1 10 Color.blue 150 68 | , child 2 15 Color.green 270 69 | ] 70 | 71 | 72 | type alias Model = 73 | { now : Time 74 | , text : String 75 | , size : Maybe Window.Size 76 | } 77 | 78 | 79 | type Msg 80 | = Tick Time 81 | | NewText String 82 | | WindowSize Window.Size 83 | 84 | 85 | update : Msg -> Model -> ( Model, Cmd Msg ) 86 | update msg model = 87 | case msg of 88 | Tick t -> 89 | ( { model | now = t }, Cmd.none ) 90 | 91 | NewText text -> 92 | ( { model | text = text }, Cmd.none ) 93 | 94 | WindowSize size -> 95 | ( { model | size = Just size }, Cmd.none ) 96 | 97 | 98 | view : Model -> Html Msg 99 | view model = 100 | case model.size of 101 | Nothing -> 102 | Html.text "" 103 | 104 | Just size -> 105 | Html.div [ Html.Attributes.style [ ( "position", "relative" ) ] ] 106 | [ Html.div [ Html.Attributes.style [ ( "position", "absolute" ) ] ] 107 | [ [ theShape 108 | model.text 109 | model.now 110 | 300 111 | Color.yellow 112 | ] 113 | |> Collage.collage size.width size.height 114 | |> Element.toHtml 115 | ] 116 | , Html.div 117 | [ Html.Attributes.style 118 | [ ( "position", "absolute" ) 119 | , ( "width", "100%" ) 120 | , ( "padding", "10px" ) 121 | , ( "margin", "0" ) 122 | , ( "box-sizing", "border-box" ) 123 | ] 124 | ] 125 | [ Html.input 126 | [ Html.Attributes.style 127 | [ ( "width", "100%" ) 128 | , ( "font-size", "24px" ) 129 | , ( "box-sizing", "border-box" ) 130 | ] 131 | , Html.Attributes.defaultValue model.text 132 | , Html.Events.onInput NewText 133 | ] 134 | [] 135 | ] 136 | ] 137 | 138 | 139 | main : Program Never Model Msg 140 | main = 141 | Html.program 142 | { init = 143 | ( { now = 0 144 | , text = "A delightful language for reliable webapps." 145 | , size = Nothing 146 | } 147 | , Window.size |> Task.perform WindowSize 148 | ) 149 | , subscriptions = 150 | \_ -> 151 | Sub.batch 152 | [ AnimationFrame.times Tick 153 | , Window.resizes WindowSize 154 | ] 155 | , update = update 156 | , view = view 157 | } 158 | -------------------------------------------------------------------------------- /Day17/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 12 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 13 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 14 | "elm-lang/window": "1.0.1 <= v < 2.0.0", 15 | "evancz/elm-graphics": "1.0.1 <= v < 2.0.0", 16 | "mdgriffith/elm-color-mixing": "1.0.4 <= v < 2.0.0" 17 | }, 18 | "elm-version": "0.18.0 <= v < 0.19.0" 19 | } 20 | -------------------------------------------------------------------------------- /Day17/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day17/screenshot.mp4 -------------------------------------------------------------------------------- /Day18/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day18/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Color 4 | import Collage 5 | import Html exposing (Html) 6 | import Element 7 | import Color.Mixing 8 | import Time exposing (Time) 9 | import AnimationFrame 10 | import Shapes 11 | import Transform 12 | 13 | 14 | sunset : Float -> Float -> Float -> Collage.Form 15 | sunset width height percent = 16 | let 17 | blue = 18 | Color.hsl (degrees 191) 1.0 0.33 19 | 20 | orange = 21 | Color.hsl (degrees 29) 0.92 0.49 22 | 23 | red = 24 | Color.red 25 | 26 | black = 27 | Color.black 28 | in 29 | Collage.rect width height 30 | |> Collage.gradient 31 | (Color.linear 32 | ( 0, 250 ) 33 | ( 0, -250 ) 34 | [ ( 0, blue |> Color.Mixing.mix percent black ) 35 | , ( 1, orange |> Color.Mixing.mix percent red ) 36 | ] 37 | ) 38 | 39 | 40 | beach : Collage.Form 41 | beach = 42 | Collage.group 43 | [ Collage.polygon 44 | (Shapes.curve ( -375, -150 ) ( -200, -100 ) ( 375, -150 ) 40 45 | ++ [ ( 375, -250 ) 46 | , ( -375, -250 ) 47 | ] 48 | ) 49 | |> Collage.filled Color.black 50 | , Collage.polygon 51 | (Shapes.curve ( 200, -170 ) ( 230, -100 ) ( 230, 190 ) 30 52 | ++ Shapes.curve ( 250, 200 ) ( 240, 0 ) ( 250, -170 ) 30 53 | ) 54 | |> Collage.filled Color.black 55 | , Collage.polygon 56 | (Shapes.curve ( 220, 190 ) ( 55, 183 ) ( 30, 50 ) 30 57 | ++ Shapes.curve ( 30, 50 ) ( 95, 163 ) ( 220, 190 ) 30 58 | ) 59 | |> Collage.filled Color.black 60 | , Collage.polygon 61 | (Shapes.curve ( 225, 180 ) ( 75, 163 ) ( 110, 10 ) 30 62 | ++ Shapes.curve ( 110, 10 ) ( 115, 153 ) ( 225, 180 ) 30 63 | ) 64 | |> Collage.filled Color.black 65 | , Collage.polygon 66 | (Shapes.curve ( 227, 202 ) ( 95, 233 ) ( 53, 157 ) 30 67 | ++ Shapes.curve ( 53, 157 ) ( 135, 213 ) ( 227, 202 ) 30 68 | ) 69 | |> Collage.filled Color.black 70 | , Collage.groupTransform 71 | (Transform.scaleX -1 72 | |> Transform.multiply (Transform.translation 480 0) 73 | ) 74 | [ Collage.polygon 75 | (Shapes.curve ( 220, 190 ) ( 55, 183 ) ( 30, 50 ) 30 76 | ++ Shapes.curve ( 30, 50 ) ( 95, 163 ) ( 220, 190 ) 30 77 | ) 78 | |> Collage.filled Color.black 79 | , Collage.polygon 80 | (Shapes.curve ( 225, 180 ) ( 75, 163 ) ( 110, 10 ) 30 81 | ++ Shapes.curve ( 110, 10 ) ( 115, 153 ) ( 225, 180 ) 30 82 | ) 83 | |> Collage.filled Color.black 84 | , Collage.polygon 85 | (Shapes.curve ( 227, 202 ) ( 95, 233 ) ( 53, 157 ) 30 86 | ++ Shapes.curve ( 53, 157 ) ( 135, 213 ) ( 227, 202 ) 30 87 | ) 88 | |> Collage.filled Color.black 89 | ] 90 | ] 91 | 92 | 93 | type alias Model = 94 | { time : Float } 95 | 96 | 97 | initialModel : Model 98 | initialModel = 99 | { time = 0 } 100 | 101 | 102 | type Msg 103 | = Tick Time 104 | 105 | 106 | update : Msg -> Model -> ( Model, Cmd Msg ) 107 | update msg model = 108 | case msg of 109 | Tick dt -> 110 | ( { model | time = model.time + dt }, Cmd.none ) 111 | 112 | 113 | view : Model -> Html msg 114 | view model = 115 | [ sunset 750 500 (model.time / 10000) 116 | , beach 117 | ] 118 | |> Collage.collage 750 500 119 | |> Element.toHtml 120 | 121 | 122 | main : Program Never Model Msg 123 | main = 124 | Html.program 125 | { init = ( initialModel, Cmd.none ) 126 | , subscriptions = 127 | \model -> 128 | if model.time < 10000 then 129 | AnimationFrame.diffs Tick 130 | else 131 | Sub.none 132 | , update = update 133 | , view = view 134 | } 135 | -------------------------------------------------------------------------------- /Day18/Shapes.elm: -------------------------------------------------------------------------------- 1 | module Shapes exposing (curve) 2 | 3 | 4 | type alias Point = 5 | ( Float, Float ) 6 | 7 | 8 | curve : Point -> Point -> Point -> Int -> List ( Float, Float ) 9 | curve start control end n = 10 | let 11 | ( start_x, start_y ) = 12 | start 13 | 14 | ( control_x, control_y ) = 15 | control 16 | 17 | ( end_x, end_y ) = 18 | end 19 | 20 | x t = 21 | ((1 - t) * (1 - t) * start_x) 22 | + (2 * (1 - t) * t * control_x) 23 | + (t * t * end_x) 24 | 25 | y t = 26 | ((1 - t) * (1 - t) * start_y) 27 | + (2 * (1 - t) * t * control_y) 28 | + (t * t * end_y) 29 | in 30 | List.range 0 n 31 | |> List.map 32 | (\i -> 33 | ( x (toFloat i / toFloat n) 34 | , y (toFloat i / toFloat n) 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /Day18/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 12 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 13 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 14 | "evancz/elm-graphics": "1.0.1 <= v < 2.0.0", 15 | "mdgriffith/elm-color-mixing": "1.0.4 <= v < 2.0.0" 16 | }, 17 | "elm-version": "0.18.0 <= v < 0.19.0" 18 | } 19 | -------------------------------------------------------------------------------- /Day18/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day18/screenshot.mp4 -------------------------------------------------------------------------------- /Day19/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day19/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Html.Attributes 5 | import Time exposing (Time) 6 | 7 | 8 | type alias Model = 9 | { current : String 10 | , nextLines : List String 11 | , author : String 12 | , finalFade : Maybe Time 13 | , done : Bool 14 | } 15 | 16 | 17 | initialModel : Model 18 | initialModel = 19 | { current = "" 20 | , nextLines = 21 | [ "At last to be identified!" 22 | , "At last, the lamps upon thy side," 23 | , "The rest of life to see!" 24 | , "Past midnight, past the morning star!" 25 | , "Past sunrise! Ah! what leagues there are" 26 | , "Between our feet and day!" 27 | ] 28 | , author = "Emily Dickinson" 29 | , finalFade = Nothing 30 | , done = False 31 | } 32 | 33 | 34 | type Msg 35 | = Tick Time 36 | 37 | 38 | nextStep : String -> String -> String 39 | nextStep current target = 40 | if current == "" then 41 | String.left 1 target 42 | else if String.left 1 current /= String.left 1 target then 43 | String.dropRight 1 current 44 | else 45 | (String.left 1 current 46 | ++ nextStep 47 | (String.dropLeft 1 current) 48 | (String.dropLeft 1 target) 49 | ) 50 | 51 | 52 | update : Msg -> Model -> ( Model, Cmd Msg ) 53 | update msg model = 54 | case msg of 55 | Tick now -> 56 | case model.nextLines of 57 | [] -> 58 | if model.current == "" then 59 | case model.finalFade of 60 | Nothing -> 61 | ( { model | finalFade = Just 0 }, Cmd.none ) 62 | 63 | Just fade -> 64 | if fade >= 1.0 then 65 | ( { model | done = True }, Cmd.none ) 66 | else 67 | ( { model | finalFade = Just <| fade + 0.01 } 68 | , Cmd.none 69 | ) 70 | else 71 | ( { model | current = String.dropRight 1 model.current } 72 | , Cmd.none 73 | ) 74 | 75 | next :: rest -> 76 | ( { model 77 | | current = nextStep model.current next 78 | , nextLines = 79 | if model.current == next then 80 | rest 81 | else 82 | model.nextLines 83 | } 84 | , Cmd.none 85 | ) 86 | 87 | 88 | view : Model -> Html Msg 89 | view model = 90 | Html.div 91 | [ Html.Attributes.style 92 | [ ( "background-color", "black" ) 93 | , ( "width", "100vw" ) 94 | , ( "height", "100vh" ) 95 | , ( "font-family", "serif" ) 96 | ] 97 | ] 98 | [ Html.div 99 | [ Html.Attributes.style 100 | [ ( "position", "relative" ) 101 | , ( "top", "50%" ) 102 | , ( "transform", "translateY(-50%)" ) 103 | , ( "text-align", "center" ) 104 | , ( "color", "#ddc" ) 105 | , ( "font-size", "9vw" ) 106 | ] 107 | ] 108 | [ Html.text model.current ] 109 | , Html.div 110 | [ Html.Attributes.style 111 | [ ( "position", "relative" ) 112 | , ( "top", "70%" ) 113 | , ( "transform", "translateY(-50%)" ) 114 | , ( "text-align", "center" ) 115 | , ( "padding-left", "20%" ) 116 | , ( "color", "#665" ) 117 | , ( "font-size", "6vw" ) 118 | , ( "opacity" 119 | , model.finalFade 120 | |> Maybe.withDefault 0 121 | |> toString 122 | ) 123 | ] 124 | ] 125 | [ Html.text model.author ] 126 | ] 127 | 128 | 129 | main : Program Never Model Msg 130 | main = 131 | Html.program 132 | { init = ( initialModel, Cmd.none ) 133 | , subscriptions = 134 | \model -> 135 | if model.done then 136 | Sub.none 137 | else 138 | Time.every 100 Tick 139 | , update = update 140 | , view = view 141 | } 142 | -------------------------------------------------------------------------------- /Day19/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 12 | "elm-lang/html": "2.0.0 <= v < 3.0.0" 13 | }, 14 | "elm-version": "0.18.0 <= v < 0.19.0" 15 | } 16 | -------------------------------------------------------------------------------- /Day19/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day19/screenshot.gif -------------------------------------------------------------------------------- /Day20/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day20/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/list-extra": "4.0.0 <= v < 5.0.0", 12 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 13 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 14 | "elm-lang/svg": "2.0.0 <= v < 3.0.0" 15 | }, 16 | "elm-version": "0.18.0 <= v < 0.19.0" 17 | } 18 | -------------------------------------------------------------------------------- /Day20/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day20/screenshot.gif -------------------------------------------------------------------------------- /Day21/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day21/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Animation 4 | import Html exposing (Html) 5 | import Svg exposing (Svg) 6 | import Svg.Attributes 7 | import Html.Attributes 8 | import Color 9 | 10 | 11 | type alias Model = 12 | { shape : Animation.State 13 | , background : Animation.State 14 | } 15 | 16 | 17 | initialModel : Model 18 | initialModel = 19 | { shape = 20 | Animation.style 21 | [ Animation.points (regularPolygon 3) 22 | , Animation.translate (Animation.px 50) (Animation.px 50) 23 | , Animation.scale 15.0 24 | , Animation.fill Color.red 25 | , Animation.rotate (Animation.turn 0) 26 | ] 27 | |> Animation.queue 28 | [ Animation.loop 29 | [ Animation.wait 500 30 | , Animation.to 31 | [ Animation.scale 30 32 | , Animation.points (regularPolygon 50) 33 | , Animation.fill Color.blue 34 | , Animation.rotate (Animation.turn 0.6) 35 | ] 36 | , Animation.wait 500 37 | , Animation.to 38 | [ Animation.points (star 5) 39 | , Animation.scale 25.0 40 | , Animation.fill (Color.hsl (degrees 345) 0.6 0.7) 41 | , Animation.rotate (Animation.turn 0.3) 42 | , Animation.translate (Animation.px 75) (Animation.px 80) 43 | ] 44 | , Animation.wait 500 45 | , Animation.to 46 | [ Animation.points (regularPolygon 3) 47 | , Animation.scale 15.0 48 | , Animation.fill Color.red 49 | , Animation.translate (Animation.px 50) (Animation.px 50) 50 | ] 51 | ] 52 | ] 53 | , background = 54 | Animation.style 55 | [ Animation.fill Color.black 56 | ] 57 | |> Animation.queue 58 | [ Animation.loop 59 | [ Animation.wait 500 60 | , Animation.to 61 | [ Animation.fill Color.yellow 62 | ] 63 | , Animation.wait 500 64 | , Animation.to 65 | [ Animation.fill Color.orange 66 | ] 67 | , Animation.wait 500 68 | , Animation.to 69 | [ Animation.fill Color.black 70 | ] 71 | ] 72 | ] 73 | } 74 | 75 | 76 | normalizePolygon : Int -> List ( Float, Float ) -> List ( Float, Float ) 77 | normalizePolygon targetNumberOfPoints originalPoints = 78 | let 79 | originalLength = 80 | List.length originalPoints 81 | in 82 | List.indexedMap 83 | (\i point -> 84 | List.repeat (targetNumberOfPoints // originalLength) point 85 | ) 86 | originalPoints 87 | |> List.concat 88 | 89 | 90 | regularPolygon : Int -> List ( Float, Float ) 91 | regularPolygon sides = 92 | List.range 1 sides 93 | |> List.map 94 | (\i -> 95 | ( cos (2 * pi * toFloat i / toFloat sides) 96 | , sin (2 * pi * toFloat i / toFloat sides) 97 | ) 98 | ) 99 | 100 | 101 | star : Int -> List ( Float, Float ) 102 | star points = 103 | List.range 1 (points * 2) 104 | |> List.map 105 | (\i -> 106 | let 107 | distance = 108 | if i % 2 == 0 then 109 | 1.0 110 | else 111 | 0.5 112 | in 113 | ( distance * cos (2 * pi * toFloat i / toFloat points) 114 | , distance * sin (2 * pi * toFloat i / toFloat points) 115 | ) 116 | ) 117 | 118 | 119 | type Msg 120 | = Animate Animation.Msg 121 | 122 | 123 | update : Msg -> Model -> ( Model, Cmd Msg ) 124 | update msg model = 125 | case msg of 126 | Animate animMsg -> 127 | ( { model 128 | | shape = Animation.update animMsg model.shape 129 | , background = Animation.update animMsg model.background 130 | } 131 | , Cmd.none 132 | ) 133 | 134 | 135 | view : Model -> Html Msg 136 | view model = 137 | Svg.svg 138 | [ Html.Attributes.style [ ( "max-height", "100vh" ) ] 139 | , Svg.Attributes.viewBox "0 0 100 100" 140 | ] 141 | [ Svg.rect 142 | ([ Svg.Attributes.width "100" 143 | , Svg.Attributes.height "100" 144 | , Svg.Attributes.x "0" 145 | , Svg.Attributes.y "0" 146 | ] 147 | ++ Animation.render model.background 148 | ) 149 | [] 150 | , Svg.polygon (Animation.render model.shape) [] 151 | ] 152 | 153 | 154 | main : Program Never Model Msg 155 | main = 156 | Html.program 157 | { init = ( initialModel, Cmd.none ) 158 | , subscriptions = 159 | \model -> 160 | Animation.subscription Animate 161 | [ model.shape 162 | , model.background 163 | ] 164 | , update = update 165 | , view = view 166 | } 167 | -------------------------------------------------------------------------------- /Day21/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 12 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 13 | "elm-lang/svg": "2.0.0 <= v < 3.0.0", 14 | "mdgriffith/elm-style-animation": "3.4.0 <= v < 4.0.0" 15 | }, 16 | "elm-version": "0.18.0 <= v < 0.19.0" 17 | } 18 | -------------------------------------------------------------------------------- /Day21/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day21/screenshot.mp4 -------------------------------------------------------------------------------- /Day22/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day22/DrawTree.elm: -------------------------------------------------------------------------------- 1 | module DrawTree exposing (draw) 2 | 3 | import TreeDiagram 4 | import TreeDiagram.Svg 5 | import Svg exposing (..) 6 | import Svg.Attributes exposing (..) 7 | 8 | 9 | draw : TreeDiagram.Tree String -> Svg msg 10 | draw = 11 | TreeDiagram.Svg.draw 12 | { orientation = TreeDiagram.topToBottom 13 | , levelHeight = 50 14 | , siblingDistance = 160 15 | , subtreeDistance = 170 16 | , padding = 100 17 | } 18 | drawNode 19 | drawLine 20 | 21 | 22 | drawLine : ( Float, Float ) -> Svg msg 23 | drawLine ( targetX, targetY ) = 24 | line 25 | [ x1 "0" 26 | , y1 "0" 27 | , x2 (toString targetX) 28 | , y2 (toString targetY) 29 | , stroke "black" 30 | ] 31 | [] 32 | 33 | 34 | drawNode : String -> Svg msg 35 | drawNode n = 36 | let 37 | w = 38 | (String.length n * 8) 39 | |> Basics.max 50 40 | in 41 | g 42 | [] 43 | [ rect 44 | [ x <| toString (toFloat -w / 2) 45 | , y "-6" 46 | , width <| toString w 47 | , height "32" 48 | , fill "white" 49 | , stroke "black" 50 | ] 51 | [] 52 | -- circle [ r "16", stroke "black", fill "white", cx "0", cy "0" ] [] 53 | , text_ [ textAnchor "middle", transform "translate(0,14)" ] [ text n ] 54 | ] 55 | -------------------------------------------------------------------------------- /Day22/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Html exposing (Html) 4 | import Combine exposing ((<$>), (<*>), (<*), (*>)) 5 | import TreeDiagram 6 | import DrawTree 7 | 8 | 9 | testSentence1 : String 10 | testSentence1 = 11 | "The whin was frankincense and flame." 12 | 13 | 14 | testSentence2 : String 15 | testSentence2 = 16 | "Now I have seen the furze wren at his very best!" 17 | 18 | 19 | type alias Tree = 20 | TreeDiagram.Tree String 21 | 22 | 23 | node : String -> List Tree -> Tree 24 | node = 25 | TreeDiagram.node 26 | 27 | 28 | nounPhrase : Combine.Parser () Tree 29 | nounPhrase = 30 | (\result -> node result []) 31 | <$> Combine.choice 32 | [ Combine.string "The whin" 33 | , Combine.string "frankincense and flame" 34 | , Combine.string "I" 35 | , Combine.string "the furze wren" 36 | , Combine.string "his very best" 37 | ] 38 | 39 | 40 | verb : Combine.Parser () String 41 | verb = 42 | Combine.choice 43 | [ Combine.string "was" 44 | , Combine.string "have seen" 45 | ] 46 | 47 | 48 | whitespace : Combine.Parser () String 49 | whitespace = 50 | Combine.string " " 51 | 52 | 53 | timePhrase : Combine.Parser () String 54 | timePhrase = 55 | Combine.string "Now" 56 | 57 | 58 | prepositionalPhrase : Combine.Parser () Tree 59 | prepositionalPhrase = 60 | (\prep noun -> node prep [ noun ]) 61 | <$> (Combine.string "at" <* whitespace) 62 | <*> nounPhrase 63 | 64 | 65 | sentenceParser : Combine.Parser () Tree 66 | sentenceParser = 67 | Combine.choice 68 | [ (\subject verb object preps -> 69 | node verb 70 | ([ subject, object ] ++ preps) 71 | ) 72 | <$> nounPhrase 73 | <*> (whitespace *> verb <* whitespace) 74 | <*> nounPhrase 75 | <*> Combine.many (whitespace *> prepositionalPhrase) 76 | , (\time rest -> node time [ rest ]) 77 | <$> (timePhrase <* whitespace) 78 | <*> Combine.lazy (\() -> sentenceParser) 79 | ] 80 | 81 | 82 | parse : String -> Result ( String, List String ) Tree 83 | parse input = 84 | case Combine.parse sentenceParser input of 85 | Err ( _, inputStream, messages ) -> 86 | Err ( inputStream.input, messages ) 87 | 88 | Ok ( _, _, result ) -> 89 | Ok result 90 | 91 | 92 | main : Html msg 93 | main = 94 | case parse testSentence2 of 95 | Ok tree -> 96 | tree 97 | |> DrawTree.draw 98 | 99 | Err ( remaining, messages ) -> 100 | Html.div [] 101 | [ Html.b [] [ Html.text <| "Couldn't parse: " ++ remaining ] 102 | , messages 103 | |> List.map (\m -> Html.li [] [ Html.text m ]) 104 | |> Html.ul [] 105 | ] 106 | -------------------------------------------------------------------------------- /Day22/elm-tree-diagram/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Brenden Kokoszka 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /Day22/elm-tree-diagram/src/TreeDiagram/Canvas.elm: -------------------------------------------------------------------------------- 1 | module TreeDiagram.Canvas exposing (draw) 2 | 3 | {-| Provides a draw function for drawing trees as canvas images. 4 | 5 | @docs draw 6 | -} 7 | 8 | import Collage exposing (..) 9 | import Element exposing (..) 10 | import TreeDiagram exposing (..) 11 | 12 | 13 | canvasPosition : Coord -> Form -> Form 14 | canvasPosition coord form = 15 | move coord form 16 | 17 | 18 | canvasCompose : Int -> Int -> List Form -> Element 19 | canvasCompose width height forms = 20 | collage width height forms 21 | 22 | 23 | canvasTransform : Int -> Int -> Coord -> Coord 24 | canvasTransform width height coord = 25 | coord 26 | 27 | 28 | canvasDrawable : Drawable Form Element 29 | canvasDrawable = 30 | Drawable canvasPosition canvasCompose canvasTransform 31 | 32 | 33 | {-| Draws the tree using the provided functions for drawings nodes and edges. 34 | TreeLayout contains some more options for positioning the tree. 35 | -} 36 | draw : TreeLayout -> NodeDrawer a Form -> EdgeDrawer Form -> Tree a -> Element 37 | draw layout drawNode drawLine tree = 38 | draw_ canvasDrawable layout drawNode drawLine tree 39 | -------------------------------------------------------------------------------- /Day22/elm-tree-diagram/src/TreeDiagram/Svg.elm: -------------------------------------------------------------------------------- 1 | module TreeDiagram.Svg exposing (draw) 2 | 3 | {-| Provides a draw function for drawing trees as SVGs. 4 | 5 | @docs draw 6 | -} 7 | 8 | import Html exposing (Html) 9 | import Svg exposing (Svg) 10 | import Svg.Attributes as SA 11 | import TreeDiagram exposing (..) 12 | 13 | 14 | svgPosition : Coord -> Svg msg -> Svg msg 15 | svgPosition ( x, y ) svg = 16 | Svg.g 17 | [ SA.transform <| "translate(" ++ (toString x) ++ " " ++ (toString y) ++ ")" ] 18 | [ svg ] 19 | 20 | 21 | svgCompose : Int -> Int -> List (Svg msg) -> Svg msg 22 | svgCompose width height svgs = 23 | Svg.svg 24 | [ SA.width <| toString width 25 | , SA.height <| toString height 26 | ] 27 | [ Svg.g [] svgs ] 28 | 29 | 30 | svgTransform : Int -> Int -> Coord -> Coord 31 | svgTransform width height coord = 32 | let 33 | ( x, y ) = 34 | coord 35 | 36 | svgX = 37 | x + ((toFloat width) / 2) 38 | 39 | svgY = 40 | ((toFloat height) / 2) - y 41 | in 42 | ( svgX, svgY ) 43 | 44 | 45 | svgDrawable : Drawable (Svg msg) (Html msg) 46 | svgDrawable = 47 | Drawable svgPosition svgCompose svgTransform 48 | 49 | 50 | {-| Draws the tree using the provided functions for drawings nodes and edges. 51 | TreeLayout contains some more options for positioning the tree. 52 | -} 53 | draw : TreeLayout -> NodeDrawer a (Svg msg) -> EdgeDrawer (Svg msg) -> Tree a -> Html msg 54 | draw layout drawNode drawLine tree = 55 | draw_ svgDrawable layout drawNode drawLine tree 56 | -------------------------------------------------------------------------------- /Day22/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day22/screenshot.png -------------------------------------------------------------------------------- /Day23/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day23/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Color exposing (Color) 4 | import Svg exposing (Svg) 5 | import Svg.Attributes 6 | import Html exposing (Html) 7 | import Html.Attributes 8 | import Color.Convert 9 | import Time exposing (Time) 10 | import AnimationFrame 11 | import Random 12 | import Random.Color 13 | import Color.Mixing 14 | import Mouse 15 | import Window 16 | import Task 17 | 18 | 19 | type alias Blade = 20 | { color : Color 21 | , size : Float 22 | , angle : Float 23 | } 24 | 25 | 26 | type alias Model = 27 | { blades : List Blade 28 | , done : Bool 29 | , mousePosition : { x : Int, y : Int } 30 | , windowSize : { width : Int, height : Int } 31 | } 32 | 33 | 34 | initialModel : Model 35 | initialModel = 36 | { blades = 37 | List.range 0 50 38 | |> List.map 39 | (\i -> 40 | { color = Color.darkGreen 41 | , size = 5 42 | , angle = degrees <| (toFloat i / 50 * 40) - 20 43 | } 44 | ) 45 | , done = False 46 | , mousePosition = { x = 0, y = 0 } 47 | , windowSize = { width = 1, height = 1 } 48 | } 49 | 50 | 51 | grow : Float -> Color -> Int -> List Blade -> List Blade 52 | grow xPercent growthColor whichBlade blades = 53 | List.indexedMap 54 | (\i blade -> 55 | if i == whichBlade then 56 | { blade 57 | | size = 58 | blade.size + 0.7 * ((1 - abs ((toFloat i / 50) - xPercent)) ^ 8) 59 | , color = 60 | blade.color 61 | |> Color.Mixing.mix 0.01 growthColor 62 | } 63 | else 64 | blade 65 | ) 66 | blades 67 | 68 | 69 | renderBlade : Int -> Blade -> Svg msg 70 | renderBlade i blade = 71 | Svg.polygon 72 | [ Svg.Attributes.points <| "-1.2,0 0," ++ toString (-blade.size) ++ " 1.2,0" 73 | , Svg.Attributes.fill (Color.Convert.colorToHex blade.color) 74 | , Svg.Attributes.transform <| 75 | String.join " " 76 | [ "translate(" ++ toString (i - 50 // 2) ++ ",0)" 77 | , "rotate(" ++ toString (blade.angle / pi * 180) ++ ")" 78 | ] 79 | ] 80 | [] 81 | 82 | 83 | pointer : Float -> Svg msg 84 | pointer pct = 85 | let 86 | pointerPosition = 87 | "translate(" ++ (toString <| (pct * 50) - 50 / 2) ++ ",37)" 88 | in 89 | Svg.polygon 90 | [ Svg.Attributes.points "-1,0 0,-2 1,0 0,2" 91 | , Svg.Attributes.fill "#ffc" 92 | , Svg.Attributes.transform pointerPosition 93 | ] 94 | [] 95 | 96 | 97 | view : Model -> Html msg 98 | view model = 99 | Svg.svg 100 | [ Svg.Attributes.viewBox "-50 -50 100 100" 101 | , Html.Attributes.style 102 | [ ( "max-height", "100vh" ) ] 103 | ] 104 | [ Svg.rect 105 | [ Svg.Attributes.x "-150" 106 | , Svg.Attributes.y "-150" 107 | , Svg.Attributes.width "300" 108 | , Svg.Attributes.height "300" 109 | , Svg.Attributes.fill "#222" 110 | ] 111 | [] 112 | , pointer <| toFloat model.mousePosition.x / toFloat model.windowSize.width 113 | , List.indexedMap renderBlade model.blades 114 | |> Svg.g [ Svg.Attributes.transform "translate(0,35)" ] 115 | ] 116 | 117 | 118 | type Msg 119 | = Tick Time 120 | | GrowBlades (List ( Int, Color )) 121 | | MouseMoved Mouse.Position 122 | | WindowSize Window.Size 123 | 124 | 125 | checkDone : Model -> Model 126 | checkDone model = 127 | if List.any (\blade -> blade.size > 80) model.blades then 128 | { model | done = True } 129 | else 130 | model 131 | 132 | 133 | update : Msg -> Model -> ( Model, Cmd Msg ) 134 | update msg model = 135 | case msg of 136 | Tick now -> 137 | ( model 138 | , Random.generate 139 | GrowBlades 140 | (Random.list 10 141 | (Random.map2 (,) 142 | (Random.int 0 (List.length model.blades)) 143 | (Random.Color.rgb) 144 | ) 145 | ) 146 | ) 147 | 148 | GrowBlades growths -> 149 | let 150 | growBlade ( i, color ) blades = 151 | grow 152 | (toFloat model.mousePosition.x 153 | / toFloat model.windowSize.width 154 | ) 155 | color 156 | i 157 | blades 158 | in 159 | ( { model 160 | | blades = 161 | List.foldl growBlade model.blades growths 162 | } 163 | |> checkDone 164 | , Cmd.none 165 | ) 166 | 167 | MouseMoved pos -> 168 | ( { model | mousePosition = pos } 169 | , Cmd.none 170 | ) 171 | 172 | WindowSize newSize -> 173 | ( { model | windowSize = newSize } 174 | , Cmd.none 175 | ) 176 | 177 | 178 | main : Program Never Model Msg 179 | main = 180 | Html.program 181 | { init = 182 | ( initialModel 183 | , Window.size |> Task.perform WindowSize 184 | ) 185 | , subscriptions = 186 | \model -> 187 | Sub.batch 188 | [ if model.done then 189 | Sub.none 190 | else 191 | AnimationFrame.times Tick 192 | , Mouse.moves MouseMoved 193 | , Window.resizes WindowSize 194 | ] 195 | , update = update 196 | , view = view 197 | } 198 | -------------------------------------------------------------------------------- /Day23/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/random-extra": "2.0.0 <= v < 3.0.0", 12 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 13 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 14 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 15 | "elm-lang/mouse": "1.0.1 <= v < 2.0.0", 16 | "elm-lang/svg": "2.0.0 <= v < 3.0.0", 17 | "elm-lang/window": "1.0.1 <= v < 2.0.0", 18 | "eskimoblood/elm-color-extra": "3.2.3 <= v < 4.0.0", 19 | "mdgriffith/elm-color-mixing": "1.0.4 <= v < 2.0.0" 20 | }, 21 | "elm-version": "0.18.0 <= v < 0.19.0" 22 | } 23 | -------------------------------------------------------------------------------- /Day23/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day23/screenshot.mp4 -------------------------------------------------------------------------------- /Day24/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day24/Board.elm: -------------------------------------------------------------------------------- 1 | module Board exposing (Board, Tile(..), Piece(..), Position, new, makeMove, view) 2 | 3 | import Color exposing (Color) 4 | import Dict exposing (Dict) 5 | 6 | 7 | type Piece 8 | = Player1 9 | | Player2 10 | 11 | 12 | type Tile 13 | = Empty Color 14 | | Occupied Piece Color 15 | | DoesntExist 16 | 17 | 18 | type Board 19 | = Board 20 | { columns : Int 21 | , rows : Int 22 | , tiles : Dict Position Tile 23 | } 24 | 25 | 26 | type alias Position = 27 | ( Int, Int ) 28 | 29 | 30 | new : Board 31 | new = 32 | Board 33 | { columns = 8 34 | , rows = 8 35 | , tiles = Dict.empty 36 | } 37 | |> map 38 | (\( row, col ) _ -> 39 | if (row + col) % 2 == 0 then 40 | Empty Color.red 41 | else 42 | Empty Color.yellow 43 | ) 44 | |> map 45 | (\( row, col ) tile -> 46 | case ( tile, (row + col) % 2 ) of 47 | ( Empty color, 0 ) -> 48 | if row == 1 || row == 2 then 49 | Occupied Player1 color 50 | else if row == 7 || row == 8 then 51 | Occupied Player2 color 52 | else 53 | tile 54 | 55 | _ -> 56 | tile 57 | ) 58 | 59 | 60 | map : (Position -> Tile -> Tile) -> Board -> Board 61 | map fn (Board board) = 62 | let 63 | mapTile row col tiles = 64 | let 65 | pos = 66 | ( col, row ) 67 | 68 | tile = 69 | Dict.get pos tiles 70 | |> Maybe.withDefault DoesntExist 71 | in 72 | tiles 73 | |> Dict.insert pos 74 | (fn pos tile) 75 | 76 | mapRow row tiles = 77 | List.foldl (mapTile row) tiles (List.range 1 board.columns) 78 | 79 | mapAll tiles = 80 | List.foldl mapRow tiles (List.range 1 board.rows) 81 | in 82 | Board { board | tiles = mapAll board.tiles } 83 | 84 | 85 | makeMove : Position -> Position -> Board -> Board 86 | makeMove from to (Board board) = 87 | let 88 | fromTile = 89 | Dict.get from board.tiles 90 | |> Maybe.withDefault DoesntExist 91 | 92 | toTile = 93 | Dict.get to board.tiles 94 | |> Maybe.withDefault DoesntExist 95 | 96 | ( newFromTile, newToTile ) = 97 | case ( fromTile, toTile ) of 98 | ( Occupied piece fromColor, Empty toColor ) -> 99 | ( Empty fromColor, Occupied piece toColor ) 100 | 101 | _ -> 102 | ( fromTile, toTile ) 103 | in 104 | Board 105 | { board 106 | | tiles = 107 | board.tiles 108 | |> Dict.insert from newFromTile 109 | |> Dict.insert to newToTile 110 | } 111 | 112 | 113 | view : (Position -> Tile -> result) -> Board -> List (List result) 114 | view renderTile (Board board) = 115 | let 116 | makeRow row = 117 | List.range 1 board.columns 118 | |> List.map (makeTile row) 119 | 120 | makeTile row col = 121 | Dict.get ( col, row ) board.tiles 122 | |> Maybe.withDefault DoesntExist 123 | |> renderTile ( col, row ) 124 | in 125 | List.range 1 board.rows 126 | |> List.map makeRow 127 | -------------------------------------------------------------------------------- /Day24/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Board exposing (Board) 4 | import Html exposing (Html) 5 | import Color.Convert 6 | import Svg exposing (Svg) 7 | import Svg.Attributes 8 | import Html.Attributes 9 | import Svg.Events 10 | 11 | 12 | type alias Model = 13 | { board : Board 14 | , selectedTile : Maybe Board.Position 15 | } 16 | 17 | 18 | initialModel : Model 19 | initialModel = 20 | { board = Board.new 21 | , selectedTile = Nothing 22 | } 23 | 24 | 25 | type Msg 26 | = ClickTile Board.Position 27 | 28 | 29 | update : Msg -> Model -> ( Model, Cmd Msg ) 30 | update msg model = 31 | case msg of 32 | ClickTile pos -> 33 | case model.selectedTile of 34 | Nothing -> 35 | ( { model | selectedTile = Just pos } 36 | , Cmd.none 37 | ) 38 | 39 | Just selected -> 40 | ( { model 41 | | board = Board.makeMove selected pos model.board 42 | , selectedTile = Nothing 43 | } 44 | , Cmd.none 45 | ) 46 | 47 | 48 | view : Model -> Html Msg 49 | view model = 50 | let 51 | renderTile pos tile = 52 | case tile of 53 | Board.DoesntExist -> 54 | Svg.g [] [] 55 | 56 | Board.Empty color -> 57 | Svg.rect 58 | [ Svg.Attributes.x "-5" 59 | , Svg.Attributes.y "-5" 60 | , Svg.Attributes.width "10" 61 | , Svg.Attributes.height "10" 62 | , Svg.Attributes.fill (Color.Convert.colorToHex color) 63 | , Svg.Events.onClick (ClickTile pos) 64 | ] 65 | [] 66 | 67 | Board.Occupied piece color -> 68 | Svg.g 69 | [ Svg.Events.onClick (ClickTile pos) 70 | ] 71 | [ renderTile pos (Board.Empty color) 72 | , Svg.circle 73 | [ Svg.Attributes.r "4" 74 | , Svg.Attributes.fill <| 75 | case piece of 76 | Board.Player1 -> 77 | "#111" 78 | 79 | Board.Player2 -> 80 | "#eee" 81 | , if model.selectedTile == Just pos then 82 | Svg.Attributes.stroke "#22e" 83 | else 84 | Svg.Attributes.stroke "none" 85 | ] 86 | [] 87 | ] 88 | 89 | combineRow tiles = 90 | List.indexedMap 91 | (\col tile -> 92 | Svg.g [ Svg.Attributes.transform ("translate(" ++ toString (col * 10) ++ ",0)") ] 93 | [ tile ] 94 | ) 95 | tiles 96 | in 97 | Board.view renderTile model.board 98 | |> List.indexedMap 99 | (\row tiles -> 100 | Svg.g [ Svg.Attributes.transform ("translate(0," ++ toString (row * 10) ++ ")") ] 101 | (combineRow tiles) 102 | ) 103 | |> Svg.svg 104 | [ Svg.Attributes.viewBox "-5 -5 80 80" 105 | , Html.Attributes.style [ ( "max-height", "100vh" ) ] 106 | ] 107 | 108 | 109 | main : Program Never Model Msg 110 | main = 111 | Html.program 112 | { init = ( initialModel, Cmd.none ) 113 | , subscriptions = \_ -> Sub.none 114 | , update = update 115 | , view = view 116 | } 117 | -------------------------------------------------------------------------------- /Day24/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 12 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 13 | "elm-lang/svg": "2.0.0 <= v < 3.0.0", 14 | "eskimoblood/elm-color-extra": "3.2.3 <= v < 4.0.0" 15 | }, 16 | "elm-version": "0.18.0 <= v < 0.19.0" 17 | } 18 | -------------------------------------------------------------------------------- /Day24/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day24/screenshot.gif -------------------------------------------------------------------------------- /Day25/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day25/Board.elm: -------------------------------------------------------------------------------- 1 | module Board 2 | exposing 3 | ( Board 4 | , Tile(..) 5 | , Piece(..) 6 | , Player(..) 7 | , Position 8 | , new 9 | , makeMove 10 | , view 11 | ) 12 | 13 | import Color exposing (Color) 14 | import Dict exposing (Dict) 15 | import Set exposing (Set) 16 | import Random 17 | import Random.Extra 18 | 19 | 20 | type Player 21 | = Player1 22 | | Player2 23 | 24 | 25 | type Piece 26 | = BasicPiece 27 | | TerraformingPiece TerraformingShape 28 | 29 | 30 | type Tile 31 | = Tile (List Color) 32 | 33 | 34 | type Board 35 | = Board 36 | { columns : Int 37 | , rows : Int 38 | , tiles : Dict Position Tile 39 | , pieces : Dict Position ( Player, Piece ) 40 | } 41 | 42 | 43 | type alias TerraformingShape = 44 | Set ( Int, Int ) 45 | 46 | 47 | type alias Position = 48 | ( Int, Int ) 49 | 50 | 51 | possibleShapes : List TerraformingShape 52 | possibleShapes = 53 | [ Set.fromList [ ( 0, 0 ), ( 1, 0 ), ( 0, -1 ), ( 0, 1 ) ] 54 | , Set.fromList [ ( 0, 0 ), ( 1, 0 ), ( 2, 0 ), ( -1, 0 ) ] 55 | , Set.fromList [ ( 0, 0 ), ( 1, 0 ), ( 1, 1 ), ( 0, 1 ) ] 56 | , Set.fromList [ ( 0, 0 ), ( 1, 0 ), ( -1, 0 ), ( 1, 1 ) ] 57 | , Set.fromList [ ( 0, 0 ), ( 1, 0 ), ( -1, 0 ), ( 1, -1 ) ] 58 | ] 59 | 60 | 61 | new : Random.Seed -> Board 62 | new seed = 63 | Board 64 | { columns = 8 65 | , rows = 8 66 | , tiles = Dict.empty 67 | , pieces = 68 | List.foldl 69 | (\i ( pieces, seed1 ) -> 70 | let 71 | ( p1Shape, seed2 ) = 72 | Random.step (Random.Extra.sample possibleShapes) seed1 73 | 74 | ( p2Shape, seed3 ) = 75 | Random.step (Random.Extra.sample possibleShapes) seed2 76 | in 77 | ( pieces 78 | |> Dict.insert ( 2 - i % 2, i ) 79 | ( Player1 80 | , p1Shape 81 | |> Maybe.map TerraformingPiece 82 | |> Maybe.withDefault BasicPiece 83 | ) 84 | |> Dict.insert ( 8 - i % 2, i ) 85 | ( Player2 86 | , p2Shape 87 | |> Maybe.map TerraformingPiece 88 | |> Maybe.withDefault BasicPiece 89 | ) 90 | , seed3 91 | ) 92 | ) 93 | ( Dict.empty, seed ) 94 | (List.range 1 8) 95 | |> Tuple.first 96 | } 97 | |> mapTiles 98 | (\( row, col ) _ -> 99 | if (row + col) % 2 == 0 then 100 | Tile [ Color.red ] 101 | else 102 | Tile [ Color.yellow ] 103 | ) 104 | 105 | 106 | mapTiles : (Position -> Tile -> Tile) -> Board -> Board 107 | mapTiles fn (Board board) = 108 | let 109 | mapTile row col tiles = 110 | let 111 | pos = 112 | ( col, row ) 113 | 114 | tile = 115 | Dict.get pos tiles 116 | |> Maybe.withDefault (Tile []) 117 | in 118 | tiles 119 | |> Dict.insert pos 120 | (fn pos tile) 121 | 122 | mapRow row tiles = 123 | List.foldl (mapTile row) tiles (List.range 1 board.columns) 124 | 125 | mapAll tiles = 126 | List.foldl mapRow tiles (List.range 1 board.rows) 127 | in 128 | Board { board | tiles = mapAll board.tiles } 129 | 130 | 131 | pullTopColor : Tile -> ( Maybe Color, Tile ) 132 | pullTopColor (Tile colors) = 133 | case colors of 134 | [] -> 135 | ( Nothing, (Tile colors) ) 136 | 137 | topColor :: rest -> 138 | ( Just topColor, Tile rest ) 139 | 140 | 141 | pushTopColor : Color -> Tile -> Tile 142 | pushTopColor newColor (Tile colors) = 143 | Tile (newColor :: colors) 144 | 145 | 146 | add : Position -> Position -> Position 147 | add ( x, y ) ( x1, y1 ) = 148 | ( x + x1, y + y1 ) 149 | 150 | 151 | terraformBoard : TerraformingShape -> Position -> Position -> Dict Position Tile -> Dict Position Tile 152 | terraformBoard relativeFroms fromCenter toCenter tiles = 153 | let 154 | calcMovement : ( Int, Int ) -> ( Position, Tile, Maybe Color, Position ) 155 | calcMovement rel = 156 | let 157 | fromPos = 158 | add rel fromCenter 159 | 160 | ( movingColor, reminaingTile ) = 161 | tiles 162 | |> Dict.get fromPos 163 | |> Maybe.withDefault (Tile []) 164 | |> pullTopColor 165 | in 166 | ( add rel fromCenter 167 | , reminaingTile 168 | , movingColor 169 | , add rel toCenter 170 | ) 171 | 172 | movements : List ( Position, Tile, Maybe Color, Position ) 173 | movements = 174 | relativeFroms 175 | |> Set.toList 176 | |> List.map calcMovement 177 | 178 | withTopsRemoved : Dict Position Tile 179 | withTopsRemoved = 180 | List.foldl 181 | (\( pos, tile, _, _ ) tiles -> 182 | Dict.insert pos tile tiles 183 | ) 184 | tiles 185 | movements 186 | 187 | withColorsPushed : Dict Position Tile 188 | withColorsPushed = 189 | List.foldl 190 | (\( _, _, color, pos ) -> 191 | Dict.update pos 192 | (\tile -> 193 | case color of 194 | Nothing -> 195 | tile 196 | 197 | Just color -> 198 | Maybe.map (pushTopColor color) tile 199 | ) 200 | ) 201 | withTopsRemoved 202 | movements 203 | in 204 | withColorsPushed 205 | 206 | 207 | makeMove : Position -> Position -> Board -> Board 208 | makeMove from to (Board board) = 209 | let 210 | piece = 211 | Dict.get from board.pieces 212 | 213 | isValidMove = 214 | not (Dict.member to board.pieces) 215 | 216 | newTiles = 217 | case piece of 218 | Just ( _, TerraformingPiece shape ) -> 219 | terraformBoard shape from to board.tiles 220 | 221 | _ -> 222 | board.tiles 223 | in 224 | case ( piece, isValidMove ) of 225 | ( Just piece, True ) -> 226 | Board 227 | { board 228 | | pieces = 229 | board.pieces 230 | |> Dict.remove from 231 | |> Dict.insert to piece 232 | , tiles = newTiles 233 | } 234 | 235 | _ -> 236 | Board board 237 | 238 | 239 | view : (Position -> Tile -> Maybe ( Player, Piece ) -> result) -> Board -> List (List result) 240 | view renderTile (Board board) = 241 | let 242 | makeRow row = 243 | List.range 1 board.columns 244 | |> List.map (makeTile row) 245 | 246 | makeTile row col = 247 | Dict.get ( col, row ) board.tiles 248 | |> Maybe.withDefault (Tile []) 249 | |> (\tile -> 250 | renderTile ( col, row ) 251 | tile 252 | (Dict.get ( col, row ) board.pieces) 253 | ) 254 | in 255 | List.range 1 board.rows 256 | |> List.map makeRow 257 | -------------------------------------------------------------------------------- /Day25/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Board exposing (Board) 4 | import Html exposing (Html) 5 | import Color.Convert 6 | import Svg exposing (Svg) 7 | import Svg.Attributes 8 | import Html.Attributes 9 | import Svg.Events 10 | import Set exposing (Set) 11 | import Random 12 | import Time exposing (Time) 13 | import Task 14 | 15 | 16 | type alias Model = 17 | { board : Maybe Board 18 | , selectedTile : Maybe Board.Position 19 | } 20 | 21 | 22 | initialModel : Model 23 | initialModel = 24 | { board = Nothing 25 | , selectedTile = Nothing 26 | } 27 | 28 | 29 | type Msg 30 | = ClickTile Board.Position 31 | | CreateGame Random.Seed 32 | 33 | 34 | update : Msg -> Model -> ( Model, Cmd Msg ) 35 | update msg model = 36 | case msg of 37 | ClickTile pos -> 38 | case model.selectedTile of 39 | Nothing -> 40 | ( { model | selectedTile = Just pos } 41 | , Cmd.none 42 | ) 43 | 44 | Just selected -> 45 | ( { model 46 | | board = 47 | model.board 48 | |> Maybe.map (Board.makeMove selected pos) 49 | , selectedTile = Nothing 50 | } 51 | , Cmd.none 52 | ) 53 | 54 | CreateGame seed -> 55 | ( { board = Board.new seed |> Just 56 | , selectedTile = Nothing 57 | } 58 | , Cmd.none 59 | ) 60 | 61 | 62 | view : Model -> Html Msg 63 | view model = 64 | let 65 | renderTile pos tile piece = 66 | Svg.g [] 67 | [ case tile of 68 | Board.Tile [] -> 69 | Svg.rect 70 | [ Svg.Attributes.x "-5" 71 | , Svg.Attributes.y "-5" 72 | , Svg.Attributes.width "10" 73 | , Svg.Attributes.height "10" 74 | , Svg.Attributes.fill "transparent" 75 | , Svg.Events.onClick (ClickTile pos) 76 | ] 77 | [] 78 | 79 | Board.Tile (color :: _) -> 80 | Svg.rect 81 | [ Svg.Attributes.x "-5" 82 | , Svg.Attributes.y "-5" 83 | , Svg.Attributes.width "10" 84 | , Svg.Attributes.height "10" 85 | , Svg.Attributes.fill (Color.Convert.colorToHex color) 86 | , Svg.Events.onClick (ClickTile pos) 87 | ] 88 | [] 89 | , case piece of 90 | Nothing -> 91 | Html.text "" 92 | 93 | Just ( player, piece ) -> 94 | Svg.g 95 | [ Svg.Events.onClick (ClickTile pos) 96 | ] 97 | [ Svg.circle 98 | [ Svg.Attributes.r "4" 99 | , Svg.Attributes.fill <| 100 | case player of 101 | Board.Player1 -> 102 | "#111" 103 | 104 | Board.Player2 -> 105 | "#eee" 106 | , if model.selectedTile == Just pos then 107 | Svg.Attributes.stroke "#22e" 108 | else 109 | Svg.Attributes.stroke "none" 110 | ] 111 | [] 112 | , case piece of 113 | Board.BasicPiece -> 114 | Html.text "" 115 | 116 | Board.TerraformingPiece shape -> 117 | Set.toList shape 118 | |> List.map 119 | (\( x, y ) -> 120 | Svg.rect 121 | [ Svg.Attributes.x "-0.5" 122 | , Svg.Attributes.y "-0.5" 123 | , Svg.Attributes.width "1" 124 | , Svg.Attributes.height "1" 125 | , Svg.Attributes.fill <| 126 | case player of 127 | Board.Player1 -> 128 | "#eee" 129 | 130 | Board.Player2 -> 131 | "#111" 132 | , Svg.Attributes.transform 133 | ("translate(" 134 | ++ toString (toFloat x * 1.2) 135 | ++ "," 136 | ++ toString (toFloat y * 1.2) 137 | ++ ")" 138 | ) 139 | ] 140 | [] 141 | ) 142 | |> Svg.g [] 143 | ] 144 | ] 145 | 146 | combineRow tiles = 147 | List.indexedMap 148 | (\col tile -> 149 | Svg.g [ Svg.Attributes.transform ("translate(" ++ toString (col * 10) ++ ",0)") ] 150 | [ tile ] 151 | ) 152 | tiles 153 | in 154 | case model.board of 155 | Nothing -> 156 | Html.text "" 157 | 158 | Just board -> 159 | Board.view renderTile board 160 | |> List.indexedMap 161 | (\row tiles -> 162 | Svg.g [ Svg.Attributes.transform ("translate(0," ++ toString (row * 10) ++ ")") ] 163 | (combineRow tiles) 164 | ) 165 | |> Svg.svg 166 | [ Svg.Attributes.viewBox "-5 -5 80 80" 167 | , Html.Attributes.style [ ( "max-height", "100vh" ) ] 168 | ] 169 | 170 | 171 | main : Program Never Model Msg 172 | main = 173 | Html.program 174 | { init = 175 | ( initialModel 176 | , Time.now 177 | |> Task.map (floor >> Random.initialSeed) 178 | |> Task.perform CreateGame 179 | ) 180 | , subscriptions = \_ -> Sub.none 181 | , update = update 182 | , view = view 183 | } 184 | -------------------------------------------------------------------------------- /Day25/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/random-extra": "2.0.0 <= v < 3.0.0", 12 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 13 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 14 | "elm-lang/svg": "2.0.0 <= v < 3.0.0", 15 | "eskimoblood/elm-color-extra": "3.2.3 <= v < 4.0.0" 16 | }, 17 | "elm-version": "0.18.0 <= v < 0.19.0" 18 | } 19 | -------------------------------------------------------------------------------- /Day25/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day25/screenshot.gif -------------------------------------------------------------------------------- /Day26/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day26/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/easing-functions": "1.0.2 <= v < 2.0.0", 12 | "elm-community/random-extra": "2.0.0 <= v < 3.0.0", 13 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 14 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 15 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 16 | "elm-lang/svg": "2.0.0 <= v < 3.0.0", 17 | "eskimoblood/elm-color-extra": "3.2.3 <= v < 4.0.0" 18 | }, 19 | "elm-version": "0.18.0 <= v < 0.19.0" 20 | } 21 | -------------------------------------------------------------------------------- /Day26/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day26/screenshot.gif -------------------------------------------------------------------------------- /Day27/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day27/Coin.elm: -------------------------------------------------------------------------------- 1 | module Coin exposing (..) 2 | 3 | import Math.Vector2 exposing (..) 4 | 5 | 6 | type alias Point = 7 | Vec2 8 | 9 | 10 | type alias FlatCoin = 11 | { center : Point 12 | , radius : Float 13 | } 14 | 15 | 16 | type alias FlippingCoin = 17 | { anchor : Point 18 | , flipAngle : Float 19 | , centerDirection : Vec2 20 | , radius : Float 21 | } 22 | 23 | 24 | type alias FallingCoin = 25 | { anchor : Point 26 | , fallAngle : Float 27 | , centerDirection : Vec2 28 | , radius : Float 29 | } 30 | 31 | 32 | startFlip : Point -> FlatCoin -> FlippingCoin 33 | startFlip mousePosition coin = 34 | { anchor = 35 | (direction mousePosition coin.center) 36 | |> Math.Vector2.negate 37 | |> scale coin.radius 38 | |> add coin.center 39 | , radius = coin.radius 40 | , centerDirection = direction mousePosition coin.center 41 | , flipAngle = 0 42 | } 43 | 44 | 45 | type PushResult 46 | = Stopped FlatCoin 47 | | Continue FlippingCoin 48 | | Flipped FallingCoin 49 | 50 | 51 | pushFlippingCoin : Point -> FlippingCoin -> PushResult 52 | pushFlippingCoin mousePosition coin = 53 | let 54 | d = 55 | dot (sub mousePosition coin.anchor) coin.centerDirection 56 | / (2 * coin.radius) 57 | in 58 | if d >= 1 then 59 | Stopped 60 | { center = add coin.anchor (scale coin.radius coin.centerDirection) 61 | , radius = coin.radius 62 | } 63 | else if d <= 0.03 then 64 | Flipped 65 | { anchor = coin.anchor 66 | , radius = coin.radius 67 | , centerDirection = coin.centerDirection 68 | , fallAngle = degrees 90 69 | } 70 | else 71 | Continue 72 | { coin 73 | | flipAngle = 74 | acos d 75 | } 76 | 77 | 78 | advanceFallingCoin : FallingCoin -> Result FlatCoin FallingCoin 79 | advanceFallingCoin coin = 80 | let 81 | newAngle = 82 | coin.fallAngle + (degrees 3) 83 | in 84 | if newAngle >= (degrees 180) then 85 | Err 86 | { radius = coin.radius 87 | , center = add coin.anchor (scale -coin.radius coin.centerDirection) 88 | } 89 | else 90 | Ok { coin | fallAngle = newAngle } 91 | -------------------------------------------------------------------------------- /Day27/Svg/Util.elm: -------------------------------------------------------------------------------- 1 | module Svg.Util exposing (..) 2 | 3 | import Math.Vector2 exposing (..) 4 | 5 | 6 | translateString : Vec2 -> String 7 | translateString p = 8 | "translate(" 9 | ++ (p |> getX |> toString) 10 | ++ "," 11 | ++ (p |> getY |> toString) 12 | ++ ")" 13 | 14 | 15 | rotateString : Float -> String 16 | rotateString angle = 17 | "rotate(" 18 | ++ (toString <| 180 / pi * angle) 19 | ++ ")" 20 | -------------------------------------------------------------------------------- /Day27/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/linear-algebra": "1.0.0 <= v < 2.0.0", 12 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 13 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 14 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 15 | "elm-lang/mouse": "1.0.1 <= v < 2.0.0", 16 | "elm-lang/svg": "2.0.0 <= v < 3.0.0", 17 | "elm-lang/window": "1.0.1 <= v < 2.0.0" 18 | }, 19 | "elm-version": "0.18.0 <= v < 0.19.0" 20 | } 21 | -------------------------------------------------------------------------------- /Day27/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day27/screenshot.gif -------------------------------------------------------------------------------- /Day28/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day28/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Math.Vector2 exposing (..) 4 | import Time exposing (Time) 5 | import AnimationFrame 6 | import Particle exposing (Particle) 7 | import Html exposing (Html) 8 | import Collage 9 | import Element 10 | import Color exposing (Color) 11 | import Random 12 | 13 | 14 | particleCount : Int 15 | particleCount = 16 | 1000 17 | 18 | 19 | type alias Model = 20 | { particles : List Particle 21 | , t : Time 22 | } 23 | 24 | 25 | initialModel : Model 26 | initialModel = 27 | { particles = 28 | [ Particle (vec2 0 0) (vec2 5 5) 29 | , Particle (vec2 10 0) (vec2 -2 3) 30 | ] 31 | , t = 0 32 | } 33 | 34 | 35 | type Msg 36 | = Tick Time 37 | | NewParticles (List Particle) 38 | | AddParticles (List Particle) 39 | 40 | 41 | update : Msg -> Model -> ( Model, Cmd Msg ) 42 | update msg model = 43 | case msg of 44 | Tick t -> 45 | ( { model 46 | | t = model.t + 0.1 47 | , particles = 48 | List.map (Particle.update t 0.1) model.particles 49 | |> List.filter (Particle.inBounds ( -375, -250 ) ( 375, 250 )) 50 | } 51 | , if List.length model.particles < particleCount then 52 | Random.generate AddParticles (Random.list 5 Particle.random) 53 | else 54 | Cmd.none 55 | ) 56 | 57 | NewParticles particles -> 58 | ( { model | particles = particles } 59 | , Cmd.none 60 | ) 61 | 62 | AddParticles particle -> 63 | ( { model | particles = particle ++ model.particles } 64 | , Cmd.none 65 | ) 66 | 67 | 68 | drawParticle : Particle -> Collage.Form 69 | drawParticle particle = 70 | let 71 | a = 72 | scale 0.2 particle.vel 73 | 74 | b = 75 | scale -0.2 particle.vel 76 | in 77 | Collage.segment (toTuple a) (toTuple b) 78 | |> Collage.traced 79 | { color = Color.hsl 0 0 (length particle.pos / 500) 80 | , width = 3 81 | , cap = Collage.Flat 82 | , join = Collage.Clipped 83 | , dashing = [] 84 | , dashOffset = 0 85 | } 86 | |> Collage.move (toTuple particle.pos) 87 | 88 | 89 | view : Model -> Html msg 90 | view model = 91 | [ Collage.rect 750 500 92 | |> Collage.filled (Color.hsl (degrees 206) 0.5 (0.5 + (0.3 * sin (model.t / 100)))) 93 | , model.particles 94 | |> List.map drawParticle 95 | |> Collage.group 96 | ] 97 | |> Collage.collage 750 500 98 | |> Element.toHtml 99 | 100 | 101 | main : Program Never Model Msg 102 | main = 103 | Html.program 104 | { init = 105 | ( initialModel 106 | , Random.generate NewParticles (Random.list particleCount Particle.random) 107 | ) 108 | , subscriptions = 109 | \model -> 110 | if List.length model.particles > 0 then 111 | AnimationFrame.times Tick 112 | else 113 | Sub.none 114 | , update = update 115 | , view = view 116 | } 117 | -------------------------------------------------------------------------------- /Day28/Particle.elm: -------------------------------------------------------------------------------- 1 | module Particle exposing (Particle, inBounds, update, random) 2 | 3 | import Math.Vector2 exposing (..) 4 | import Random 5 | 6 | 7 | type alias Particle = 8 | { pos : Vec2 9 | , vel : Vec2 10 | } 11 | 12 | 13 | inBounds : ( Float, Float ) -> ( Float, Float ) -> Particle -> Bool 14 | inBounds ( minx, miny ) ( maxx, maxy ) particle = 15 | let 16 | x = 17 | getX particle.pos 18 | 19 | y = 20 | getY particle.pos 21 | in 22 | x >= minx && x <= maxx && y >= miny && y <= maxy 23 | 24 | 25 | update : Float -> Float -> Particle -> Particle 26 | update t dt particle = 27 | let 28 | ( x, y ) = 29 | toTuple particle.pos 30 | 31 | dvel = 32 | vec2 33 | (sin (x / 100 + t)) 34 | (cos (x / 100 + t)) 35 | |> scale 5 36 | in 37 | { particle 38 | | pos = 39 | particle.pos 40 | |> add (scale dt particle.vel) 41 | , vel = 42 | particle.vel 43 | |> add dvel 44 | } 45 | 46 | 47 | randomVec2 : ( Float, Float ) -> ( Float, Float ) -> Random.Generator Vec2 48 | randomVec2 ( minx, miny ) ( maxx, maxy ) = 49 | Random.map2 vec2 50 | (Random.float minx maxx) 51 | (Random.float miny maxy) 52 | 53 | 54 | random : Random.Generator Particle 55 | random = 56 | Random.map2 Particle 57 | (randomVec2 ( -375, -250 ) ( 275, 250 )) 58 | (randomVec2 ( -1, -1 ) ( 1, 1 )) 59 | -------------------------------------------------------------------------------- /Day28/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/linear-algebra": "1.0.0 <= v < 2.0.0", 12 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 13 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 14 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 15 | "evancz/elm-graphics": "1.0.1 <= v < 2.0.0" 16 | }, 17 | "elm-version": "0.18.0 <= v < 0.19.0" 18 | } 19 | -------------------------------------------------------------------------------- /Day28/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day28/screenshot.mp4 -------------------------------------------------------------------------------- /Day29/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day29/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Math.Vector2 exposing (..) 4 | import Time exposing (Time) 5 | import AnimationFrame 6 | import Particle exposing (Particle) 7 | import Html exposing (Html) 8 | import Collage 9 | import Element 10 | import Color exposing (Color) 11 | import Random 12 | 13 | 14 | particleCount : Int 15 | particleCount = 16 | 200 17 | 18 | 19 | type alias Model = 20 | { particles : List Particle 21 | , t : Time 22 | , i : Int 23 | } 24 | 25 | 26 | initialModel : Model 27 | initialModel = 28 | { particles = 29 | [ Particle (vec2 -10 0) True 30 | , Particle (vec2 10 0) False 31 | , Particle (vec2 20 10) False 32 | ] 33 | , t = 0 34 | , i = 0 35 | } 36 | 37 | 38 | type Msg 39 | = Tick Time 40 | | NewParticles (List Particle) 41 | | AddParticles (List Particle) 42 | 43 | 44 | update : Msg -> Model -> ( Model, Cmd Msg ) 45 | update msg model = 46 | case msg of 47 | Tick t -> 48 | ( { model 49 | | t = model.t + 0.1 50 | , i = model.i + 1 51 | , particles = 52 | List.indexedMap 53 | (\i p -> 54 | -- if (i % 20) == (model.i % 20) then 55 | Particle.update 56 | (List.filter (\n -> distance n.pos p.pos < 100) model.particles) 57 | p 58 | -- else 59 | -- p 60 | ) 61 | model.particles 62 | |> List.filter (Particle.inBounds ( -375, -250 ) ( 375, 250 )) 63 | } 64 | , if List.length model.particles < particleCount then 65 | Random.generate AddParticles (Random.list 5 Particle.random) 66 | else 67 | Cmd.none 68 | ) 69 | 70 | NewParticles particles -> 71 | ( model 72 | , Cmd.none 73 | ) 74 | 75 | AddParticles particle -> 76 | ( { model | particles = particle ++ model.particles } 77 | , Cmd.none 78 | ) 79 | 80 | 81 | drawParticle : Particle -> Collage.Form 82 | drawParticle particle = 83 | let 84 | color = 85 | if particle.kind then 86 | Color.black 87 | else 88 | Color.white 89 | 90 | -- a = 91 | -- scale 0.2 particle.vel 92 | -- 93 | -- b = 94 | -- scale -0.2 particle.vel 95 | in 96 | Collage.circle 3 97 | |> Collage.filled color 98 | -- Collage.segment 99 | -- (toTuple a) 100 | -- (toTuple b) 101 | -- |> Collage.traced 102 | -- { color = Color.hsl 0 0 (length particle.pos / 500) 103 | -- , width = 3 104 | -- , cap = Collage.Flat 105 | -- , join = Collage.Clipped 106 | -- , dashing = [] 107 | -- , dashOffset = 0 108 | -- } 109 | |> 110 | Collage.move (toTuple particle.pos) 111 | 112 | 113 | view : Model -> Html msg 114 | view model = 115 | [ Collage.rect 750 500 116 | |> Collage.filled (Color.hsl (degrees 42) 0.73 0.66) 117 | , model.particles 118 | |> List.map drawParticle 119 | |> Collage.group 120 | ] 121 | |> Collage.collage 750 500 122 | |> Element.toHtml 123 | 124 | 125 | main : Program Never Model Msg 126 | main = 127 | Html.program 128 | { init = 129 | ( initialModel 130 | , Random.generate NewParticles (Random.list particleCount Particle.random) 131 | ) 132 | , subscriptions = 133 | \model -> 134 | if List.length model.particles > 0 then 135 | AnimationFrame.times Tick 136 | else 137 | Sub.none 138 | , update = update 139 | , view = view 140 | } 141 | -------------------------------------------------------------------------------- /Day29/Particle.elm: -------------------------------------------------------------------------------- 1 | module Particle exposing (Particle, inBounds, update, random) 2 | 3 | import Math.Vector2 exposing (..) 4 | import Random 5 | 6 | 7 | type alias Particle = 8 | { pos : Vec2 9 | , kind : Bool 10 | } 11 | 12 | 13 | inBounds : ( Float, Float ) -> ( Float, Float ) -> Particle -> Bool 14 | inBounds ( minx, miny ) ( maxx, maxy ) particle = 15 | let 16 | x = 17 | getX (Debug.log "p" particle.pos) 18 | 19 | y = 20 | getY particle.pos 21 | in 22 | (x >= minx && x <= maxx && y >= miny && y <= maxy) 23 | 24 | 25 | update : List Particle -> Particle -> Particle 26 | update neighbors particle = 27 | let 28 | ( sameNeighbors, oppositeNeighbors ) = 29 | List.partition (\n -> n.kind == particle.kind) neighbors 30 | 31 | oppositeCenter = 32 | List.foldl (\n -> add n.pos) (vec2 0 0) oppositeNeighbors 33 | |> scale (toFloat <| List.length oppositeNeighbors) 34 | 35 | sameCenter = 36 | List.foldl (\n -> add n.pos) (vec2 0 0) sameNeighbors 37 | |> scale (toFloat <| List.length sameNeighbors) 38 | 39 | targetPos = 40 | oppositeCenter 41 | |> add (Math.Vector2.negate sameCenter) 42 | in 43 | if targetPos == particle.pos then 44 | particle 45 | else 46 | { particle 47 | | pos = 48 | particle.pos 49 | |> add (direction targetPos particle.pos) 50 | } 51 | 52 | 53 | 54 | -- let 55 | -- ( x, y ) = 56 | -- toTuple particle.pos 57 | -- 58 | -- dvel = 59 | -- vec2 60 | -- (sin (x / 100 + t)) 61 | -- (cos (x / 100 + t)) 62 | -- |> scale 5 63 | -- in 64 | -- { particle 65 | -- | pos = 66 | -- particle.pos 67 | -- |> add (scale dt particle.vel) 68 | -- , vel = 69 | -- particle.vel 70 | -- |> add dvel 71 | -- } 72 | 73 | 74 | randomVec2 : ( Float, Float ) -> ( Float, Float ) -> Random.Generator Vec2 75 | randomVec2 ( minx, miny ) ( maxx, maxy ) = 76 | Random.map2 vec2 77 | (Random.float minx maxx) 78 | (Random.float miny maxy) 79 | 80 | 81 | random : Random.Generator Particle 82 | random = 83 | Random.map2 Particle 84 | (randomVec2 ( -375, -250 ) ( 275, 250 )) 85 | (Random.bool) 86 | -------------------------------------------------------------------------------- /Day29/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/linear-algebra": "1.0.0 <= v < 2.0.0", 12 | "elm-lang/animation-frame": "1.0.1 <= v < 2.0.0", 13 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 14 | "elm-lang/html": "2.0.0 <= v < 3.0.0", 15 | "evancz/elm-graphics": "1.0.1 <= v < 2.0.0" 16 | }, 17 | "elm-version": "0.18.0 <= v < 0.19.0" 18 | } 19 | -------------------------------------------------------------------------------- /Day29/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day29/screenshot.mp4 -------------------------------------------------------------------------------- /Day30/.gitignore: -------------------------------------------------------------------------------- 1 | /elm-stuff/ 2 | -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Brown Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Brown Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Character Boy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Character Boy.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Character Cat Girl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Character Cat Girl.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Character Horn Girl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Character Horn Girl.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Character Pink Girl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Character Pink Girl.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Character Princess Girl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Character Princess Girl.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Chest Closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Chest Closed.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Chest Lid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Chest Lid.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Chest Open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Chest Open.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Dirt Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Dirt Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Door Tall Closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Door Tall Closed.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Door Tall Open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Door Tall Open.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Enemy Bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Enemy Bug.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Gem Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Gem Blue.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Gem Green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Gem Green.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Gem Orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Gem Orange.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Grass Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Grass Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Heart.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Key.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Plain Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Plain Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/PlanetCuteShadowMockup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/PlanetCuteShadowMockup.jpg -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/PlanetCuteShadowTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/PlanetCuteShadowTest.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Ramp East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Ramp East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Ramp North.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Ramp North.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Ramp South.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Ramp South.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Ramp West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Ramp West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Rock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Rock.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof North East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof North East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof North West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof North West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof North.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof North.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof South East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof South East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof South West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof South West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof South.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof South.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Roof West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Roof West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Selector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Selector.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow North East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow North East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow North West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow North West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow North.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow North.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow Side West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow Side West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow South East.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow South East.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow South West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow South West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow South.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow South.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Shadow West.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Shadow West.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/SpeechBubble.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/SpeechBubble.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Star.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Stone Block Tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Stone Block Tall.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Stone Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Stone Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Thumbs.db -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Tree Short.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Tree Short.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Tree Tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Tree Tall.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Tree Ugly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Tree Ugly.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Wall Block Tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Wall Block Tall.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Wall Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Wall Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Water Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Water Block.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Window Tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Window Tall.png -------------------------------------------------------------------------------- /Day30/PlanetCute PNG/Wood Block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/PlanetCute PNG/Wood Block.png -------------------------------------------------------------------------------- /Day30/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "elm-community/random-extra": "2.0.0 <= v < 3.0.0", 12 | "elm-lang/core": "5.0.0 <= v < 6.0.0", 13 | "elm-lang/html": "2.0.0 <= v < 3.0.0" 14 | }, 15 | "elm-version": "0.18.0 <= v < 0.19.0" 16 | } 17 | -------------------------------------------------------------------------------- /Day30/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day30/screenshot.mp4 -------------------------------------------------------------------------------- /Day6/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Math.Vector3 exposing (..) 4 | import Math.Matrix4 exposing (..) 5 | import WebGL exposing (..) 6 | import Html.App as Html 7 | import AnimationFrame 8 | import Html.Attributes exposing (width, height) 9 | import Day6.Meshes exposing (cube) 10 | import Animation exposing (..) 11 | import Color exposing (Color) 12 | 13 | 14 | type alias Model = 15 | Float 16 | 17 | 18 | type Msg 19 | = Tick Float 20 | 21 | 22 | update : Msg -> Model -> ( Model, Cmd Msg ) 23 | update msg theta = 24 | case msg of 25 | Tick dt -> 26 | ( theta + dt / 1000, Cmd.none ) 27 | 28 | 29 | main : Program Never 30 | main = 31 | Html.program 32 | { init = ( 0, Cmd.none ) 33 | , view = 34 | scene 35 | >> WebGL.toHtml 36 | [ width 750 37 | , height 500 38 | , Html.Attributes.style [ ( "background-color", "black" ) ] 39 | ] 40 | , subscriptions = (\model -> AnimationFrame.diffs Tick) 41 | , update = update 42 | } 43 | 44 | 45 | 46 | -- VIEW 47 | 48 | 49 | cubes = 50 | { red = cube Color.red 51 | , blue = cube Color.blue 52 | , green = cube Color.green 53 | , purple = cube Color.purple 54 | , yellow = cube Color.yellow 55 | } 56 | 57 | 58 | scene : Model -> List Renderable 59 | scene t = 60 | let 61 | angleAnim = 62 | animation 1 |> from 0 |> to (degrees 360) |> duration 1 63 | 64 | angle d = 65 | animate t (angleAnim |> delay d) 66 | in 67 | [ render vertexShader fragmentShader (cubes.red) (uniforms 0 0 (angle 0)) 68 | , render vertexShader fragmentShader (cubes.blue) (uniforms -1 0 (angle 0)) 69 | , render vertexShader fragmentShader (cubes.green) (uniforms 1 0 (angle 0)) 70 | , render vertexShader fragmentShader (cubes.purple) (uniforms 0 1 (angle 0.4)) 71 | , render vertexShader fragmentShader (cubes.yellow) (uniforms 0 -1 (angle -0.4)) 72 | ] 73 | 74 | 75 | type alias Uniforms = 76 | { rotation : Mat4 77 | , transform : Mat4 78 | , perspective : Mat4 79 | , camera : Mat4 80 | , shade : Float 81 | } 82 | 83 | 84 | uniforms : Int -> Int -> Float -> Uniforms 85 | uniforms x y angle = 86 | { transform = 87 | Math.Matrix4.identity 88 | |> translate3 (3 * toFloat x) (3 * toFloat y) 0 89 | , rotation = 90 | (makeRotate angle (vec3 0 1 0)) 91 | , perspective = makePerspective 45 (3 / 2) 0.01 100 92 | , camera = 93 | makeLookAt 94 | (vec3 0 0 15) 95 | (vec3 0 0 0) 96 | (vec3 0 1 0) 97 | , shade = 0.8 98 | } 99 | 100 | 101 | 102 | -- SHADERS 103 | 104 | 105 | vertexShader : Shader { position : Vec3, color : Vec3 } Uniforms { vcolor : Vec3 } 106 | vertexShader = 107 | [glsl| 108 | 109 | attribute vec3 position; 110 | attribute vec3 color; 111 | uniform mat4 perspective; 112 | uniform mat4 camera; 113 | uniform mat4 rotation; 114 | uniform mat4 transform; 115 | varying vec3 vcolor; 116 | void main () { 117 | gl_Position = perspective * camera * rotation * transform * vec4(position, 1.0); 118 | vcolor = color; 119 | } 120 | 121 | |] 122 | 123 | 124 | fragmentShader : Shader {} { u | shade : Float } { vcolor : Vec3 } 125 | fragmentShader = 126 | [glsl| 127 | 128 | precision mediump float; 129 | uniform float shade; 130 | varying vec3 vcolor; 131 | void main () { 132 | gl_FragColor = shade * vec4(vcolor, 1.0); 133 | } 134 | 135 | |] 136 | -------------------------------------------------------------------------------- /Day6/Meshes.elm: -------------------------------------------------------------------------------- 1 | module Day6.Meshes exposing (cube) 2 | 3 | import Color exposing (..) 4 | import Math.Vector3 exposing (..) 5 | import WebGL exposing (..) 6 | 7 | 8 | -- MESHES - create a cube in which each vertex has a position and color 9 | 10 | 11 | type alias Vertex = 12 | { color : Vec3 13 | , position : Vec3 14 | } 15 | 16 | 17 | cube : Color -> Drawable Vertex 18 | cube color = 19 | let 20 | { hue, saturation, lightness, alpha } = 21 | Color.toHsl color 22 | 23 | lighter = 24 | Color.hsla hue saturation (lightness + 0.1) alpha 25 | 26 | darker = 27 | Color.hsla hue saturation (lightness - 0.1) alpha 28 | 29 | rft = 30 | vec3 1 1 1 31 | 32 | -- right, front, top 33 | lft = 34 | vec3 -1 1 1 35 | 36 | -- left, front, top 37 | lbt = 38 | vec3 -1 -1 1 39 | 40 | rbt = 41 | vec3 1 -1 1 42 | 43 | rbb = 44 | vec3 1 -1 -1 45 | 46 | rfb = 47 | vec3 1 1 -1 48 | 49 | lfb = 50 | vec3 -1 1 -1 51 | 52 | lbb = 53 | vec3 -1 -1 -1 54 | in 55 | Triangle 56 | << List.concat 57 | <| 58 | [ face color rft rfb rbb rbt 59 | -- right 60 | , face color rft rfb lfb lft 61 | -- front 62 | , face lighter rft lft lbt rbt 63 | -- top 64 | , face darker rfb lfb lbb rbb 65 | -- bottom 66 | , face lighter lft lfb lbb lbt 67 | -- left 68 | , face darker rbt rbb lbb lbt 69 | -- back 70 | ] 71 | 72 | 73 | face : Color -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> List ( Vertex, Vertex, Vertex ) 74 | face rawColor a b c d = 75 | let 76 | color = 77 | let 78 | c = 79 | toRgb rawColor 80 | in 81 | vec3 82 | (toFloat c.red / 255) 83 | (toFloat c.green / 255) 84 | (toFloat c.blue / 255) 85 | 86 | vertex position = 87 | Vertex color position 88 | in 89 | [ ( vertex a, vertex b, vertex c ) 90 | , ( vertex c, vertex d, vertex a ) 91 | ] 92 | -------------------------------------------------------------------------------- /Day6/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day6/screenshot.gif -------------------------------------------------------------------------------- /Day7/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Color exposing (..) 4 | import Math.Vector3 exposing (..) 5 | import Math.Matrix4 exposing (..) 6 | import Math.Vector3 exposing (..) 7 | import WebGL exposing (..) 8 | import Html.App as Html 9 | import AnimationFrame 10 | import Html.Attributes exposing (width, height) 11 | 12 | 13 | main : Program Never 14 | main = 15 | Html.program 16 | { init = ( 0, Cmd.none ) 17 | , view = 18 | scene 19 | >> WebGL.toHtml 20 | [ width 750 21 | , height 500 22 | , Html.Attributes.style [ ( "background-color", "black" ) ] 23 | ] 24 | , subscriptions = (\model -> AnimationFrame.diffs Basics.identity) 25 | , update = (\dt theta -> ( theta + dt / 1000, Cmd.none )) 26 | } 27 | 28 | 29 | 30 | -- MESHES - create a cube in which each vertex has a position and color 31 | 32 | 33 | type alias VertexAttributes = 34 | { color : Vec3 35 | , position : Vec3 36 | , normal : Vec3 37 | } 38 | 39 | 40 | cube : Drawable VertexAttributes 41 | cube = 42 | let 43 | rft = 44 | vec3 1 1 1 45 | 46 | -- right, front, top 47 | lft = 48 | vec3 -1 1 1 49 | 50 | -- left, front, top 51 | lbt = 52 | vec3 -1 -1 1 53 | 54 | rbt = 55 | vec3 1 -1 1 56 | 57 | rbb = 58 | vec3 1 -1 -1 59 | 60 | rfb = 61 | vec3 1 1 -1 62 | 63 | lfb = 64 | vec3 -1 1 -1 65 | 66 | lbb = 67 | vec3 -1 -1 -1 68 | in 69 | Triangle 70 | << List.concat 71 | <| 72 | [ face purple rft rfb rbb rbt 73 | -- right 74 | , face purple rft rfb lfb lft 75 | -- front 76 | , face purple rft lft lbt rbt 77 | -- top 78 | , face purple rfb lfb lbb rbb 79 | -- bottom 80 | , face purple lft lfb lbb lbt 81 | -- left 82 | , face purple rbt rbb lbb lbt 83 | -- back 84 | ] 85 | 86 | 87 | face : Color -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> List ( VertexAttributes, VertexAttributes, VertexAttributes ) 88 | face rawColor a b c d = 89 | let 90 | color = 91 | let 92 | c = 93 | toRgb rawColor 94 | in 95 | vec3 96 | (toFloat c.red / 255) 97 | (toFloat c.green / 255) 98 | (toFloat c.blue / 255) 99 | 100 | normal = 101 | Math.Vector3.cross a b 102 | 103 | vertex position = 104 | VertexAttributes color position normal 105 | in 106 | [ ( vertex a, vertex b, vertex c ) 107 | , ( vertex c, vertex d, vertex a ) 108 | ] 109 | 110 | 111 | 112 | -- VIEW 113 | 114 | 115 | scene : Float -> List Renderable 116 | scene t = 117 | let 118 | box x y = 119 | render vertexShader fragmentShader cube (uniforms x y (x + y) t) 120 | 121 | row x = 122 | [-5..5] 123 | |> List.map (box x) 124 | in 125 | [-5..5] 126 | |> List.map row 127 | |> List.concat 128 | 129 | 130 | type alias Uniforms = 131 | { rotation : Mat4 132 | , perspective : Mat4 133 | , transform : Mat4 134 | , camera : Mat4 135 | , shade : Float 136 | , lightPos : Vec3 137 | , lightColor : Vec3 138 | , cameraPos : Vec3 139 | } 140 | 141 | 142 | type alias Varyings = 143 | { vcolor : Vec3 144 | , vnormal : Vec3 145 | , vpos : Vec3 146 | } 147 | 148 | 149 | uniforms : Float -> Float -> Float -> Float -> Uniforms 150 | uniforms x y r t = 151 | let 152 | cameraPos = 153 | (vec3 0 -40 20) 154 | in 155 | { rotation = 156 | mul (makeRotate (3 * r) (vec3 0 1 0)) (makeRotate (2 * r) (vec3 1 0 0)) 157 | , perspective = makePerspective 45 (3 / 2) 0.01 100 158 | , camera = makeLookAt cameraPos (vec3 0 0 0) (vec3 0 1 0) 159 | , cameraPos = cameraPos 160 | , shade = 0.8 161 | , transform = 162 | Math.Matrix4.identity 163 | |> translate3 (x * 2.5) (2.5 * y) 0 164 | , lightPos = 165 | vec3 0 -30 5 166 | |> Math.Matrix4.transform (makeRotate t Math.Vector3.k) 167 | , lightColor = vec3 1 1 1 168 | } 169 | 170 | 171 | 172 | -- SHADERS 173 | 174 | 175 | vertexShader : Shader VertexAttributes Uniforms Varyings 176 | vertexShader = 177 | [glsl| 178 | 179 | attribute vec3 position; 180 | attribute vec3 color; 181 | attribute vec3 normal; 182 | uniform mat4 perspective; 183 | uniform mat4 camera; 184 | uniform mat4 rotation; 185 | uniform mat4 transform; 186 | varying vec3 vcolor; 187 | varying vec3 vnormal; 188 | varying vec3 vpos; 189 | void main () { 190 | gl_Position = perspective * camera * rotation * transform * vec4(position, 1.0); 191 | vcolor = color; 192 | vnormal = normal; 193 | vpos = vec3(transform * vec4(position, 1.0)); 194 | } 195 | 196 | |] 197 | 198 | 199 | fragmentShader : Shader {} Uniforms Varyings 200 | fragmentShader = 201 | [glsl| 202 | 203 | precision mediump float; 204 | uniform float shade; 205 | uniform vec3 lightPos; 206 | uniform vec3 lightColor; 207 | uniform vec3 cameraPos; 208 | varying vec3 vcolor; 209 | varying vec3 vnormal; 210 | varying vec3 vpos; 211 | void main () { 212 | // Ambient lighting 213 | vec3 ambient = shade * vcolor; 214 | 215 | // Diffuse lighting 216 | vec3 norm = normalize(vnormal); 217 | vec3 lightDir = normalize(lightPos - vpos); 218 | float diff = max(dot(norm, lightDir), 0.0); 219 | vec3 diffuse = diff * lightColor; 220 | 221 | // Specular lighting 222 | float specularStrength = 0.8; 223 | vec3 cameraDir = normalize(cameraPos - vpos); 224 | vec3 reflectDir = reflect(-lightDir, norm); 225 | float spec = pow(max(dot(cameraDir, reflectDir), 0.0), 128.0); 226 | vec3 specular = specularStrength * spec * lightColor; 227 | 228 | vec3 result = (ambient + diffuse + specular) * vcolor; 229 | gl_FragColor = vec4(result, 1.0); 230 | } 231 | 232 | |] 233 | -------------------------------------------------------------------------------- /Day7/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day7/screenshot.gif -------------------------------------------------------------------------------- /Day8/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day8/screenshot.gif -------------------------------------------------------------------------------- /Day9/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Color exposing (..) 4 | import Math.Vector3 exposing (..) 5 | import Math.Matrix4 exposing (..) 6 | import WebGL exposing (..) 7 | import Html.App as Html 8 | import AnimationFrame 9 | import Html.Attributes exposing (width, height) 10 | 11 | 12 | main : Program Never 13 | main = 14 | Html.program 15 | { init = ( 0, Cmd.none ) 16 | , view = scene >> WebGL.toHtml [ width 400, height 400 ] 17 | , subscriptions = (\model -> AnimationFrame.diffs Basics.identity) 18 | , update = (\dt theta -> ( theta + dt / 1000, Cmd.none )) 19 | } 20 | 21 | 22 | 23 | -- MESHES - create a cube in which each vertex has a position and color 24 | 25 | 26 | type alias Vertex = 27 | { color : Vec3 28 | , position : Vec3 29 | , normal : Vec3 30 | } 31 | 32 | 33 | triangle : Drawable Vertex 34 | triangle = 35 | let 36 | at = 37 | vec3 0 0 1 38 | 39 | bt = 40 | vec3 1 0 1 41 | 42 | ct = 43 | vec3 0 1 1 44 | 45 | ab = 46 | vec3 0 0 0 47 | 48 | bb = 49 | vec3 1 0 0 50 | 51 | cb = 52 | vec3 0 1 0 53 | in 54 | Triangle 55 | << List.concat 56 | <| 57 | [ tri (Color.rgb 255 0 255) at bt ct 58 | , tri Color.purple ab bb cb 59 | , face Color.blue at bt bb ab 60 | , face Color.green bt ct cb bb 61 | , face Color.yellow ct at ab cb 62 | ] 63 | 64 | 65 | tri : Color -> Vec3 -> Vec3 -> Vec3 -> List ( Vertex, Vertex, Vertex ) 66 | tri color a b c = 67 | let 68 | normal = 69 | Math.Vector3.cross a b 70 | in 71 | [ ( Vertex (colorToVec color) a normal 72 | , Vertex (colorToVec color) b normal 73 | , Vertex (colorToVec color) c normal 74 | ) 75 | ] 76 | 77 | 78 | colorToVec : Color -> Vec3 79 | colorToVec rawColor = 80 | let 81 | c = 82 | toRgb rawColor 83 | in 84 | vec3 85 | (toFloat c.red / 255) 86 | (toFloat c.green / 255) 87 | (toFloat c.blue / 255) 88 | 89 | 90 | square : Drawable Vertex 91 | square = 92 | let 93 | rft = 94 | -- right, front, top 95 | vec3 1 1 1 96 | 97 | lft = 98 | -- left, front, top 99 | vec3 0 1 1 100 | 101 | lbt = 102 | vec3 0 0 1 103 | 104 | rbt = 105 | vec3 1 0 1 106 | 107 | rbb = 108 | vec3 1 0 0 109 | 110 | rfb = 111 | vec3 1 1 0 112 | 113 | lfb = 114 | vec3 0 1 0 115 | 116 | lbb = 117 | vec3 0 0 0 118 | in 119 | Triangle 120 | << List.concat 121 | <| 122 | [ face green rft rfb rbb rbt 123 | -- right 124 | , face blue rft rfb lfb lft 125 | -- front 126 | , face yellow rft lft lbt rbt 127 | -- top 128 | , face red rfb lfb lbb rbb 129 | -- bottom 130 | , face purple lft lfb lbb lbt 131 | -- left 132 | , face orange rbt rbb lbb lbt 133 | -- back 134 | ] 135 | 136 | 137 | face : Color -> Vec3 -> Vec3 -> Vec3 -> Vec3 -> List ( Vertex, Vertex, Vertex ) 138 | face rawColor a b c d = 139 | let 140 | color = 141 | let 142 | c = 143 | toRgb rawColor 144 | in 145 | vec3 146 | (toFloat c.red / 255) 147 | (toFloat c.green / 255) 148 | (toFloat c.blue / 255) 149 | 150 | normal = 151 | Math.Vector3.cross a b 152 | 153 | vertex position = 154 | Vertex color position normal 155 | in 156 | [ ( vertex a, vertex b, vertex c ) 157 | , ( vertex c, vertex d, vertex a ) 158 | ] 159 | 160 | 161 | 162 | -- VIEW 163 | 164 | 165 | scene : Float -> List Renderable 166 | scene t = 167 | [ render vertexShader fragmentShader square (uniforms (Color.rgb 0x83 0xC8 0x33) 0 0 1 -45 t) 168 | , render vertexShader fragmentShader triangle (uniforms (Color.rgb 0xEF 0xA5 0x00) 0 0 1 45 t) 169 | , render vertexShader fragmentShader triangle (uniforms (Color.rgb 0x5A 0x63 0x78) 0 0 2 135 t) 170 | , render vertexShader fragmentShader triangle (uniforms (Color.rgb 0x5F 0xB4 0xCA) 0 0 2 225 t) 171 | , render vertexShader fragmentShader triangle (uniforms (Color.rgb 0xEF 0xA5 0x00) (sqrt 0.5) (-1 * sqrt 0.5) 1 -45 t) 172 | , render vertexShader fragmentShader triangle (uniforms (Color.rgb 0x5F 0xB4 0xCA) (2 * sqrt 0.5) (2 * sqrt 0.5) (sqrt 2) 180 t) 173 | ] 174 | 175 | 176 | type alias Uniforms = 177 | { rotation : Mat4 178 | , transform : Mat4 179 | , perspective : Mat4 180 | , camera : Mat4 181 | , shade : Float 182 | , shapeColor : Vec3 183 | , cameraPos : Vec3 184 | , lightColor : Vec3 185 | , lightPos : Vec3 186 | } 187 | 188 | 189 | uniforms : Color -> Float -> Float -> Float -> Float -> Float -> Uniforms 190 | uniforms color x y scale angle t = 191 | let 192 | cameraPos = 193 | (vec3 2 3 5) 194 | in 195 | { rotation = 196 | mul 197 | (makeRotate (1 * t) (vec3 0 1 0)) 198 | (makeRotate (degrees <| 20 * sin (t / 5)) (vec3 1 0 0)) 199 | , transform = 200 | Math.Matrix4.identity 201 | |> Math.Matrix4.translate (vec3 0 0 -0.5) 202 | |> Math.Matrix4.scale (vec3 1 1 0.3) 203 | |> Math.Matrix4.translate (vec3 x y 0) 204 | |> Math.Matrix4.scale (vec3 scale scale 1) 205 | |> Math.Matrix4.rotate (degrees angle) Math.Vector3.k 206 | , perspective = makePerspective 45 1 0.01 100 207 | , camera = makeLookAt cameraPos (vec3 0 0 0) (vec3 0 1 0) 208 | , shade = 0.8 209 | , shapeColor = colorToVec color 210 | , cameraPos = cameraPos 211 | , lightColor = vec3 0.8 0.8 0.8 212 | , lightPos = vec3 -2 2 4 213 | } 214 | 215 | 216 | 217 | -- SHADERS 218 | 219 | 220 | type alias Varyings = 221 | { vcolor : Vec3 222 | , vnormal : Vec3 223 | , vpos : Vec3 224 | } 225 | 226 | 227 | vertexShader : Shader { attr | position : Vec3, color : Vec3, normal : Vec3 } Uniforms Varyings 228 | vertexShader = 229 | [glsl| 230 | 231 | attribute vec3 position; 232 | attribute vec3 normal; 233 | uniform mat4 perspective; 234 | uniform mat4 camera; 235 | uniform mat4 rotation; 236 | uniform mat4 transform; 237 | uniform vec3 shapeColor; 238 | varying vec3 vcolor; 239 | varying vec3 vnormal; 240 | varying vec3 vpos; 241 | void main () { 242 | gl_Position = perspective * camera * rotation * transform * vec4(position, 1.0); 243 | vcolor = shapeColor; 244 | vnormal = normal; 245 | vpos = vec3(transform * vec4(position, 1.0)); 246 | } 247 | 248 | |] 249 | 250 | 251 | fragmentShader : Shader {} Uniforms Varyings 252 | fragmentShader = 253 | [glsl| 254 | 255 | precision mediump float; 256 | uniform float shade; 257 | uniform vec3 lightPos; 258 | uniform vec3 lightColor; 259 | uniform vec3 cameraPos; 260 | varying vec3 vcolor; 261 | varying vec3 vnormal; 262 | varying vec3 vpos; 263 | void main () { 264 | // Ambient lighting 265 | vec3 ambient = shade * vcolor; 266 | 267 | // Diffuse lighting 268 | vec3 norm = normalize(vnormal); 269 | vec3 lightDir = normalize(lightPos - vpos); 270 | float diff = max(dot(vnormal, lightDir), 0.0); 271 | vec3 diffuse = diff * lightColor; 272 | 273 | // Specular lighting 274 | float specularStrength = 0.8; 275 | vec3 cameraDir = normalize(cameraPos - vpos); 276 | vec3 reflectDir = reflect(-lightDir, norm); 277 | float spec = pow(max(dot(cameraDir, reflectDir), 0.0), 128.0); 278 | vec3 specular = specularStrength * spec * lightColor; 279 | 280 | vec3 result = (ambient + diffuse + specular) * vcolor; 281 | gl_FragColor = vec4(result, 1.0); 282 | } 283 | 284 | |] 285 | -------------------------------------------------------------------------------- /Day9/screenshot.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/Day9/screenshot.mp4 -------------------------------------------------------------------------------- /day-1/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Graphics.Render exposing (..) 4 | import Color exposing (rgb) 5 | import Random 6 | import Random.Extra 7 | import Html 8 | import Html.Attributes 9 | import Html.App 10 | 11 | 12 | canvasSize = 13 | { width = 750, height = 500 } 14 | 15 | 16 | type Move 17 | = Straight 18 | | TurnLeft 19 | | TurnRight 20 | 21 | 22 | randomMove : Random.Generator Move 23 | randomMove = 24 | Random.Extra.frequency 25 | [ ( 2, Random.Extra.constant Straight ) 26 | , ( 1, Random.Extra.constant TurnLeft ) 27 | , ( 1, Random.Extra.constant TurnRight ) 28 | ] 29 | 30 | 31 | type Direction 32 | = North 33 | | South 34 | | East 35 | | West 36 | 37 | 38 | createPath : List Move -> List Point 39 | createPath moves = 40 | let 41 | distance = 42 | 24 43 | 44 | init = 45 | ( ( 0, 0 ), North, [] ) 46 | 47 | step move ( ( x, y ), dir, result ) = 48 | let 49 | newDir = 50 | case ( dir, move ) of 51 | ( _, Straight ) -> 52 | dir 53 | 54 | ( North, TurnLeft ) -> 55 | West 56 | 57 | ( North, TurnRight ) -> 58 | East 59 | 60 | ( West, TurnLeft ) -> 61 | South 62 | 63 | ( West, TurnRight ) -> 64 | North 65 | 66 | ( East, TurnLeft ) -> 67 | North 68 | 69 | ( East, TurnRight ) -> 70 | South 71 | 72 | ( South, TurnLeft ) -> 73 | East 74 | 75 | ( South, TurnRight ) -> 76 | West 77 | 78 | newPos = 79 | case newDir of 80 | North -> 81 | ( x, y - distance ) 82 | 83 | South -> 84 | ( x, y + distance ) 85 | 86 | East -> 87 | ( x + distance, y ) 88 | 89 | West -> 90 | ( x - distance, y ) 91 | in 92 | ( newPos, newDir, newPos :: result ) 93 | in 94 | List.foldl step init moves 95 | |> (\( _, _, result ) -> result) 96 | 97 | 98 | view seedBase = 99 | case seedBase of 100 | Nothing -> 101 | rectangle canvasSize.width canvasSize.height 102 | |> solidFill (rgb 15 15 15) 103 | |> svg canvasSize.width canvasSize.height 104 | 105 | Just seed -> 106 | let 107 | drawLine l = 108 | line l 109 | { color = (rgb 220 200 220) 110 | , width = 3 111 | , cap = Square 112 | , join = Sharp 113 | , dashing = [ 80, 40 ] 114 | , dashOffset = 0 115 | } 116 | in 117 | group 118 | [ rectangle canvasSize.width canvasSize.height 119 | |> solidFill (rgb 15 15 15) 120 | , [0..20] 121 | |> List.map (\x -> Random.initialSeed (x + seed)) 122 | |> List.map (Random.step (Random.list 25 randomMove) >> fst) 123 | |> List.map (createPath >> polyline >> drawLine) 124 | |> group 125 | ] 126 | |> svg canvasSize.width canvasSize.height 127 | 128 | 129 | type alias Model = 130 | Maybe Int 131 | 132 | 133 | type alias Msg = 134 | Int 135 | 136 | 137 | update msg model = 138 | Just msg 139 | 140 | 141 | main : Program Never 142 | main = 143 | Html.App.program 144 | { init = ( Nothing, Random.generate identity (Random.int -1000000 10000000) ) 145 | , subscriptions = \_ -> Sub.none 146 | , update = \msg model -> ( update msg model, Cmd.none ) 147 | , view = view 148 | } 149 | -------------------------------------------------------------------------------- /day-1/elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "Kwarrtz/render": "1.0.1 <= v < 2.0.0", 12 | "elm-community/random-extra": "1.0.0 <= v < 2.0.0", 13 | "elm-lang/core": "4.0.5 <= v < 5.0.0", 14 | "elm-lang/html": "1.1.0 <= v < 2.0.0" 15 | }, 16 | "elm-version": "0.17.1 <= v < 0.18.0" 17 | } 18 | -------------------------------------------------------------------------------- /day-1/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/day-1/screenshot.png -------------------------------------------------------------------------------- /day-2/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Graphics.Render exposing (..) 4 | import Color exposing (Color) 5 | import Html exposing (Html) 6 | import Html.App 7 | import Time 8 | 9 | 10 | background : Color 11 | background = 12 | Color.rgb 30 40 200 13 | 14 | 15 | foreground : Color 16 | foreground = 17 | Color.rgb 30 200 90 18 | 19 | 20 | transparent : Color 21 | transparent = 22 | Color.rgba 0 0 0 0 23 | 24 | 25 | singleCircle : Float -> Form msg 26 | singleCircle size = 27 | ellipse size size 28 | |> solidFillWithBorder transparent 4 foreground 29 | 30 | 31 | setOfCircles : Int -> Form msg 32 | setOfCircles offset = 33 | [0..25] 34 | |> List.map (\i -> i * 30 + (toFloat (offset % 30))) 35 | |> List.map singleCircle 36 | |> group 37 | 38 | 39 | type alias Model = 40 | { offset : Int } 41 | 42 | 43 | type alias Msg = 44 | () 45 | 46 | 47 | update : Msg -> Model -> ( Model, Cmd msg ) 48 | update () model = 49 | ( { model | offset = model.offset + 1 }, Cmd.none ) 50 | 51 | 52 | view : Model -> Html msg 53 | view model = 54 | group 55 | [ rectangle 750 500 |> solidFill background 56 | , setOfCircles model.offset 57 | , setOfCircles model.offset |> move 70 70 58 | , setOfCircles model.offset |> move -70 70 59 | , setOfCircles model.offset |> move 70 -70 60 | , setOfCircles model.offset |> move -70 -70 61 | , setOfCircles model.offset |> move 240 150 62 | , setOfCircles model.offset |> move -240 150 63 | , setOfCircles model.offset |> move 240 -150 64 | , setOfCircles model.offset |> move -240 -150 65 | ] 66 | |> svg 750 500 67 | 68 | 69 | main = 70 | Html.App.program 71 | { init = ( { offset = 0 }, Cmd.none ) 72 | , subscriptions = \_ -> Time.every 100 (always ()) 73 | , update = update 74 | , view = view 75 | } 76 | -------------------------------------------------------------------------------- /day-2/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/day-2/screenshot.gif -------------------------------------------------------------------------------- /day-3/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Graphics.Render exposing (..) 4 | import Color exposing (Color) 5 | import Html.App 6 | import Html exposing (Html) 7 | import Random 8 | 9 | 10 | border = 11 | solidFillWithBorder (Color.rgba 0 0 0 0) 12 | 13 | 14 | tile : Color -> Form msg 15 | tile color = 16 | let 17 | arc r = 18 | group 19 | [ ellipse r r 20 | |> border 10 color 21 | , rectangle (r * 2) 100 22 | |> solidFill (Color.rgb 200 200 200) 23 | |> move 0 50 24 | , segment ( -r, -0.8 ) ( -r, 50 ) 25 | |> solid 10 color 26 | , segment ( r, -0.8 ) ( r, 50 ) 27 | |> solid 10 color 28 | ] 29 | in 30 | group 31 | [ ellipse 100 100 32 | |> solidFill (Color.rgb 200 200 200) 33 | , rectangle 200 100 34 | |> solidFill (Color.rgb 200 200 200) 35 | |> move 0 50 36 | , arc 85 37 | , arc 65 38 | , arc 45 39 | ] 40 | 41 | 42 | row : Color -> Color -> Float -> Form msg 43 | row color1 color2 tileWidth = 44 | let 45 | colorFor i = 46 | if i % 3 == 0 then 47 | color2 48 | else 49 | color1 50 | 51 | makeTile i = 52 | tile (colorFor i) |> move (toFloat i * tileWidth) 0 53 | in 54 | [0..6] 55 | |> List.map makeTile 56 | |> group 57 | 58 | 59 | view : Model -> Html msg 60 | view model = 61 | let 62 | tileWidth = 63 | 190 64 | in 65 | group 66 | [ rectangle 750 500 67 | |> solidFill (Color.rgb 240 240 240) 68 | , [0..7] 69 | |> List.map 70 | (\i -> 71 | row model.color1 model.color2 tileWidth 72 | |> move 73 | (if i % 2 == 0 then 74 | tileWidth / 2 + tileWidth 75 | else 76 | 0 77 | ) 78 | (100 * toFloat i) 79 | ) 80 | |> group 81 | |> move -600 -300 82 | |> move (model.shiftX * -tileWidth) (model.shiftY * -200) 83 | ] 84 | |> svg 750 500 85 | 86 | 87 | type alias Model = 88 | { color1 : Color 89 | , color2 : Color 90 | , shiftX : Float 91 | , shiftY : Float 92 | } 93 | 94 | 95 | type Msg 96 | = NewModel Model 97 | 98 | 99 | update : Msg -> Model -> ( Model, Cmd Msg ) 100 | update msg model = 101 | case msg of 102 | NewModel newModel -> 103 | ( newModel, Cmd.none ) 104 | 105 | 106 | colorGenerator : Random.Generator Model 107 | colorGenerator = 108 | let 109 | color1 = 110 | Random.map3 Color.rgb 111 | (Random.int 0 100) 112 | (Random.int 0 100) 113 | (Random.int 0 100) 114 | 115 | color2 = 116 | Random.map3 Color.rgb 117 | (Random.int 80 180) 118 | (Random.int 80 180) 119 | (Random.int 80 180) 120 | in 121 | Random.map4 Model 122 | color1 123 | color2 124 | (Random.float 0 1) 125 | (Random.float 0 1) 126 | 127 | 128 | main : Program Never 129 | main = 130 | Html.App.program 131 | { init = 132 | ( { color1 = Color.rgb 70 30 70 133 | , color2 = Color.rgb 10 30 70 134 | , shiftX = 0 135 | , shiftY = 0 136 | } 137 | , Random.generate NewModel colorGenerator 138 | ) 139 | , subscriptions = \_ -> Sub.none 140 | , update = update 141 | , view = view 142 | } 143 | -------------------------------------------------------------------------------- /day-3/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/day-3/screenshot.gif -------------------------------------------------------------------------------- /day-4/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Graphics.Render exposing (..) 4 | import Color exposing (Color) 5 | import Html exposing (Html) 6 | import Html.App 7 | import Random 8 | import Random.Extra 9 | import Http 10 | import Task 11 | import Json.Decode 12 | import Color.Convert 13 | 14 | 15 | triangle : Float -> Color -> Form msg 16 | triangle size color = 17 | polygon [ ( 0, 0 ), ( abs size, 0 ), ( abs size / 2, size * sqrt 3 / 2 ) ] 18 | |> solidFill color 19 | 20 | 21 | triangleRow : List Color -> List Triangle -> Form msg 22 | triangleRow pallete triangles = 23 | let 24 | chooseColor i = 25 | if List.length pallete == 0 then 26 | Color.rgb 245 245 230 27 | else 28 | pallete 29 | |> List.drop (i % List.length pallete) 30 | |> List.head 31 | |> Maybe.withDefault Color.black 32 | 33 | step i { size, color } = 34 | triangle (toFloat size * 50) (chooseColor color) 35 | |> move (50 * toFloat i) 0 36 | in 37 | triangles 38 | |> List.indexedMap step 39 | |> group 40 | 41 | 42 | type alias Model = 43 | { pallete : List Color 44 | , triangleData : List (List Triangle) 45 | } 46 | 47 | 48 | view : Model -> Html msg 49 | view model = 50 | group 51 | [ rectangle 750 500 |> solidFill (Color.rgb 255 255 240) 52 | , model.triangleData 53 | |> List.indexedMap (\i sizes -> triangleRow model.pallete sizes |> move 0 (toFloat i * 60)) 54 | |> group 55 | |> move -180 -120 56 | ] 57 | |> svg 750 500 58 | 59 | 60 | modelGenerator : Random.Generator (List (List Triangle)) 61 | modelGenerator = 62 | let 63 | randomSize = 64 | Random.int -2 2 65 | 66 | randomRow = 67 | Random.list 6 (Random.map2 Triangle randomSize (Random.int 0 50)) 68 | in 69 | Random.list 4 randomRow 70 | 71 | 72 | type alias Triangle = 73 | { size : Int, color : Int } 74 | 75 | 76 | type Msg 77 | = NewTriangleData (List (List Triangle)) 78 | | NewPallete (List Color) 79 | | NewCacheBuster Int 80 | 81 | 82 | update : Msg -> Model -> ( Model, Cmd Msg ) 83 | update msg model = 84 | case msg of 85 | NewCacheBuster token -> 86 | ( model 87 | , Http.get palleteDecoder 88 | ("https://crossorigin.me/https://www.colourlovers.com/api/palettes/random?format=json&sequence=" 89 | ++ toString token 90 | ) 91 | |> Task.perform (always <| NewPallete []) NewPallete 92 | ) 93 | 94 | NewPallete colors -> 95 | ( { model | pallete = colors }, Cmd.none ) 96 | 97 | NewTriangleData newData -> 98 | ( { model | triangleData = newData }, Cmd.none ) 99 | 100 | 101 | palleteDecoder : Json.Decode.Decoder (List Color) 102 | palleteDecoder = 103 | Json.Decode.tuple1 identity 104 | (Json.Decode.at [ "colors" ] 105 | (Json.Decode.map (List.filterMap identity) <| 106 | Json.Decode.list (Json.Decode.map Color.Convert.hexToColor Json.Decode.string) 107 | ) 108 | ) 109 | 110 | 111 | main : Program Never 112 | main = 113 | Html.App.program 114 | { init = 115 | ( { pallete = [] 116 | , triangleData = [] 117 | } 118 | , Cmd.batch 119 | [ Random.generate NewTriangleData modelGenerator 120 | , Random.generate NewCacheBuster (Random.int 0 100000000000) 121 | ] 122 | ) 123 | , subscriptions = \_ -> Sub.none 124 | , update = update 125 | , view = view 126 | } 127 | -------------------------------------------------------------------------------- /day-4/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/day-4/screenshot.gif -------------------------------------------------------------------------------- /day-5/Main.elm: -------------------------------------------------------------------------------- 1 | module Main exposing (..) 2 | 3 | import Graphics.Render exposing (..) 4 | import Color exposing (Color) 5 | import Animation exposing (..) 6 | import Html.App 7 | import Time exposing (Time) 8 | import Ease 9 | 10 | 11 | type alias Model = 12 | { startTime : Maybe Time 13 | , time : Time 14 | } 15 | 16 | 17 | type Msg 18 | = Tick Time 19 | 20 | 21 | update msg model = 22 | case msg of 23 | Tick newTime -> 24 | case model.startTime of 25 | Nothing -> 26 | ( { model 27 | | startTime = Just newTime 28 | , time = 0 29 | } 30 | , Cmd.none 31 | ) 32 | 33 | Just startTime -> 34 | ( { model | time = newTime - startTime } 35 | , Cmd.none 36 | ) 37 | 38 | 39 | view model = 40 | let 41 | lineYAnim = 42 | animation 500 43 | |> from -500 44 | |> to 0 45 | |> duration 700 46 | |> ease Ease.inOutQuint 47 | 48 | lineXAnim = 49 | animation 500 50 | |> from 50 51 | |> to 0 52 | |> duration 700 53 | |> ease Ease.inOutQuint 54 | 55 | diagLine del x = 56 | segment ( 0 + x, -250 ) ( x - 50, 250 ) 57 | |> solid 11 (Color.rgb 255 250 250) 58 | |> move 59 | (animate model.time (lineXAnim |> delay (50 * del))) 60 | (animate model.time (lineYAnim |> delay (50 * del))) 61 | 62 | circleSizeAnim = 63 | animation 1500 64 | |> from 0 65 | |> to 1 66 | |> duration 400 67 | |> ease Ease.outElastic 68 | 69 | circle del scale x y = 70 | let 71 | size = 72 | scale * 30 * (animate model.time (circleSizeAnim |> delay (del * 50))) 73 | in 74 | ellipse size size 75 | |> solidFill (Color.rgb 213 251 217) 76 | |> move x y 77 | in 78 | group 79 | [ rectangle 750 500 80 | |> solidFill (Color.rgb 251 53 35) 81 | , group 82 | [ diagLine 0 0 83 | , diagLine 1 -30 84 | , diagLine 2 -60 85 | , diagLine 3 -90 86 | , diagLine 4 -150 87 | ] 88 | |> move -50 0 89 | , circle 0 1.0 20 -50 90 | , circle 1 0.6 120 -140 91 | , circle 2 0.3 250 100 92 | , circle 3 1.7 180 120 93 | ] 94 | |> svg 750 500 95 | 96 | 97 | main = 98 | Html.App.program 99 | { init = ( { startTime = Nothing, time = 0 }, Cmd.none ) 100 | , subscriptions = \_ -> Time.every 20 Tick 101 | , update = update 102 | , view = view 103 | } 104 | -------------------------------------------------------------------------------- /day-5/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avh4/codevember-2016/7207e046a98a4e4a5b22a5f3288550b18c10a61f/day-5/screenshot.gif -------------------------------------------------------------------------------- /elm-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "summary": "helpful summary of your project, less than 80 characters", 4 | "repository": "https://github.com/user/project.git", 5 | "license": "BSD3", 6 | "source-directories": [ 7 | "." 8 | ], 9 | "exposed-modules": [], 10 | "dependencies": { 11 | "Kwarrtz/render": "1.0.1 <= v < 2.0.0", 12 | "avh4/elm-fifo": "1.0.2 <= v < 2.0.0", 13 | "elm-community/easing-functions": "1.0.1 <= v < 2.0.0", 14 | "elm-community/elm-linear-algebra": "2.0.3 <= v < 3.0.0", 15 | "elm-community/elm-webgl": "3.0.3 <= v < 4.0.0", 16 | "elm-community/random-extra": "1.0.0 <= v < 2.0.0", 17 | "elm-lang/animation-frame": "1.0.0 <= v < 2.0.0", 18 | "elm-lang/core": "4.0.5 <= v < 5.0.0", 19 | "elm-lang/html": "1.1.0 <= v < 2.0.0", 20 | "elm-lang/window": "1.0.0 <= v < 2.0.0", 21 | "eskimoblood/elm-color-extra": "3.2.1 <= v < 4.0.0", 22 | "evancz/elm-graphics": "1.0.0 <= v < 2.0.0", 23 | "evancz/elm-http": "3.0.1 <= v < 4.0.0", 24 | "mdgriffith/elm-color-mixing": "1.0.3 <= v < 2.0.0", 25 | "mgold/elm-animation": "1.0.4 <= v < 2.0.0" 26 | }, 27 | "elm-version": "0.17.1 <= v < 0.18.0" 28 | } 29 | --------------------------------------------------------------------------------