Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Last active December 31, 2015 23:29
Show Gist options
  • Select an option

  • Save pedrofurla/8060815 to your computer and use it in GitHub Desktop.

Select an option

Save pedrofurla/8060815 to your computer and use it in GitHub Desktop.
---- Put it together and show it ----
main = lift3 presentation sunAndEarth bouncingBall sineGraph
presentation figure1 figure2 f3 =
flow down [ figure1, figure2, f3 ]
-- Signal.foldp : (a -> b -> b) -> b -> Signal a -> Signal b
-- Text.asText : a -> Element
-- Signal.lift : (a -> b) -> Signal a -> Signal b
-- Time.fps : number -> Signal Time
-- Signal.lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
---- Text ----
---- Diagrams ----
time = lift (inSeconds . fst) (timestamp (fps 20))
sunAndEarthAt angle =
let earth = group [ filled lightBlue (circle 20), toForm (plainText "Earth") ]
sun = group [ filled lightYellow (circle 35), toForm (plainText "Sun") ]
in collage 300 200
[ earth |> move (120 * cos angle, 80 * sin angle)
, sun |> move (25,0), toForm (asText angle) |> move (50,-90)]
sunAndEarth = lift sunAndEarthAt time
bouncingBallAt angle =
let ball = filled red (circle 15)
ground = filled green (rect 300 50)
in collage 300 200
[ ball |> move (0, abs (150 * sin angle) - 75),
ground |> move (0,-100) ]
bouncingBall = lift bouncingBallAt time
bounds w h = {
center = (0,0), top = h / 2, right = w / 2,
topRight = (round <| w / 2, round <| h / 2), bottonLeft = (round <| -w / 2, round <| -h / 2),
width = round <| w + 2, height = round <| h + 2 }
b = bounds 302 302
colWithBounds b = collage b.width b.height
lineColor c = { defaultLine | width <- 3, color <- c }
toDegrees : Float -> Int
toDegrees x = round <| 180 * x / pi
formText = toForm . asText
sine t =
let y = b.top * sin t
x = b.right * cos t
s = (b.right,y)
c = (x,-b.top)
cs = (x,y)
angle = toDegrees <| (\x -> (x/1000))
<| toFloat <| rem (round (1000*(t - pi/2))) (round (2000 * pi))
in colWithBounds b [
segment (0,0) cs |> traced (lineColor red),
segment (0,-150) c |> traced (lineColor green),
segment (150,0) s |> traced (lineColor blue),
segment (-150,0) (150,0) |> traced (solid black),
segment (0,-150) (0,150) |> traced (solid black),
move (10, 75) <| formText <| angle ]
sineGraph = lift sine time
@pedrofurla
Copy link
Author

d'oh... integer division give me the angle, d'oh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment