Midas v2.0

Examples

rule helloWorld
   Wave
   display "Hello world!"
end
Hello Lode
rule helloWorld
   Wave { user ⩵ "Lode" }
   display "Hello Lode!"
end
Hello ?user
rule helloWorld
   w = Wave
   display "Hello ", w.user, "!"
end
Simple Tap
rule tap
   t1 = Touch { state ⩵ Touch.DOWN }
   t2 = Touch { state ⩵ Touch.UP && finger ⩵ t1.finger }
   t1<-beforeF t2, 200.ms
   assert Tap { finger ⇒ t1.finger, time ⇒ t2.time }
end
Double Tap
rule doubleTap
   t1 = Tap
   t2 = Tap { finger ⩵ t1.finger }
   t1<-beforeF t2, 500.ms
   assert DoubleTap { finger ⇒ t1.finger, time ⇒ t2.time }
end
Flick Left
attempt flickLeft
    return movingTouch(10.px, 20.px, -3.px, 3.px)
end
Double Flick Left
rule doubleFlickLeft
    f1 = flickLeft
    f2 = flickLeft
 
    # Temporal relation: At the same time (approximately)
    f1←equalF f2, 150.ms
 
    # Spatial relation: f1 below f2 (in px,mm,... or normalised [0..1])
    f1←near_belowF f2, 100.px
 
    assert DoubleFlickLeft { time_begin ⇒ f1.time_begin, time_end ⇒ f1.time_end }
end
Reused building blocks
module Time
  time
 
  attempt self←equal(time1, time2)         # Similar to class methods in Java
    Math.abs(t1.time - t2.time) < eps
  end
  attempt beforeF(f, eps = 0)              # Similar to instance methods in Java
    time + eps < f.time
  end
end
module TimeInterval
  time_begin, time_end
 
  attempt equalF(f, eps = 0.1.ms)
    Time←equal(time_begin, f.time_begin, eps)
  end
end
module Space2DInterval
  x_begin, x_end
  y_begin, y_end
 
  attempt near_belowF(f, y_diff)
    y_begin < f.y_begin
    y_begin + y_diff > f.y_begin
  end
end
attempt movingTouch(min_x, max_x, min_y, max_y)
  t1 = Touch2D                             # Match a touch event
  t2 = Touch2D { finger ⩵ t1.finger }     # Match another event from the same finger
  t1←beforeF t2                            # t1 happens before t1
  t2.x > t1.x + min_x                      # t2 within a bounding box relative to t1
  t2.x < t1.x + max_x
  t2.y > t1.y + min_y
  t2.y < t1.y + max_y
  return { time_begin ⇒ t1.time, time_end ⇒ t2.time,
           x_begin ⇒ t1.x, x_end ⇒ t2.x, y_begin ⇒ t1.y, y_end ⇒ t2.y
         } with [TimeInterval, Space2DInterval]
end

JMidas v1.0

Examples

Hello world
(defrule HelloWorld
   ?wave <- (Wave)
 =>
   (printout t "Hello world!"))
Hello Lode
(defrule HelloWorld
   ?wave <- (Wave (user "Lode"))
 =>
   (printout t "Hello Lode!"))
Hello ?user
(defrule HelloWorld
   ?wave <- (Wave (user ?user))
 =>
   (printout t "Hello " ?user "!"))
Simple Tap
(defrule Tap
   ?t1 <- (Touch (state ?*DOWN*))
   ?t2 <- (Touch (state ?*UP*))
   (test (time:shortlyafter ?t2 ?t1))
 =>
   (assert (Tap)))
Double Tap
(defrule DoubleTap
   ?t1 <- (Tap)
   ?t2 <- (Tap)
   (test (time:shortlyafter ?t2 ?t1))
 =>
   (assert (DoubleTap)))
Flick Left
(defrule FlickLeft
    ?eventList[] <(ListOf (Cursor (same: id) (within: 500) (min: 5)))
    (space:movingLeft ?eventList[])
 =>
    (assert (FlickLeft (events ?eventList[]) (time ?eventList[-1].time))))
Double Flick Left
(defrule DoubleFlickLeft
    ?upLeftFlick <(FlickLeft)
    ?downLeftFlick <(FlickLeft)
 
    ; Temporal relation: At the same time (approximately)
    (time:equal ?upLeftFlick.events ?downLeftFlick.events)
 
    ; Spatial relation: DownLeftFlick below the UpLeftFlick (approximately)
    (space:nearBelowOf ?downLeftFlick.events ?upLeftFlick.events)
 =>
    (assert (DoubleFlickLeft (time ?upLeftFlick.time))))
research/midas/gestures.txt · Last modified: 2015/07/03 11:31 by lhoste
Trace: gestures