First ugly pass of show
[clnl] / src / main / nvm.lisp
1 (in-package #:cl-nl.nvm)
2
3 ; This is the engine.  Yay.
4
5 (defvar *current-id* 0)
6
7 (defstruct turtle who color heading)
8 (defvar *turtles* nil)
9
10 (defun show (n)
11  (format t "Showing: ~A~%" n))
12
13 (defun create-turtle ()
14  (push
15   (make-turtle :who *current-id*
16                :color (coerce (+ 5 (* 10 (cl-nl.random:next-int 14))) 'double-float)
17                :heading (coerce (cl-nl.random:next-int 360) 'double-float))
18   *turtles*)
19  (incf *current-id*))
20
21 (defun create-turtles (n)
22  (loop for i from 1 to n do (create-turtle)))
23
24 (defun create-world ()
25  (setf *turtles* nil)
26  (setf *current-id* 0))
27
28 (defun format-num (n)
29  (multiple-value-bind (int rem) (floor n)
30   (if (eql 0d0 rem)
31       (format nil "~A" int)
32       (format nil "~F" n))))
33
34 (defun export-world ()
35  (format nil "~{~A~%~}"
36   (list
37    (format nil "~S" "RANDOM STATE")
38    (format nil "~S" (cl-nl.random:export))
39    ""
40    (format nil "~S" "GLOBALS")
41    "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\",\"nextIndex\",\"directed-links\",\"ticks\","
42    (format nil "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\"" *current-id*)
43    ""
44    (format nil "~S" "TURTLES")
45    "\"who\",\"color\",\"heading\",\"xcor\",\"ycor\",\"shape\",\"label\",\"label-color\",\"breed\",\"hidden?\",\"size\",\"pen-size\",\"pen-mode\""
46    (format nil "~{~A~%~}"
47     (mapcar
48      (lambda (turtle)
49       (format nil
50        "\"~A\",\"~A\",\"~A\",\"0\",\"0\",\"\"\"default\"\"\",\"\"\"\"\"\",\"9.9\",\"{all-turtles}\",\"false\",\"1\",\"1\",\"\"\"up\"\"\""
51        (turtle-who turtle)
52        (format-num (turtle-color turtle))
53        (format-num (turtle-heading turtle))))
54      (reverse *turtles*)))
55    (format nil "~S" "PATCHES")
56    "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\""
57    "\"-1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
58    "\"0\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
59    "\"1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
60    "\"-1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
61    "\"0\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
62    "\"1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
63    "\"-1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
64    "\"0\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
65    "\"1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
66    ""
67    (format nil "~S" "LINKS")
68    "\"end1\",\"end2\",\"color\",\"label\",\"label-color\",\"hidden?\",\"breed\",\"thickness\",\"shape\",\"tie-mode\""
69    ""
70    )))