ottt

xyzzy の覚え書き

graph

turtle.l で地味にグラフ表示してみる(*scrath* でテスト), spreadsheet-mode で使えると嬉しいかも

    (require "wip/turtle")
    (defun pole-graph(&rest rest)
      (let*((min (apply #'min rest))
            (max (apply #'max rest))
            (total (apply #'+ rest))
            (width win-user::*turtle-window-width*)
            (height win-user::*turtle-window-height*)
            (win-hi (* (-(- min max))))
            (digit(do((x 1 (* x 10)))((>= x win-hi)(/ x 1000))))
            (i 0) (ii ()))
        (setq win-user::*turtle-window-width* (+ 30(* 30 (length rest))))
        (setq win-user::*turtle-window-height* (/ win-hi digit 2)) ;
        (win-user::with-turtle-paint
          (win-user::turtle-right 90)
            (dolist (a rest)
              (setq ii (* 25 (incf i)))
              (dotimes (b (/ (if (plusp a) a (* (- a)))
                             (* digit 10))) ;
                (win-user::turtle-setpos ii (if(plusp a)
                                                (- (/ win-user::*turtle-window-height* 2) b)
                                              (+ (/ win-user::*turtle-window-height* 2) b)))
                (win-user::turtle-lineto 20))
              ))
          (setq win-user::*turtle-window-width* width)
          (setq win-user::*turtle-window-height* height)
    (format t "min:~15T~D~%max:~15T~D~%average:~15T~D~%total:~15T~D~%"
            min max (round (/ total (length rest))) total)
        ))
    (pole-graph 10 20 30 20 50 100 5)
    =>min:           5
    =>max:           100
    =>average:       34
    =>total:         235
    =>nil
    (defun circle-graph(&rest rest)
      (let((total (apply #'+ rest))
           (p 360)(x 50)(y 200)
           percent result radius)
        (setq radius (/ p pi));?2
        (dolist (x rest (setq percent (nreverse percent)))
          (push (* (/ x total) p) percent)
          (push (list x (floor (* (/ x total) 100))) result))
        (win-user::with-turtle-paint
          (win-user::turtle-setpos x y)
          ;circle
          (dotimes (a p)
            (win-user::turtle-right 1)
            (win-user::turtle-lineto 2))
          ;base line
          (win-user::turtle-setpos (+ x radius) y)
          (win-user::turtle-lineto radius)
          ;
          (dolist (b percent)
            (win-user::turtle-right b)
            (win-user::turtle-setpos (+ x radius) y)
            (win-user::turtle-lineto radius))
          (format t "~{~{~D~5T:~10T~A%~}~%~}" (nreverse result))
          )))
    (circle-graph 31 3 6 8 9 45 8 32 43 35)
    =>31   :    14%
    =>3    :    1%
    =>6    :    2%
    =>8    :    3%
    =>9    :    4%
    =>45   :    20%
    =>8    :    3%
    =>32   :    14%
    =>43   :    19%
    =>35   :    15%
    =>nil

last modified Sun, 27 Jan 2008 15:40:02 JST-9