Skip to content

Instantly share code, notes, and snippets.

@evancz
Created October 25, 2013 15:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evancz/7156716 to your computer and use it in GitHub Desktop.
Save evancz/7156716 to your computer and use it in GitHub Desktop.
Examples of markdown interpolation in Elm's markdown branch: https://github.com/evancz/Elm/tree/markdown
import Graphics.Input as Input
import String
main = lift2 scene textBox name
(textBox, name) = Input.field "What is your name?"
scene textBox name = [markdown|
{{ textBox }}
Hello {{ toText name }}! Check out this circle that grows as you type more letters:
{{ blueCircle (String.length name) }}
|]
blueCircle radius =
collage 200 200 [ filled blue (circle (toFloat (10 + radius * 5))) ]
main = lift2 presentation sunAndEarth bouncingBall
presentation orbit bounce = [markdown|
# Physics: How does it work?
Today we are going to learn how to gravity.
{{ orbit }}
Now that we can gravity, let's see if we can do it with elasticity!
{{ bounce }}
Now you know how to gravity with elasticity! Good work physics friend!
|]
time = fst <~ timestamp (fps 40)
sunAndEarthAt time =
let earth = group [ filled blue (circle 20), toForm (plainText "Earth") ]
sun = group [ filled yellow (circle 35), toForm (plainText "Sun") ]
position = (120 * cos (inSeconds time), 80 * sin (inSeconds time))
in collage 500 300
[ move position earth, move (25,0) sun ]
sunAndEarth = lift sunAndEarthAt time
bouncingBallAt t =
let y = abs (200 * sin (inSeconds t)) - 100
in collage 300 300
[ move (0,y) (filled red (circle 15)),
move (0,0-125) (filled green (rect 300 50)) ]
bouncingBall = lift bouncingBallAt time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment