github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

sebastiaanvisser / frp-js

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: 1168635

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Functional Reactive DSL in Haskell that compiles to JavaScript. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

FRP -> Val 
sebastiaanvisser (author)
Sat May 16 14:09:17 -0700 2009
commit  116863503f64964bcc5bdbb33d9a43e9658270dd
tree    e8663a4a66d41e2a4a126c0536df52d91e6fbf77
parent  c5285c29ff5340f91b797da81ea66e720107e921
frp-js / src / Demo.hs src/Demo.hs
100644 70 lines (54 sloc) 1.779 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Demo (demo) where
 
import Control.Monad
import Geometry
import List
import Number
import Prelude hiding (mod, max, min, reverse, sin)
import Text
import Val
import Window
 
demo :: FRP ()
demo =
  do let red = ById "first"
         blue = ById "second"
         orange = ById "third"
         magenta = ById "fourth"
         pink = ById "fifth"
         boxes = [blue, orange, magenta, pink]
 
         yellow = ById "header"
 
         t1 = input "t1"
         t2 = input "t2"
         t3 = input "t3"
         t4 = input "t4"
         t5 = input "t5"
         
         subs = [blue, orange, magenta, pink]
 
     -- Window title follows mouse cursor.
     text Window <-: string (List [string (px Mouse), string (py Mouse)])
 
     -- Background color depends on mouse state.
     color Body <-:
       _if (down Mouse)
         (con "green")
         (con "white")
 
     -- Let yellow be sorted list of the five input fields.
     let inputs = List $ map text [t1, t2, t3, t4, t5]
     text yellow <-: string (sort inputs)
 
     -- Set initial geomtry.
     geom (0, 0, 40, 40) `mapM_` subs
     geom (0, 0, 400, 300) red
 
     -- Let red and yellow follow mouse.
     left red <-: 200 `max` (px Mouse - width red / 2) `min` 600
     top red <-: 200 `max` (py Mouse - height red / 2) `min` 400
     overlay yellow red 20
 
     -- Let color boxes follow red.
     mapM_ grow boxes
     zipWithM_ attachCenter boxes (corners red)
 
-- Helpers.
 
grow :: Geometry a => a -> FRP ()
grow a =
  do let s = 60 + 40 * sin (time / 200)
     width a <-: s
     height a <-: s
 
attachCenter :: Geometry a => a -> (Val Number, Val Number) -> FRP ()
attachCenter a (x, y) =
  do left a <-: x - width a / 2
     top a <-: y - height a / 2
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server