X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?p=clnl;a=blobdiff_plain;f=src%2Fmain%2Fnvm.lisp;h=011eb6d8158c9ce1452f3cabf422bf5352b47c79;hp=3ea76d9309c681662c6f35e686348dc8212fc812;hb=a4cc3c4;hpb=d0e9e5aea40d947370e90276fe12fbaa671c8992 diff --git a/src/main/nvm.lisp b/src/main/nvm.lisp index 3ea76d9..011eb6d 100644 --- a/src/main/nvm.lisp +++ b/src/main/nvm.lisp @@ -2,8 +2,31 @@ ; This is the engine. Yay. +(defvar *current-id* 0) + +(defstruct turtle who color heading) +(defvar *turtles* nil) + +(defun create-turtle () + (push + (make-turtle :who *current-id* + :color (coerce (+ 5 (* 10 (cl-nl.random:next-int 14))) 'double-float) + :heading (coerce (cl-nl.random:next-int 360) 'double-float)) + *turtles*) + (incf *current-id*)) + (defun create-turtles (n) - (format t "HELLO WORLD ~A~%" n)) + (loop for i from 1 to n do (create-turtle))) + +(defun create-world () + (setf *turtles* nil) + (setf *current-id* 0)) + +(defun format-num (n) + (multiple-value-bind (int rem) (floor n) + (if (eql 0d0 rem) + (format nil "~A" int) + (format nil "~F" n)))) (defun export-world () (format nil "~{~A~%~}" @@ -13,11 +36,19 @@ "" (format nil "~S" "GLOBALS") "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\",\"nextIndex\",\"directed-links\",\"ticks\"," - "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"0\",\"\"\"NEITHER\"\"\",\"-1\"" + (format nil "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\"" *current-id*) "" (format nil "~S" "TURTLES") "\"who\",\"color\",\"heading\",\"xcor\",\"ycor\",\"shape\",\"label\",\"label-color\",\"breed\",\"hidden?\",\"size\",\"pen-size\",\"pen-mode\"" - "" + (format nil "~{~A~%~}" + (mapcar + (lambda (turtle) + (format nil + "\"~A\",\"~A\",\"~A\",\"0\",\"0\",\"\"\"default\"\"\",\"\"\"\"\"\",\"9.9\",\"{all-turtles}\",\"false\",\"1\",\"1\",\"\"\"up\"\"\"" + (turtle-who turtle) + (format-num (turtle-color turtle)) + (format-num (turtle-heading turtle)))) + (reverse *turtles*))) (format nil "~S" "PATCHES") "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\"" "\"-1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""