Add Licensing and Contributing
[clnl] / src / main / clnl / nvm / world.lisp
1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3.  See distributed LICENSE.txt.
2 (in-package #:clnl-nvm)
3
4 (defun clear-patches ()
5  (setf
6   *patches*
7   (loop
8    :for y :from (max-pycor) :downto (min-pycor)
9    :append (loop
10             :for x :from (min-pxcor) :to (max-pxcor)
11             :collect (make-patch
12                       :xcor (coerce x 'double-float)
13                       :ycor (coerce y 'double-float)
14                       :color 0d0)))))
15
16 (defun clear-turtles ()
17  (setf *turtles* nil)
18  (setf *current-id* 0))
19
20 (defun clear-ticks ()
21  (setf *ticks* nil))
22
23 (defcommand clear-all ()
24  "CLEAR-ALL => RESULT
25
26   RESULT: :undefined
27
28 DESCRIPTION:
29
30   Clears ticks, turtles, patches, globals (unimplemented).
31
32   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#clear-all"
33  (clear-turtles)
34  (clear-patches)
35  (clear-ticks))
36
37 (defcommand display ()
38  "DISPLAY => RESULT
39
40   RESULT: :undefined
41
42 DESCRIPTION:
43
44   As of yet, this does nothing.  A placeholder method for forced dipslay
45   updates from the engine.
46
47   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#display"
48  nil)
49
50 (defcommand reset-ticks ()
51  "RESET-TICKS => RESULT
52
53   RESULT: :undefined
54
55 DESCRIPTION:
56
57   Resets the tick counter to zero, sets up all plots, then updates all plots.
58
59   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#reset-ticks"
60  (setf *ticks* 0d0))
61
62 (defcommand tick ()
63  "RESET-TICKS => RESULT
64
65   RESULT: :undefined
66
67 DESCRIPTION:
68
69   Advances the tick counter by one and updates all plots.
70
71   If the tick counter has not been started yet with reset-ticks, an error results.
72
73   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#tick"
74
75  (when (not *ticks*) (error "reset-ticks must be called"))
76  (incf *ticks*))
77
78 (defun ticks ()
79  "TICKS => CURRENT-TICKS
80
81 ARGUMENTS AND VALUES:
82
83   CURRENT-TICKS: A positiv double, representing the current number of ticks
84
85 DESCRIPTION:
86
87   Reports the current value of the tick counter. The result is always a number and never negative.
88
89   If the tick counter has not been started yet with reset-ticks, an error results.
90
91   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ticks"
92  (when (not *ticks*) (error "reset-ticks must be called"))
93  *ticks*)