Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sketchy transformation #44

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b327d5e
Initial sketchy renderer.
chipjacks May 14, 2021
6b492cd
Add catmull rom curves.
chipjacks May 14, 2021
a5d7f38
Draw two sketchy lines for each regular line.
chipjacks May 14, 2021
2083ecc
Add sketched lines around shapes.
chipjacks May 15, 2021
0fa6fd1
Get bowed lines working again.
chipjacks May 15, 2021
97817fa
Simplify roughness computation.
chipjacks May 15, 2021
e5fa9cc
Add sketchy circles.
chipjacks May 16, 2021
9e198df
Use svg paths and bezier curves instead of splines.
chipjacks May 19, 2021
7edc666
Remove one-true-path dependency.
chipjacks May 19, 2021
667bc66
Use sketchy for composition example.
chipjacks May 19, 2021
b916a1e
Get sketchy ellipse working.
chipjacks May 19, 2021
ac1be36
Add sketchy house example.
chipjacks May 19, 2021
36391f6
Fix composition example interactivity.
chipjacks May 19, 2021
7f87779
Cleaner circle and ellipse sketching.
chipjacks May 20, 2021
e32bffd
Use curve instead of polyline for rectangles.
chipjacks May 20, 2021
ae828f7
Use virgil font for flowchart.
chipjacks May 20, 2021
e4876fc
Use Caveat for font.
chipjacks May 20, 2021
21e6d41
Pass in config.
chipjacks May 20, 2021
b1bdb9c
Reorganize logic.
chipjacks May 20, 2021
bf97047
Elm format sketchy module.
chipjacks May 20, 2021
8bbe98d
Add curve API and example.
chipjacks May 20, 2021
17f9d02
Add normal vs sketchy render buttons to composition example.
chipjacks May 20, 2021
33a1544
Add wrapper for rendering examples with both backends.
chipjacks May 20, 2021
0396a50
Use example wrapper for other sketchy examples.
chipjacks May 20, 2021
7ea0bc0
Use example wrapper for all examples.
chipjacks May 20, 2021
63aad95
Make Example extensible with non-svg renderers.
chipjacks May 21, 2021
87aff64
Don't use Example wrapper when not needed.
chipjacks May 21, 2021
fa3419a
Update docs.
chipjacks May 21, 2021
c4f4c68
Transform curves into two sketchy lines.
chipjacks May 21, 2021
f41c26a
Hardcode list of random numbers for deterministic results without nee…
chipjacks May 25, 2021
8bf7fe3
Remove unneeded random dependency.
chipjacks May 25, 2021
fcc21c3
Fix documentation for random number generation.
chipjacks May 31, 2021
ffd7798
Refactor to use segments helper.
chipjacks Jun 2, 2021
2b31734
Use hachures to fill sketchy polygons (WIP).
chipjacks Jun 3, 2021
cf78e3b
Refactor to use helpers and exposed API functions when possible.
chipjacks Jun 3, 2021
c5aede8
Fix bug drawing hachures.
chipjacks Jun 3, 2021
9379894
Make hachures sketchy instead of uniform.
chipjacks Jun 3, 2021
b35709b
Hachure thickness matches shape outline.
chipjacks Jun 3, 2021
94bf652
Draw hachure lines at a 45 degree angle.
chipjacks Jun 3, 2021
20e6a6c
Smoother hachure fills for circles and ellipses.
chipjacks Jun 4, 2021
432b18c
Smoother hachures for small ellipses.
chipjacks Jun 4, 2021
b555393
Don't seperate segments when sketching curves.
chipjacks Jun 4, 2021
aae86cf
Hachures work with more complex polygons.
chipjacks Jun 4, 2021
7e98d86
Scale up house so it works with sketchy hachures.
chipjacks Jun 4, 2021
36918f2
Run elm-format.
chipjacks Jun 4, 2021
caa5117
Don't draw lines through text/shapes in flowchart example.
chipjacks Jun 7, 2021
c69bace
Use more descriptive svg module names.
chipjacks Jul 12, 2021
f9bfa19
Factor out pipelines from decodeCurve.
chipjacks Jul 12, 2021
b65720c
Simplify neighbors function.
chipjacks Jul 12, 2021
2a5942f
Use exposed fromFloat and fromInt functions to match rest of module.
chipjacks Jul 12, 2021
32c4dd5
Remove Sketchy.Helpers, add Helpers.List.
chipjacks Jul 12, 2021
97627cb
Minor code review fixes.
chipjacks Jul 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"Collage.Render",
"Collage.Events",
"Collage.Layout",
"Collage.Text"
"Collage.Text",
"Collage.Sketchy"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
Expand Down
13 changes: 10 additions & 3 deletions examples/Axis.elm
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
module Axis exposing (main)

import Example
import Collage exposing (..)
import Collage.Render exposing (..)
import Collage.Text exposing (Text, fromString)
import Color exposing (..)
import Html exposing (Html)


main : Html msg
main : Platform.Program () (Example.Model () (Collage ())) (Example.Msg ())
main =
Example.example
{ init = collage
, update = (\_ _ -> collage)
, render = (\_ -> collage)
, view = identity
}

collage =
let
up =
triangle 10
Expand Down Expand Up @@ -43,4 +51,3 @@ main =
, box
, ellipse 20 40 |> filled (uniform red) |> shift ( 50, 50 )
]
|> svg
38 changes: 17 additions & 21 deletions examples/Composition.elm
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
module Composition exposing (main)

import Browser
import Collage exposing (..)
import Collage.Events exposing (onClick)
import Collage.Layout exposing (..)
import Collage.Render exposing (svg)
import Collage.Text exposing (fromString)
import Color exposing (..)
import Html exposing (Html)

import Example


-- Model -----------------------------------------------------------------------
Expand All @@ -18,22 +15,19 @@ type alias Model =
{ active : Bool }


init : Model
init = { active = False }



-- Update ----------------------------------------------------------------------


type Msg
= Switch
= Switch


update : Msg -> Model -> Model
update msg model =
case msg of
Switch -> { model | active = not model.active }
Switch ->
{ model | active = not model.active }



Expand All @@ -59,12 +53,12 @@ txt =
-- Shapes --


elps : Model -> Collage Msg
elps model =
elps : Bool -> Collage Msg
elps active =
ellipse 100 50
|> styled
( uniform <|
if model.active then
if active then
lightPurple
else
lightBlue
Expand Down Expand Up @@ -105,9 +99,7 @@ alignments =

-- Main ------------------------------------------------------------------------


view : Model -> Html Msg
view model =
render model =
vertical
[ horizontal
[ rect
Expand All @@ -118,11 +110,15 @@ view model =
|> center
, debug penta
]
, stack [ showEnvelope txt, elps model ]
, stack [ showEnvelope txt, elps model.active ]
]
|> debug
|> svg


main : Program () Model Msg
main = Browser.sandbox { init = init, view = view, update = update }
main : Platform.Program () (Example.Model Msg Model) (Example.Msg Msg)
main =
Example.example
{ init = Model False
, update = update
, render = render
, view = identity
}
17 changes: 13 additions & 4 deletions examples/Dimensions.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Dimensions exposing (diamond, main)

import Example
import Collage exposing (..)
import Collage.Layout exposing (..)
import Collage.Render exposing (..)
import Collage.Text as Text exposing (Shape(..), Text, fromString)
import Color exposing (Color)
import Html exposing (Html)
Expand Down Expand Up @@ -42,11 +42,20 @@ diamond label =
]


main : Html msg
main =
collage =
vertical
[ diamond "a very long piece of text"
, gap
, diamond "short text"
]
|> svg


main : Platform.Program () (Example.Model () (Collage ())) (Example.Msg ())
main =
Example.example
{ init = collage
, update = (\_ _ -> collage)
, render = (\_ -> collage)
, view = identity
}

2 changes: 1 addition & 1 deletion examples/Embedding.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main =
[ Html.button []
[ text "Hello Html!" ]
]
|> html ( 100, 100 )
|> html ( 100, 100 ) []
, rectangle 100 100
|> filled (uniform Color.lightGreen)
]
Expand Down
103 changes: 103 additions & 0 deletions examples/Example.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module Example exposing (Model, Msg, example)
timjs marked this conversation as resolved.
Show resolved Hide resolved

import Browser
import Collage exposing (..)
import Collage.Render exposing (svg)
import Collage.Sketchy as Sketchy exposing (sketchy)
import Html exposing (Html)
import Html.Attributes
import Html.Events


type alias Config msg model =
{ init : model
, update : msg -> model -> model
, render : model -> Collage msg
, view : Html msg -> Html msg
}


type Msg childMsg
= ClickedNormal
| ClickedSketchy
| ChildMsg childMsg


type Renderer
= Normal
| Sketchy


type alias Model childMsg childModel =
{ collage : Collage childMsg
, renderer : Renderer
, model : childModel
, sketchyConfig : Sketchy.Config
}


init : (childModel -> Collage childMsg) -> childModel -> ( Model childMsg childModel, Cmd (Msg childMsg) )
init render child =
let
model =
Model (render child) Normal child Sketchy.defaultConfig
in
( model, Cmd.none )


update : Config childMsg childModel -> Msg childMsg -> Model childMsg childModel -> ( Model childMsg childModel, Cmd (Msg childMsg) )
update config msg model =
let
render m =
case m.renderer of
Sketchy ->
( { m | collage = sketchy m.sketchyConfig (config.render m.model) }
, Cmd.none
)

Normal ->
( { m | collage = config.render m.model }
, Cmd.none
)
in
case msg of
ClickedNormal ->
{ model | renderer = Normal }
|> render

ClickedSketchy ->
{ model | renderer = Sketchy, sketchyConfig = Sketchy.nextSeed model.sketchyConfig }
|> render

ChildMsg cMsg ->
{ model | model = config.update cMsg model.model }
|> render


example : Config childMsg childModel -> Platform.Program flags (Model childMsg childModel) (Msg childMsg)
example config =
Browser.element
{ init = \_ -> init config.render config.init
, update = update config
, subscriptions = \_ -> Sub.none
, view = view config.view
}


button : String -> Msg childMsg -> Html (Msg childMsg)
button name msg =
Html.button [ Html.Events.onClick msg ] [ Html.text name ]


view : (Html childMsg -> Html childMsg) -> Model childMsg childModel -> Html (Msg childMsg)
view childView model =
Html.div []
[ Html.div [ Html.Attributes.style "margin-bottom" "10px" ]
[ button "Normal" ClickedNormal
, button "Sketchy" ClickedSketchy
]
, model.collage
|> svg
|> childView
|> Html.map ChildMsg
]
Loading