
(/VERSIONCHECK 2) 

(DEFUN |COLOR;*;Df2$;1| (|f| |c| $)
  (COND ((ZEROP |f|) |c|) ('T (CONS (QCAR |c|) (* |f| (QCDR |c|)))))) 

(DEFUN |COLOR;+;3$;2| (|x| |y| $)
  (PROG (|ans| |offset| |diff| |moreThanHalf| |xHueSmaller| |c|)
    (RETURN
     (SEQ
      (COND
       ((EQL (QCAR |x|) (QCAR |y|))
        (CONS (QCAR |x|) (+ (QCDR |x|) (QCDR |y|))))
       (#1='T
        (SEQ
         (COND
          ((< (QCDR |x|) (QCDR |y|))
           (SEQ (LETT |c| |x| . #2=(|COLOR;+;3$;2|)) (LETT |x| |y| . #2#)
                (EXIT (LETT |y| |c| . #2#)))))
         (LETT |diff| (- (QCAR |x|) (QCAR |y|)) . #2#)
         (SEQ (LETT |xHueSmaller| (< |diff| 0) . #2#)
              (EXIT (COND (|xHueSmaller| (LETT |diff| (- |diff|) . #2#)))))
         (SEQ (LETT |moreThanHalf| (< (QUOTIENT2 27 2) |diff|) . #2#)
              (EXIT (COND (|moreThanHalf| (LETT |diff| (- 27 |diff|) . #2#)))))
         (LETT |offset|
               (TRUNCATE
                (SPADCALL
                 (/ (FLOAT |diff| MOST-POSITIVE-DOUBLE-FLOAT)
                    (SPADCALL (FLOAT 2 MOST-POSITIVE-DOUBLE-FLOAT)
                              (/ (QCDR |x|) (QCDR |y|)) (QREFELT $ 9)))
                 (QREFELT $ 10)))
               . #2#)
         (COND
          (|xHueSmaller|
           (COND
            (|moreThanHalf|
             (COND
              ((OR |xHueSmaller| (NULL |moreThanHalf|))
               (LETT |ans| (- (QCAR |x|) |offset|) . #2#))
              ('T (LETT |ans| (+ (QCAR |x|) |offset|) . #2#))))
            (#1# (LETT |ans| (+ (QCAR |x|) |offset|) . #2#))))
          (|moreThanHalf| (LETT |ans| (+ (QCAR |x|) |offset|) . #2#))
          (#1# (LETT |ans| (- (QCAR |x|) |offset|) . #2#)))
         (COND ((< |ans| 0) (LETT |ans| (+ 27 |ans|) . #2#))
               ((< 27 |ans|) (LETT |ans| (- |ans| 27) . #2#)))
         (EXIT (CONS |ans| 1.0))))))))) 

(DEFUN |COLOR;=;2$B;3| (|x| |y| $)
  (COND ((EQL (QCAR |x|) (QCAR |y|)) (= (QCDR |x|) (QCDR |y|))) ('T 'NIL))) 

(PUT '|COLOR;red;$;4| '|SPADreplace| '(XLAM NIL (CONS 1 1.0))) 

(DEFUN |COLOR;red;$;4| ($) (CONS 1 1.0)) 

(PUT '|COLOR;yellow;$;5| '|SPADreplace| '(XLAM NIL (CONS 11 1.0))) 

(DEFUN |COLOR;yellow;$;5| ($) (CONS 11 1.0)) 

(PUT '|COLOR;green;$;6| '|SPADreplace| '(XLAM NIL (CONS 14 1.0))) 

(DEFUN |COLOR;green;$;6| ($) (CONS 14 1.0)) 

(PUT '|COLOR;blue;$;7| '|SPADreplace| '(XLAM NIL (CONS 22 1.0))) 

(DEFUN |COLOR;blue;$;7| ($) (CONS 22 1.0)) 

(PUT '|COLOR;hue;$I;8| '|SPADreplace| 'QCAR) 

(DEFUN |COLOR;hue;$I;8| (|c| $) (QCAR |c|)) 

(DEFUN |COLOR;*;Pi2$;9| (|i| |c| $)
  (SPADCALL (FLOAT |i| MOST-POSITIVE-DOUBLE-FLOAT) |c| (QREFELT $ 8))) 

(PUT '|COLOR;numberOfHues;Pi;10| '|SPADreplace| '(XLAM NIL 27)) 

(DEFUN |COLOR;numberOfHues;Pi;10| ($) 27) 

(DEFUN |COLOR;color;I$;11| (|i| $)
  (SEQ
   (COND
    ((OR (< |i| 0) (< 27 |i|))
     (|error|
      (|concat| "Color should be in the range 1.." (|::| 27 (|String|))))))
   (EXIT (CONS |i| 1.0)))) 

(DEFUN |COLOR;coerce;$Of;12| (|c| $)
  (SPADCALL
   (LIST "Hue: " (SPADCALL (QCAR |c|) (QREFELT $ 25)) "  Weight: "
         (SPADCALL (QCDR |c|) (QREFELT $ 26)))
   (QREFELT $ 28))) 

(DEFUN |Color| #1=()
  (PROG #1#
    (RETURN
     (PROG (#2=#:G1834)
       (RETURN
        (COND
         ((LETT #2# (HGET |$ConstructorCache| '|Color|) . #3=(|Color|))
          (|CDRwithIncrement| (CDAR #2#)))
         ('T
          (UNWIND-PROTECT
              (PROG1
                  (CDDAR
                   (HPUT |$ConstructorCache| '|Color|
                         (LIST (CONS NIL (CONS 1 (|Color;|))))))
                (LETT #2# T . #3#))
            (COND ((NOT #2#) (HREM |$ConstructorCache| '|Color|))))))))))) 

(DEFUN |Color;| ()
  (PROG (|dv$| $ |pv$|)
    (RETURN
     (PROGN
      (LETT |dv$| '(|Color|) . #1=(|Color|))
      (LETT $ (GETREFV 32) . #1#)
      (QSETREFV $ 0 |dv$|)
      (QSETREFV $ 3 (LETT |pv$| (|buildPredVector| 0 0 NIL) . #1#))
      (|haddProp| |$ConstructorCache| '|Color| NIL (CONS 1 $))
      (|stuffDomainSlots| $)
      (QSETREFV $ 6
                (|Record| (|:| |hue| (|Integer|))
                          (|:| |weight| (|DoubleFloat|))))
      $)))) 

(MAKEPROP '|Color| '|infovec|
          (LIST
           '#(NIL NIL NIL NIL NIL NIL '|Rep| (|DoubleFloat|) |COLOR;*;Df2$;1|
              (0 . ^) (6 . |round|) |COLOR;+;3$;2| (|Boolean|) |COLOR;=;2$B;3|
              |COLOR;red;$;4| |COLOR;yellow;$;5| |COLOR;green;$;6|
              |COLOR;blue;$;7| (|Integer|) |COLOR;hue;$I;8| (|PositiveInteger|)
              |COLOR;*;Pi2$;9| |COLOR;numberOfHues;Pi;10| |COLOR;color;I$;11|
              (|OutputForm|) (11 . |coerce|) (16 . |coerce|) (|List| $)
              (21 . |hconcat|) |COLOR;coerce;$Of;12| (|String|)
              (|SingleInteger|))
           '#(~= 26 |yellow| 32 |red| 36 |numberOfHues| 40 |latex| 44 |hue| 49
              |hash| 54 |green| 59 |color| 63 |coerce| 68 |blue| 73 = 77 + 83 *
              89)
           'NIL
           (CONS (|makeByteWordVec2| 1 '(0 0 0 0))
                 (CONS '#(|AbelianSemiGroup&| |SetCategory&| |BasicType&| NIL)
                       (CONS
                        '#((|AbelianSemiGroup|) (|SetCategory|) (|BasicType|)
                           (|CoercibleTo| 24))
                        (|makeByteWordVec2| 31
                                            '(2 7 0 0 0 9 1 7 0 0 10 1 18 24 0
                                              25 1 7 24 0 26 1 24 0 27 28 2 0
                                              12 0 0 1 0 0 0 15 0 0 0 14 0 0 20
                                              22 1 0 30 0 1 1 0 18 0 19 1 0 31
                                              0 1 0 0 0 16 1 0 0 18 23 1 0 24 0
                                              29 0 0 0 17 2 0 12 0 0 13 2 0 0 0
                                              0 11 2 0 0 20 0 21 2 0 0 7 0
                                              8)))))
           '|lookupComplete|)) 

(MAKEPROP '|Color| 'NILADIC T) 
