La Tour Sans Faim




#lang scheme
(require fluxus-016/drflux)
(require alpha/recorder)
(require scheme/class)
(clear)
;(hint-wire)
;(hint-origin)

;(collisions 1)
;(ground-plane (vector 0 0 1) 0)
;(gravity (vector 0 0 -1))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; brick                          
;                                                              
;   ;              ;         ;;                             
;   ;              ;         ;;                          d
;   ;                        ;;                          
;   ;;;;;   ;; ;  ;;   ;;;;  ;;  ;;                     / \         
;   ;   ;;  ;;     ;  ;   ;  ;;                        /   \        
;   ;    ;  ;;     ;  ;      ;; ;                     /     \       
;   ;    ;  ;;     ;  ;      ;;;;                    /       \ c     
;   ;    ;  ;;     ;  ;      ;; ;                   /        /
;   ;   ;;  ;;     ;  ;;     ;;  ;                 /        /
;   ;;;;;   ;;;   ;;   ;;;;  ;;  ;;            b  /________/  a
;                                   


(define brick%
  (class object%
    
    ;; [normal] a e [pos] n-ring n-brick [type] front/back 
    (init a e n-ring n-brick type)
    
    (init-field
     (pi 3.14159265)
     ;; var
     (base .08)
     (height .1)
     (angle (* 95 (/ pi 180))) ;; radiant !
     ;; points
     (b 0)
     (c 0)
     (d 0)
     (f 0)
     (g 0)
     (h 0)
     ;; h-axis --horizontal
     (h-axis 0)
     ;; v-axis --vertical
     (v-axis (vector 0 0 1))
     ;;root
     (root (build-polygons 8 'quad-list))
     ;; prev
     (prev-c 0)
     (prev-d 0)
     (prev-g 0)
     (prev-h 0)
     
     (new-a 0)
     (new-e 0)
     
     )
    
    (super-new)
    
    ;; ask-the-cook
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (define (ask-the-cook)
      (set! angle (* (send cook get-brick-angle)  (/ pi 180))) ;; radiant !
      (set! base (send cook get-brick-base))
      (set! height (send cook get-brick-height))
      )
    
    ;; throw-me
    (define/public (throw-me)
      (with-primitive root
                      (detach-parent)
                      )
      (destroy root))
    
    
    ;; AXIS
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ;; get-h-axis 
    (define (get-h-axis) 
      (set! h-axis 
            (vnormalise
             (vcross
              v-axis
              (vsub e a))              
             )))
    
    ;; get-v-axis
    (define (get-v-axis)
      (set! v-axis
            (vnormalise
             (vcross
              ;;(vsub e a)
              ;;(vsub b a)
              (vsub prev-g prev-c)
              (vsub prev-d prev-c)
              
              ))))
    
    ;; B
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ;; get-b    
    (define (get-b)
      (let
          ((ab
            (/
             height
             (sin (- pi angle))))) 
        (set! b 
              (vadd
               a
               (vmul
                h-axis
                ab)))))
    
    ;; C
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ;;get-c
    (define (get-c)
      (let*
          ((alpha (- pi angle))
           (dx (- (* base (cos alpha))))
           (dy (* base (sin alpha)))
           (vx (vmul h-axis dx))
           (vy (vmul v-axis dy))
           (V (vadd vx vy))
           )
        (set! c (vadd a V)))) ;;!
    
    
    ;; get-back-c
    (define (get-back-c)
      (let*
          ((bd (vsub d b))
           (bf (vsub f b))
           (mid-bd (vadd b (vdiv bd 2)))
           ;; norm
           (norm (vcross bf bd)) ;;!
           (mid-ac (vadd mid-bd (vmul (vnormalise norm) height)))
           (a-mid-ac (vsub  mid-ac a))
           (cc (vadd a (vmul a-mid-ac 2)))
           )
        (set! c cc)
        ))
    
    ;; D
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; get-d
    (define (get-d)
      (let*
          ((ac (vsub c a))
           (ae (vsub e a))
           (mid-ac (vadd a (vdiv ac 2)))
           (norm (vcross ac ae))
           (mid-bd (vadd mid-ac (vmul (vnormalise norm) height)))
           (b-mid-bd (vsub  mid-bd b))
           (dd (vadd b (vmul b-mid-bd 2)))
           )
        (set! d dd)
        ))
    
    ;; get-back-d  ~ get-c
    (define (get-back-d)
      (let*
          ((alpha (- pi angle))
           (dx (+ (* base (cos alpha)))) ;; cos
           (dy (* base (sin alpha))) ;;sin
           (vx (vmul h-axis dx))
           (vy (vmul v-axis dy))
           (V (vadd vx vy))
           )
        (set! d (vadd b V)))) ;;;;;;;;;;;;;;;;;;;;
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; get-f
    (define (get-f)
      (let
          ((ab
            (/
             height
             (sin (- pi angle))))) 
        (set! f 
              (vadd
               e
               (vmul
                h-axis
                ab)))))
    ;; get-g
    (define (get-g)
      (set! g (vadd e (vsub c a))))
    
    ;; get-h
    (define (get-h)
      (set! h (vadd f (vsub d b))))
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; build-brick
    (define (build-brick)
      (with-primitive root
                      (hint-wire)
                      (hide 1)
                      (camera-hide 0)
                      ;(colour (rndvec))
                      (pdata-set! "p" 0 a)
                      (pdata-set! "p" 1 c)
                      (pdata-set! "p" 2 d)
                      (pdata-set! "p" 3 b)
                      
                      (pdata-set! "p" 4 e)
                      (pdata-set! "p" 5 g)
                      (pdata-set! "p" 6 h)
                      (pdata-set! "p" 7 f)
                      
                      (poly-set-index (list 
                                       0 1 2 3
                                       4 7 6 5
                                       7 3 2 6
                                       5 1 0 4
                                       4 0 3 7
                                       2 1 5 6
                                       
                                       ))
                      (recalc-normals 0)))
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; rad-degree
    (define (rad-degree angle)
      (*
       angle
       (/
        180
        pi)))
    
    ;; get-angles
    (define (get-angles)
      (let*
          ((ab (vsub b a))
           (ac (vsub c a))
           (dc (vsub c d))
           (db (vsub b d))
           
           (dot-a (vdot ab ac))
           (a (acos
               (/ dot-a (* (vmag ab)(vmag ac)))))
           )
        (display "angle a:")(display (rad-degree a)) (newline)
        ))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; debug
    (define (debug)
      (display "BRICK")(newline)
      (display "a:")(display a)(newline)
      (display "e:")(display e)(newline)
      (display "h-axis:")(display h-axis)(newline)
      (display "b:")(display b)(newline)
      (display "c:")(display c)(newline)
      (display "d:")(display d)(newline)
      (display "length:")(display (vmag (vsub e a)))(newline)
      
      )
    ;; return-c
    (define/public (return-c)
      c)
    ;; return-d
    (define/public (return-d)
      d)
    ;; return-g
    (define/public (return-g)
      g)
    ;; return-g
    (define/public (return-h)
      h)
    ;; return-root
    (define/public (return-root)
      root)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; start
    (define (start)
      (cond
        ;; rang N2
        ((> n-ring 0)
         (set! prev-c (send cake get-prev-c (- n-ring 1) n-brick))
         (set! prev-d (send cake get-prev-d (- n-ring 1) n-brick))
         (set! prev-g (send cake get-prev-g (- n-ring 1) n-brick))
         (set! prev-h (send cake get-prev-h (- n-ring 1) n-brick))
         
         
         
         (set! a prev-c)   ;;  !!!!!
         ;(set! a (vector (vector-ref a 0)(vector-ref a 1)(vector-ref prev-c 2)))
         (set! e prev-g)   ;;
         ;(set! e (vector (vector-ref e 0)(vector-ref e 1)(vector-ref prev-g 2)))
         (set! f prev-h)
         ;(set! f (vadd e (vsub prev-h prev-g)))
         (set! b prev-d)
         ;(set! b (vadd a (vsub prev-d prev-c)))
         
         (get-v-axis) ;; !
         
         )))
    
    ;; main
    (ask-the-cook)
    (start)    
    (get-h-axis) ;; !
    
    ;;  B
    (get-b)
    
    ;; C & D
    (cond
      ((equal? type "back")
       (get-back-d)
       (get-back-c))
      (else
       (get-c)
       (get-d)
       ))
    
    ;; F G H
    (get-f)
    (get-g)
    (get-h)
    
    ;; BRICK
    
    (build-brick)
    ;; game
    (cond 
      ((send cook get-game-status)
       (with-primitive root (apply-transform))
       (active-box root)))
    
    ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SEGMENT                                           
;                                                    ;  
;   ;;;;   ;;;;   ;;;;;  ;;;;;  ;;    ;;;;  ;;;;;   ;;; 
;   ;  ;  ;   ;  ;   ;   ;;  ;;   ;  ;   ;  ;;   ;  ;;  
;   ;     ;;;;;  ;   ;   ;;   ;   ;  ;;;;;  ;;   ;  ;;  
;    ;;   ;      ;   ;   ;;   ;   ;  ;      ;;   ;  ;;  
;      ;  ;       ;;;    ;;   ;   ;  ;      ;;   ;  ;;  
;      ;  ;;      ;      ;;   ;   ;  ;;     ;;   ;  ;;  
;   ;;;    ;;;;   ;;;;   ;;  ;;  ;;;  ;;;;  ;;  ;;;  ;; 
;                ;    ;                                 
;                ;    ;                                 
;                ;;;;                                   
;                                                       


(define segment%
  (class object%
    (init-field
     (a 0)
     (e 0)
     (root-a 0)
     (root-e 0)
     )
    (super-new)
    
    ;; set-coords
    (define/public (set-coords)
      (with-primitive root-a
                      (apply-transform)
                      (set! a (pdata-ref "p" 0)))
      (with-primitive root-e
                      (apply-transform)
                      (set! e (pdata-ref "p" 0))))
    ;; set-root-a
    (define/public (set-root-a ob)
      (set! root-a ob))
    ;; set-root-e
    (define/public (set-root-e ob)
      (set! root-e ob))
    ;; get-a
    (define/public (get-a)
      a)
    ;; get-e
    (define/public (get-e)
      e)
    ;; destroy-points
    (define/public (destroy-points)
      (destroy root-a)
      (destroy root-e))
    ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; RING 
;                 
;          ;               
;                            
;   ;; ;  ;;  ;;;;;    ;;;;; 
;   ;;     ;  ;;   ;  ;   ;  
;   ;;     ;  ;;   ;  ;   ;  
;   ;;     ;  ;;   ;  ;   ;  
;   ;;     ;  ;;   ;   ;;;   
;   ;;     ;  ;;   ;   ;     
;   ;;;   ;;  ;;  ;;;  ;;;;  
;                     ;    ; 
;                     ;    ; 
;                     ;;;;   
;                            

(define ring%
  (class object% 
    
    (init n-ring)
    
    (init-field
     (seg-list '())     ;; segments
     (brick-list '())   ;; bricks
     (ring-radius 0)
     (ring-elements 0)
     (prev-alpha 0)
     (first-alpha 0)
     (alpha 0)
     (beta 0)
     (delta 0)
     (brick-length 0)
     (prev-c 0)
     (n-brick 0)
     (brick-orientation "front")
     (shape-type "")
     (min-offset 0)
     (changed? #t) ;; #f
     )
    
    (super-new)
    
    ;;;;;;;;;;;;; ANGLES
    
    ;; get-alpha / angle in segment (rad->degree)
    (define (get-alpha)
      (set! alpha
            (*
             (/ 360 3.1415926535897932384626433832795)
             (asin 
              (/
               brick-length
               (* 2 ring-radius))))))
    
    ;; get-beta  / angle between segment
    (define (get-beta)
      (set! beta
            (/
             (-
              360
              (* ring-elements alpha))
             (+ ring-elements 0))))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SEGMENTS
    
    ;; build-marker / 1 point mesh
    (define (build-marker)
      (let
          ((obj (build-polygons 1 'quad-list)))
        (with-primitive obj
                        (pdata-set! "p" 0 (vector 0 0 0)))
        obj))
    
    ;; 3 build-point 
    (define (build-point)
      (let
          ((point 0))
        (with-state 
         (translate (vadd (vector ring-radius 0 0)))
         (set! point (build-marker))
         point)))
    
    ;; [2] build-segment / (p1 p2) anti-clockwise
    (define (build-segment) 
      (let
          ((segment (make-object segment%)))
        ;; build a
        (send segment set-root-a (build-point)) ;; root-a
        ;; rotate alpha
        (rotate (vector 0 0 alpha))
        ;; build e
        (send segment set-root-e (build-point)) ;; root-e
        ;; add to ob-list
        (set! seg-list (cons segment seg-list))))
    
    ;; [1] build-all-segments / build ob-list 
    (define (build-all-segments x) 
      (with-state ;; with-state
       ;(rotate (vector 0 0 (- delta)))
       (cond
         ((not (zero? x))
          (build-segment)
          ;; rotate beta
          (rotate  (vector 0 0 beta))
          (build-all-segments (- x 1)))
         )
       )
      
      )
    
    ;; get-coords 
    (define (get-coords)
      ;; reverse seg-list
      (set! seg-list (reverse seg-list))
      (for
          ((segment seg-list))
        (send segment set-coords)))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  BRICK
    
    ;; build-bricks
    (define (build-bricks)
      (for
          ((segment seg-list))
        (set! brick-list 
              (append 
               brick-list 
               (list 
                (make-object brick% 
                  (send segment get-a) 
                  (send segment get-e) 
                  n-ring n-brick brick-orientation ))))
        (send segment destroy-points)
        (set! n-brick (+ n-brick 1))))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; INIT
    
    ;; ask the cook : get the receip
    (define (ask-the-cook)
      ;; update-ring
      (send cook update-ring n-ring)
      
      (set! brick-orientation (send cook get-brick-orientation))
      (set! ring-radius (send cook get-ring-radius))
      (set! ring-elements (send cook get-ring-elements))
      (set! min-offset (send cook get-min-offset))
      (set! shape-type (send cook get-shape-type))
      )
      
      ;;;;;;;; brick lenght
      (cond
      ;; ((equal? (send cook get-shape-type) "cone")
               ((not (send cook get-partition-status))

         (if
          (> n-ring 0)
          (set! brick-length (send cake get-prev-brick-length n-ring))
          (set! brick-length (send cook get-brick-length))
          ))
       (else
        (set! brick-length (send cook get-brick-length))))
        
      
      ;; look-underneath : get ring radius
      (define (look-underneath)
        (cond
          ((> n-ring 0)
           (set! prev-c (send cake get-prev-c (- n-ring 1) 0))
           (set! ring-radius (- (vector-ref prev-c 0) (send cook get-ring-offset)))
           )))
      
      ;; throw-me
      (define/public (throw-me)
        (for
            ((brick brick-list))
          (send brick throw-me))
        )
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  GET DATA
      
      ;; get-prev-c
      (define/public (get-prev-c i)
        (send (list-ref brick-list i ) return-c))
      ;; get-prev-d
      (define/public (get-prev-d i)
        (send (list-ref brick-list i) return-d))
      ;; get-prev-g
      (define/public (get-prev-g i)
        (send (list-ref brick-list i) return-g))
      ;; get-prev-h
      (define/public (get-prev-h i)
        (send (list-ref brick-list i) return-h))
      ;; get-angles
      (define/public (get-angles)
        (cons alpha beta))
      ;; return-delta
      (define/public (return-delta)
        delta)
      ;; get-brick-list
      (define/public (get-brick-list)
        brick-list)
      ;; get-brick-length
      (define/public (get-brick-length)
        brick-length)
      
      ;; n-ring ----?
      (set! n-ring n-ring)  
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  EXPORT
      
      ;; export
      (define/public (export i)
        (let
            ((n 0))
          (for
              ((brick brick-list))
            (set! n (+ n 1))
            (with-primitive (send brick return-root)
                            (detach-parent)
                            (apply-transform) 
                            (save-primitive 
                             (string-append
                              "/home/milovann/Bureau/obj/obj-"
                              (number->string i) 
                              "-"
                              (number->string n)
                              ".obj"))))))
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  BUILD
      
      ;; build-regular
      (define (build-regular)
        (build-all-segments ring-elements)
        (get-coords)
        (build-bricks))
      
      ;; build-cone
      (define (build-cone)
        (get-alpha)
        (get-beta)
        (if
         (= (get-offset) 0)
         (continue)
         (rebuild))
        
        )
      
      ;; get-offset
      (define (get-offset)
        (let*
            (
             (g-degree (- 90 (/ (+ alpha beta) 2)))
             (g-rad (/ (* g-degree 3.1415) 180))
             (h (send cook get-brick-height))
             (l (* (cos g-rad) h))
             (offset (* 2 (- ring-radius h) (sin (/ (* (/ beta 2) 3.1415) 180) )))
             (d (- offset (* l 2)))
             )
          (cond
            ((real? d)
             (if 
              (> d min-offset)
              0
              1))
            (else
             (display "complex!")(newline)
             0))))
      
      ;; continue
      (define (continue)
        (get-delta)
        (build-all-segments ring-elements) 
        (get-coords)
        (build-bricks))
      
      ;; get-delta
      (define (get-delta)
        (cond
          (changed?
           (set! delta (/ (- first-alpha) 2))
           )))
      
      ;; rebuild
      (define (rebuild)
        (set! brick-length (- brick-length (send cook get-brick-cut))) 
        (set! changed? #t)
        (build-cone))
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  main
      
      (ask-the-cook)    
      (look-underneath)
      (get-alpha)
      (get-beta)
      
      ;; color
      (colour (vector 2 2 2))
      (cond
        ((send cook get-draw-color)
         (if
          (equal? brick-orientation "front")
          (colour (vector 2 0 0))
          (colour (vector 0 2 0)))))
      
      (cond
        ((= n-ring 0)
         (send cake set-first-alpha alpha)))
      (set! first-alpha (send cake get-first-alpha))
      
      ;(display "///")(display (send cook get-game-status))
      ;; shape-type
      (cond
        ((equal? shape-type "regular")
         (build-regular)
         )
        ((equal? shape-type "cone")
         (if
          (= n-ring 0)
          (build-regular)
          (build-cone))
         )
        )))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; CAKE
  
  
  ;                                                
  ;                                                
  ;                                                
  ;                              ;;                
  ;                                                
  ;               ;          ;                     
  ;   ; ;;  ;;;   ;;;  ;;;   ;;;;;;   ;;;   ;;;;;  
  ;   ;;   ;   ;  ;   ;  ;;  ;   ;;  ;   ;  ;;  ;  
  ;   ;    ;   ;; ;      ;;  ;   ;;  ;   ;; ;   ;  
  ;   ;    ;   ;; ;    ; ;;  ;   ;;  ;   ;; ;   ;  
  ;   ;    ;   ;; ;   ;  ;;  ;   ;;  ;   ;; ;   ;  
  ;   ;    ;   ;  ;   ;  ;;  ;   ;;  ;   ;  ;   ;  
  ;   ;;    ;;;   ;;; ;;;;;  ;;; ;;   ;;;   ;;  ;; 
  ;                                                
  ;                                                
  ;                                                
  ;                                                
  
  ;; angles
  (define angles '())
  (define deltas '())
  
  ;; axis-list
  (define axis-list '())
  
  ;; build-axis
  (define (build-axis)
    (set! axis-list (append axis-list (list (build-locator)))))
  
  ;; clear-axis
  (define (clear-axis)
    (for
        ((axis axis-list))
      (destroy axis))
    (set! axis-list '()))
  
  ;;clear-angles
  (define (clear-angles)
    (set! angles '()))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; linker
  
  (define (linker)
    (let
        ((ring-list (send cake get-ring-list))
         (n-ring 0)
         )
      (for
          ((ring ring-list))
        (build-axis)
        (set! angles (append angles (list (send ring get-angles))))
        (set! deltas (append deltas (list (send ring return-delta))))
        
        (let
            ((brick-list (send ring get-brick-list)))
          (for
              ((brick brick-list))
            (let
                ((root (send brick return-root)))
              (with-primitive root
                              (parent (list-ref axis-list n-ring))))))
        
        (set! n-ring (+ n-ring 1))
        )))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rotator
  (define (rotator)
    (let
        ((i -1)
         (alpha 10)
         ;(ANGLE (list-ref angles 0))
         )
      ;(display "angles")(newline)
      ;(display angles)(newline)
      ;(display "delta")(newline)
      ;(display deltas)(newline)
      (for
          ((axis axis-list)
           (angle angles)
           (delta deltas)
           )
        ;;(with-primitive axis
        ;;            (rotate (vector 0 0 (* 10 (+ 0 delta)))))
        (with-primitive axis
                        (rotate (vector 0 0  (* i (/  (+ (car angle)(cdr angle)) 4))))
                        ;(rotate (vector 0 0  (* i (+ (/ (car angle) 1) (cdr angle)))))
                        )

                        
                        
        (if
         (= i 1)
         (set! i -1)
         (set! i 1)))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;                             
  ;                             
  ;                             
  ;                ;            
  ;                ;            
  ;                ;            
  ;    ;;;   ;;;   ;  ;;   ;;;  
  ;   ;  ;; ;  ;;  ;  ;   ;   ; 
  ;   ;        ;;  ; ;    ;;;;; 
  ;   ;      ; ;;  ;;;    ;     
  ;   ;     ;  ;;  ;  ;   ;     
  ;   ;     ;  ;;  ;  ;;  ;     
  ;    ;;;  ;;;;;  ;;  ;;  ;;;  
  ;                             
  ;                             
  ;                             
  ;                             
  
  
  (define cake%
    (class object%
      (init-field
       
       (ring-list '())
       (axis-list '())
       (first-alpha 0)
       (n 0)
       
       )
      (super-new)
      
      ;; add-ring
      (define/public (add-ring ring)
        (set! ring-list (append ring-list (list ring))))
      
      ;; get-prev-c
      (define/public (get-prev-c n-ring n-brick)
        (send (list-ref ring-list n-ring) get-prev-c n-brick))
      ;; get-pev-d
      (define/public (get-prev-d n-ring n-brick)
        (send (list-ref ring-list n-ring) get-prev-d n-brick))
      ;; get-prev-g
      (define/public (get-prev-g n-ring n-brick)
        (send (list-ref ring-list n-ring) get-prev-g n-brick))
      ;; get-prev-h
      (define/public (get-prev-h n-ring n-brick)
        (send (list-ref ring-list n-ring) get-prev-h n-brick))
      ;; get-prev-brick-length
      (define/public (get-prev-brick-length n-ring)
        (send (list-ref ring-list (- n-ring 1)) get-brick-length))
      
      ;;throw-me
      (define/public (throw-me)
        (for
            ((ring ring-list))
          (send ring throw-me))
        ;; clear
        (set! ring-list '())
        (clear-axis)
        (clear-angles)
        )
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cook-me
      
      (define/public (cook-me)
        ;; build rings
        (send cook init-partition)
        (for
            ((i (in-range (send cook get-cake-rings))))
          (add-ring (make-object ring% i )))
        ;; turn
        (linker)
        (cond
          ((send cook get-rotation-status)
                (rotator)))  
        ) 
      
      ;; export
      (define/public (export)
        (let
            ((i 0))
          (for
              ((ring ring-list))
            (send ring export i)
            (set! i (+ i 1))
            )))
      
      ;; get-angles
      (define/public (get-angles)
        (let
            ((alpha (send (list-ref ring-list 0) get-angles)))
          alpha))
      
      ;; get-ring-list
      (define/public (get-ring-list)
        ring-list)
      
      ;; set-first-alpha
      (define/public (set-first-alpha angle)
        (set! first-alpha angle))
      ;; get-first-alpha
      (define/public (get-first-alpha)
        first-alpha)
      
      ))
  
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; cook
  
  
  ;                          ;;     
  ;                          ;;     
  ;                          ;;     
  ;    ;;;;   ;;;;    ;;;;   ;;  ;; 
  ;   ;   ;  ;   ;;  ;   ;;  ;;     
  ;   ;      ;    ;  ;    ;  ;; ;   
  ;   ;      ;    ;  ;    ;  ;;;;   
  ;   ;      ;    ;  ;    ;  ;; ;   
  ;   ;;     ;   ;;  ;   ;;  ;;  ;  
  ;    ;;;;   ;;;;    ;;;;   ;;  ;; 
  ;                                 
  ;                                 
  
  (define cook%
    (class object%
      
      (init-field
       
       (brick-position 0) 
       (ring-pos 0)
       (brick-orientation "back")
       
       (ring-radius .8) 
       (cake-rings 32)  
       (ring-elements 8)
       (ring-offset 0)
       (brick-angle 88) 
       (brick-base .11) 
       (brick-height .12)  
       (brick-length .4)
       (brick-cut .1)
       (threshold 0)
       
       (min-offset 0.01)
       (shape-type "regular")  ;; regular | cone
       (threshold-mode "cone") ;; normal | symmetric | asymmetric | cone
       (draw-color? #t)
       (game? #f)
       (partition? #f)
       (rotation? #t)
       )
      
      (super-new)
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; UPDATE
      ;; STATE
      (define state "back")
      (define count 0)
      
      (define threshold-way "up")
      (define symmetry-mode "min")
      (define min-symmetry 3)
      (define max-symmetry 6)
      (define min-count 0)
      (define max-count 0)
      
      (define first-stack? #t)
      
      ;; switch-state
      (define (switch-state)
        (if
         (equal? brick-orientation "front")
         (set! brick-orientation "back")
         (set! brick-orientation "front")))
      
      ;;;;;; update
      
      (define/public (update-ring n)
        
        (set! ring-pos n)
        ;; partition
        (partition)
        (cond
          ;; normal
          ((or (equal? threshold-mode "normal") (equal? threshold-mode "cone"))
           (cond
             ((> count threshold)
              (set! count 0)
              (switch-state)))
           (set! count (+ count 1))
           )
          
          ;; symetric
          ((equal? threshold-mode "symmetric")
           (cond
             (first-stack?
              (cond
                ((< min-count min-symmetry)
                 (set! min-count (+ min-count 1)))
                (else
                 (set! first-stack? #f)
                 (switch-state)
                 (set! count (+ count 1)))))
             (else
              (cond
                ((> count threshold)
                 (set! count 0)
                 (switch-state))
                (else
                 (set! count (+ count 1)))))))
          
          ;; asymmetric
          ((equal? threshold-mode "asymmetric")
           (cond
             ;; min
             ((equal? symmetry-mode "min")
              (cond
                ((< min-count min-symmetry)
                 (set! min-count (+ min-count 1)))
                (else
                 (set! min-count 0)
                 (switch-state)
                 (set! max-count (+ max-count 1))
                 (set! symmetry-mode "max"))))
             ;; max
             ((equal? symmetry-mode "max")
              (cond
                ((< max-count max-symmetry)
                 (set! max-count (+ max-count 1)))
                (else
                 (set! max-count 0)
                 (switch-state)
                 (set! min-count (+ min-count 1))
                 (set! symmetry-mode "min"))))))
          
          ))
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PARTITION
      
      (define n-divisions 5)
      (define n-rings-per-division 0)
      (define part 0)
      
      (define back-brick-base 0)
      (define back-ring-radius 0)
      (define back-ring-elements 0)
      (define back-ring-offset 0)
      (define back-brick-angle 0)
      (define back-brick-height 0)
      (define back-brick-length 0)
      
      ;; backup-datas
      (define (backup-datas)
        (set! back-brick-base brick-base)
        (set! back-ring-radius ring-radius) 
        (set! back-ring-elements ring-elements)
        (set! back-ring-offset ring-offset)
        (set! back-brick-angle brick-angle) 
        (set! back-brick-height brick-height)  
        (set! back-brick-length brick-length)
        )
      ;; restore-datas
      (define (restore-datas)
        (set! brick-base back-brick-base)
        (set! ring-radius back-ring-radius)
        (set! ring-elements back-ring-elements)
        (set! ring-offset back-ring-offset)
        (set! brick-angle back-brick-angle)
        (set! brick-height back-brick-height)
        (set! brick-length back-brick-length)
        )
      
      ;; init-parition
      (define/public (init-partition)
        (let
            ((q (quotient cake-rings n-divisions))
             (r (remainder cake-rings n-divisions))
             )
          (backup-datas)
          (set! n-rings-per-division q)
          ))
      
      ;; partition 
      
      (define/public (partition)
        (cond
          (partition?
        (cond
          ((> part n-rings-per-division)
           (set! part 0)
           (set! brick-length (- brick-length .1))
           (set! brick-angle (- brick-angle 1))
           ))
        (set! part (+ part 1))
        )))
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MODES
      
      ;; switch-threshold-mode
      (define threshold-level 0)
      (define threshold-list (list "normal" "symmetric" "asymmetric" "cone"))
      
      (define/public (switch-threshold-mode)
        (set! threshold-mode (list-ref threshold-list threshold-level))
        (if
         (equal? threshold-mode "cone")
         (set! shape-type "cone")
         (set! threshold 1))
        
        (if
         (< threshold-level (- (length threshold-list) 1))
         (set! threshold-level (+ threshold-level 1))
         (set! threshold-level 0))
        (recook)
        )
      
      ;; shape
      (define/public (switch-shape-mode)
        (if
         (equal? shape-type "cone")
         (set! shape-type "regular")
         (set! shape-type "cone"))
        (recook))
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RE-COOK
      
      ;; adjust-threshold
      (define (adjust-threshold)
        (if
         (equal? threshold-way "up")
         (set! threshold (+ threshold 1))
         (cond
           ((and (> 1 threshold) (not (equal? threshold-mode "symmetric")) (not (equal? threshold-mode "asymmetric")))
            (set! threshold (- threshold 1))))))
      
      ;; init-threshold
      (define/public (init-threshold)
        (cond
          ((equal? threshold-mode "asymmetric")
           (cond
             ((odd? threshold)
              (adjust-threshold)))
           (set! min-symmetry threshold)
           (set! max-symmetry (* threshold 2)))
          ((equal? threshold-mode "symmetric")
           (cond
             ((odd? threshold)
              (adjust-threshold)
              (set! min-symmetry (/ threshold 2)))))
          ))
      
      ;; recook
      
      (define (recook)
        (set! brick-orientation "back") ;; have to enable back on first ring ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        (set! symmetry-mode "min")
        (set! first-stack? #t)
        (init-threshold)
        (set! count 0)
        (set! ring-pos 0)
        (set! min-count 0)
        (set! max-count 0)
        (send cake throw-me)
        (send cake cook-me)
        (send board rebuild)
        (restore-datas)
        (init-partition)
        )
      
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GET DATA
      
      ;; get-ring-radius
      (define/public (get-ring-radius)
        ring-radius)
      ;; get-cake-rings
      (define/public (get-cake-rings)
        cake-rings)
      ;; get-brick-angle
      (define/public (get-brick-angle)
        brick-angle)
      ;; get-brick-orientation
      (define/public (get-brick-orientation)
        brick-orientation)
      ;; get-brick-base
      (define/public (get-brick-base)
        brick-base)
      ;; get-brick-length
      (define/public (get-brick-length)
        brick-length)
      ;; get-brick-height
      (define/public (get-brick-height)
        brick-height)
      
      ;; get-ring-elements
      (define/public (get-ring-elements)
        ring-elements)
      ;; get-ring-offset
      (define/public (get-ring-offset)
        ring-offset)
      ;; get-min-offset
      (define/public (get-min-offset)
        min-offset)
      ;; get-shape-type
      (define/public (get-shape-type)
        shape-type)
      ;; get-draw-color
      (define/public (get-draw-color)
        draw-color?)
      ;; get-brick-cut
      (define/public (get-brick-cut)
        brick-cut)
      ;; get-threshold
      (define/public (get-threshold)
        threshold)
      ;; get-threshold-mode
      (define/public (get-threshold-mode)
        threshold-mode)
      ;; get-game-status
      (define/public (get-game-status)
        game?)
      ;; get-parition-status
      (define/public (get-partition-status)
        partition?)
      ;; get-rotation-status
      (define/public (get-rotation-status)
        rotation?)
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CHANGE DATA
      
      ;; elements
      (define/public (increase-elements)
        (set! ring-elements (+ ring-elements 1))
        (recook))
      
      (define/public (decrease-elements)
        (set! ring-elements (- ring-elements 1))
        (recook))
      
      ;; cake-rings
      (define/public (increase-cake-rings)
        (set! cake-rings (+ cake-rings 1))
        (recook))
      
      (define/public (decrease-cake-rings)
        (set! cake-rings (- cake-rings 1))
        (recook))
      
      ;; ring-radius
      (define/public (increase-ring-radius)
        (set! ring-radius (+ ring-radius .1))
        (recook))
      
      (define/public (decrease-ring-radius)
        (set! ring-radius (- ring-radius .1))
        (recook))
      
      ;; ring-offset
      (define/public (increase-ring-offset)
        (set! ring-offset (+ ring-offset .001))
        (recook))
      
      (define/public (decrease-ring-offset)
        (set! ring-offset (- ring-offset .001))
        (recook))
      
      ;; brick-angle
      (define/public (increase-brick-angle)
        (set! brick-angle (+ brick-angle .5))
        (recook))
      
      (define/public (decrease-brick-angle)
        (set! brick-angle (- brick-angle .5))
        (recook))
      
      ;; brick-base
      (define/public (increase-brick-base)
        (set! brick-base (+ brick-base .01))
        (recook))
      
      (define/public (decrease-brick-base)
        (set! brick-base (- brick-base .01))
        (recook))
      
      ;; brick-height
      (define/public (increase-brick-height)
        (set! brick-height (+ brick-height .01))
        (recook))
      
      (define/public (decrease-brick-height)
        (set! brick-height (- brick-height .01))
        (recook))
      ;;brick-cut
      (define/public (increase-brick-cut)
        (set! brick-cut (+ brick-cut .01))
        (recook))
      
      (define/public (decrease-brick-cut)
        (cond
          ((> brick-cut 0.011)
           (display brick-cut)(newline)
           (set! brick-cut (- brick-cut .01))
           (recook))))
      
      
      ;; threshold
      (define/public (increase-threshold)
        (set! threshold (+ threshold 1))
        (set! threshold-way "up")
        (init-threshold)
        (recook))
      
      (define/public (decrease-threshold)
        (cond
          ((or (>= threshold 2) (equal? threshold-mode "normal") (equal? threshold-mode "cone") )
           (cond
             ((>= threshold 1)
              (set! threshold (- threshold 1))
              (set! threshold-way "down")
              (init-threshold)
              ;(display threshold)(newline)
              (recook))))))
      
      ;; brick-length
      (define/public (increase-brick-length)
        (set! brick-length (+ brick-length .05))
        (recook))
      
      (define/public (decrease-brick-length)
        (set! brick-length (- brick-length .05))
        (recook))
      
      ;; draw-color
      (define/public (set-draw-color)
        (if
         draw-color?
         (set! draw-color? #f)
         (set! draw-color? #t))
        (recook))
      
      ;; export
      (define/public (export)
        (send cake export))
      
      
      ;; switch-game
      (define/public (switch-game)
        (if
         game?
         (set! game? #f)
         (set! game? #t))
        (cond
          (game?
           (collisions 1)
           (ground-plane (vector 0 0 1) 0)
           (gravity (vector 0 0 -1))
           
           ))
        (recook)
        )
      ;; switch-partition
      (define/public (switch-partition)
        (if
         partition?
         (set! partition? #f)
         (set! partition? #t))
        (recook))
      ;; switch-rotation
      (define/public (switch-rotation)
        (if
         rotation?
         (set! rotation? #f)
         (set! rotation? #t))
        (recook))
      
      ;; set-brick-length
      (define/public (set-brick-length l)
        (set! brick-length l))
     
      ))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; CLIENT
  
  ;                                     
  ;          ;;   ;                     
  ;           ;   ;                     
  ;           ;                      ;  
  ;    ;;;;   ;  ;;   ;;;;  ;;;;;   ;;; 
  ;   ;   ;   ;   ;  ;   ;  ;;   ;  ;;  
  ;   ;       ;   ;  ;;;;;  ;;   ;  ;;  
  ;   ;       ;   ;  ;      ;;   ;  ;;  
  ;   ;       ;   ;  ;      ;;   ;  ;;  
  ;   ;;      ;   ;  ;;     ;;   ;  ;;  
  ;    ;;;;  ;;  ;;   ;;;;  ;;  ;;;  ;; 
  
  
  (define client%
    (class object%
      (init-field
       (released? #t)
       )
      (super-new)
      
      ;; get-order
      (define/public (get-order)
        (cond
          ;; elements 
          ((key-pressed "a")
           (cond
             (released?
              (set! released? #f)
              (send cook increase-elements))))
          
          ((key-pressed "q")
           (cond
             (released?
              (set! released? #f)
              (send cook decrease-elements))))
          
          ;; rings 
          ((key-pressed "z")
           (cond
             (released?
              (set! released? #f)
              (send cook increase-cake-rings))))
          
          ((key-pressed "s")
           (cond
             (released?
              (set! released? #f)
              (send cook decrease-cake-rings))))
          
          ;; radius
          ((key-pressed "e")
           (cond (released?
                  (set! released? #f)
                  (send cook increase-ring-radius))))
          
          ((key-pressed "d")
           (cond (released?
                  (set! released? #f)
                  (send cook decrease-ring-radius))))
          
          ;; angle
          ((key-pressed "r")
           (cond (released?
                  (set! released? #f)
                  (send cook increase-brick-angle))))
          
          ((key-pressed "f")
           (cond (released?
                  (set! released? #f)
                  (send cook decrease-brick-angle))))
          
          ;; base
          ((key-pressed "t")
           (cond (released?
                  (set! released? #f)
                  (send cook increase-brick-base))))
          
          ((key-pressed "g")
           (cond (released?
                  (set! released? #f)
                  (send cook decrease-brick-base))))
          
          ;; height
          ((key-pressed "y")
           (cond (released?
                  (set! released? #f)
                  (send cook increase-brick-height))))
          
          ((key-pressed "h")
           (cond (released?
                  (set! released? #f)
                  (send cook decrease-brick-height))))
          
          ;; threshold
          ((key-pressed "u")
           (cond (released?
                  (set! released? #f)
                  (send cook increase-threshold))))
          
          ((key-pressed "j")
           (cond (released?
                  (set! released? #f)
                  (send cook decrease-threshold))))
          
          
          ;; brick-length
          ((key-pressed "o")
           (cond
             (released?
              (set! released? #f)
              (send cook increase-brick-length))))
          
          ((key-pressed "l")
           (cond
             (released?
              (set! released? #f)
              (send cook decrease-brick-length))))
          
          ;; brick-cut
          ((key-pressed "p")
           (cond
             (released? 
              (set! released? #f)
              (send cook increase-brick-cut))))
          
          ((key-pressed "m")
           (cond
             (released? 
              (set! released? #f)
              (send cook decrease-brick-cut))))
          
          ;; ring-offset
          ((key-pressed "i")
           (cond
             (released?
              (set! released? #f)
              (send cook increase-ring-offset))))
          
          ((key-pressed "k")
           (cond
             (released? 
              (set! released? #f)
              (send cook decrease-ring-offset))))
          
          ;; color
          ((key-pressed "w")
           (cond
             (released?
              (set! released? #f)
              (send cook set-draw-color))))
          
          ;; display 
          ((key-pressed "x")
           (cond
             (released?
              (set! released? #f)
              (send board set-display)
              )))
          
          ;; threshold-mode
          ((key-pressed "v")
           (cond
             (released? 
              (set! released? #f)
              (send cook switch-threshold-mode))))
          
          ;; shape-mode
          ((key-pressed "c")
           (cond
             (released? 
              (set! released? #f)
              (send cook switch-shape-mode))))
          
          ;; export
          ((key-pressed "b")
           (cond (released?
                  (set! released? #f)
                  (send cook export))))
          
          
          
          ;;exit
          ((key-pressed "&")
           (exit))
          
          ;; game
          ((key-pressed "é")
           (cond
             (released?
              (set! released? #f)
              (send cook switch-game))))
          
          ;; partition
          ((key-pressed "'")
           (cond
             (released?
              (set! released? #f)
           (send cook switch-partition))))
          
          ;; rotation
          ((key-pressed "(")
           (cond
             (released?
              (set! released? #f)
              (send cook switch-rotation))))
          
          ;; 
          (else
           (set! released? #t))
          ))
      ))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  ;                                    
  ;                                    
  ;                                    
  ;   ;                             ;  
  ;   ;                             ;  
  ;   ;                             ;  
  ;   ;;;;;   ;;;    ;;;   ; ;;  ;;;;  
  ;   ;   ;  ;   ;  ;  ;;  ;;   ;   ;  
  ;   ;   ;; ;   ;;    ;;  ;    ;   ;  
  ;   ;   ;; ;   ;;  ; ;;  ;    ;   ;  
  ;   ;   ;; ;   ;; ;  ;;  ;    ;   ;  
  ;   ;   ;  ;   ;  ;  ;;  ;    ;   ;  
  ;   ;;;;    ;;;   ;;;;;  ;;    ;;;;; 
  ;                                    
  ;                                    
  ;                                    
  ;                                    
  
  (define board%
    (class object%
      (init-field
       (root-list '())
       (data-list '())
       (name-list (list "[a-q] elements" "[z-s] rings" "[e-d] radius" "[r-f] angle" "[t-g] base" "[y-h] height" "[u-j] threshold"  "[o-l] length" "[p-m] cut" "[c] shape" "[v] mode" "[w] color" "[i] info" "[b] export" "[&] exit" "[é] game" "['] partition " "[(] rotation"))
       (camera (build-camera))
       (screen "on")
       )
      
      (super-new)
      
      ;; build-text-info
      (define (build-text-info text)
        (build-text text))
      
      ;; convert
      (define (convert data)
        (if
         data
         "ON"
         "OFF"))
      
      ;; get-data
      (define (get-data)
        (set! data-list (list
                         (send cook get-ring-elements)
                         (send cook get-cake-rings)
                         
                         (send cook get-ring-radius)
                         (send cook get-brick-angle)
                         (send cook get-brick-base)
                         (send cook get-brick-height)
                         (send cook get-threshold)
                         
                         (send cook get-brick-length)
                         (send cook get-brick-cut)
                         (send cook get-shape-type)
                         (send cook get-threshold-mode)
                         " "
                         " "
                         " "
                         " "
                         (convert (send cook get-game-status))
                         (convert (send cook get-partition-status))
                         (convert (send cook get-rotation-status))
                         
                         )))
      
      (define i 0)
      ;; build-roots
      (define (build-roots)
        (with-state
         (rotate (vector 0 0 180))
         (translate (vector 4 7 0))
         (scale (vector .5 .5 5))
         (for
             ((name name-list))
           (set! root-list (append root-list 
                                   (list 
                                    (build-text-info 
                                     (string-append 
                                      (list-ref name-list i)
                                      " : " 
                                      (if
                                       (number? (list-ref data-list i))
                                       (number->string (list-ref data-list i))
                                       (list-ref data-list i)))))))
           (set! i (+ i 1))
           (translate (vector 0 -1 0))
           )))
      ;; hide-roots
      (define (hide-roots)
        (for
            ((root root-list))
          (with-primitive root
                          (hide 1)
                          (camera-hide 0))))
      
      ;; build-board
      (define/public (build-board)
        (cond
          ((equal? screen "on")
           (colour (vector 1 1 1))
           (current-camera camera)
           (ortho)
           (set-ortho-zoom 10)
           (texture (load-texture "/home/milovann/2-DATA/16-FLUXUS/FILES/libs/textures/font.png"))
           (get-data)
           (build-roots)
           (hide-roots)
           (current-camera 0)
           (texture 0)
           )))
      ;; destroy-board
      (define/public (rebuild)
        (for
            ((root root-list))
          (destroy root))
        (set! root-list '())
        (set! i 0)
        (build-board))
      ;; set-display
      (define/public (set-display)
        (if 
         (equal? screen "on")
         (set! screen "off")
         (set! screen "on"))
        (rebuild))
      ))
  
  
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  
  ;; OBJECTS
  
  (define cake (make-object cake%))
  (define cook (make-object cook%))
  (define client (make-object client%))
  (define board (make-object board%))
  
  ;; init
  (send board build-board)
  #|
(current-camera 0)
(texture 0)
|#
  (send cake cook-me)
  
  ;; game
  (define (game)
    (recorder)
    (send client get-order))
  
  ;; start
  (every-frame (game))