]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/maze/maze.factor
Harmonize spelling
[factor.git] / extra / maze / maze.factor
index 0e4af964d3555e65c5d908846daa299fa444adc1..02a868641136cc8f7e7ced63800341e5463ce16d 100644 (file)
@@ -1,7 +1,7 @@
 ! From http://www.ffconsultancy.com/ocaml/maze/index.html
-USING: accessors arrays fry kernel math math.order math.vectors
-namespaces opengl.gl random sequences ui ui.gadgets
-ui.gadgets.canvas ui.render ;
+USING: accessors arrays kernel math math.order math.vectors
+namespaces opengl.demo-support opengl.gl random sequences ui
+ui.gadgets ui.gadgets.canvas ui.gestures ui.render ;
 IN: maze
 
 CONSTANT: line-width 8
@@ -17,7 +17,7 @@ SYMBOL: visited
     [ v+ ] with map
     [ unvisited? ] filter ;
 
-: random-neighbour ( cell -- newcell ) choices random ;
+: random-neighbor ( cell -- newcell ) choices random ;
 
 : vertex ( pair -- )
     first2 [ 0.5 + line-width * ] bi@ glVertex2d ;
@@ -25,26 +25,26 @@ SYMBOL: visited
 : (draw-maze) ( cell -- )
     dup vertex
     glEnd
-    GL_POINTS glBegin dup vertex glEnd
+    GL_POINTS [ dup vertex ] do-state
     GL_LINE_STRIP glBegin
     dup vertex
     dup visit
-    dup random-neighbour dup [
+    dup random-neighbor [
         (draw-maze) (draw-maze)
     ] [
-        2drop
+        drop
         glEnd
         GL_LINE_STRIP glBegin
-    ] if ;
+    ] if* ;
 
 : draw-maze ( n -- )
     line-width 2 - glLineWidth
     line-width 2 - glPointSize
     1.0 1.0 1.0 1.0 glColor4d
     dup '[ _ t <array> ] replicate visited set
-    GL_LINE_STRIP glBegin
-    { 0 0 } dup vertex (draw-maze)
-    glEnd ;
+    GL_LINE_STRIP [
+        { 0 0 } dup vertex (draw-maze)
+    ] do-state ;
 
 TUPLE: maze < canvas ;
 
@@ -58,7 +58,9 @@ M: maze draw-gadget* [ n draw-maze ] draw-canvas ;
 
 M: maze pref-dim* drop { 400 400 } ;
 
+M: maze handle-gesture
+    over T{ button-down { # 1 } } =
+    [ nip relayout f ] [ call-next-method ] if ;
+
 MAIN-WINDOW: maze-window { { title "Maze" } }
     <maze> >>gadgets ;
-
-MAIN: maze-window