UNPKG

7.55 kBMarkdownView Raw
1# AgentScript
2
3AgentScript is a minimalist Agent Based modeling system based on [NetLogo](https://ccl.northwestern.edu/netlogo/) semantics.
4
5It has a Model/View/Control (MVC) architecture which cleanly separates the three components.
6
7- **Model**: Provides NetLogo-like semantics for Patches, Turtles and Links. It has no colors, shapes, sizes etc for viewing the model.
8
9- **View**: Use the Model properties to create a view. There can be many Views. We provide a [2D Canvas](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) view and a [Three.js](https://threejs.org/) 2.5D and 3D views. There is also GIS support via a [gis module](https://github.com/backspaces/agentscript/blob/master/src/gis.js), a [geojson module](https://github.com/backspaces/agentscript/blob/master/src/geojson.js), as well as [Leaflet](https://leafletjs.com/) and [MapLibre](https://github.com/maplibre/maplibre-gl-js#readme/) based demos. Plot views are also available.
10
11- **Controls**: We use [src/GUI.js](https://code.agentscript.org/src/GUI.js) via [dat.gui](https://github.com/dataarts/dat.gui) for a menu UI, a [Mouse module](https://github.com/backspaces/agentscript/blob/master/src/Mouse.js) for selecting Model objects (Patches, Turtles and Links), an [Animator](https://github.com/backspaces/agentscript/blob/master/src/Animator.js) for fine control over the Model/Draw steps.
12
13## Modern JavaScript
14
15AgentScript is entirely ES6 Module based with [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) statements.
16
17This allows direct access to individual modules which will automatically load only the module and its dependencies.
18
19Example: to import Class Model for building your own model, use:
20
21> import Model from './path/to/agentscript/src/Model.js'
22
23.. where path/to/agentscript is a local file system path or a url to a server:
24
25- local: [./src/Model.js](https://raw.githubusercontent.com/backspaces/agentscript/master/src/Model.js)
26- code.agentscript.org: [https://code.agentscript.org/src/Model.js](https://code.agentscript.org/src/Model.js)
27- unpkg.com: [https://unpkg.com/agentscript/src/Model.js](https://unpkg.com/agentscript/src/Model.js)
28- skypack.dev: [https://cdn.skypack.dev/agentscript/src/Model.js](https://cdn.skypack.dev/agentscript/src/Model.js)
29
30There are bundles as well of all the agentscript modules as a single file from the usual NPM-based CDNs:
31
32- unpkg.com: [https://unpkg.com/agentscript/dist/agentscript.js](https://unpkg.com/agentscript/dist/agentscript.js)
33
34To create your own local agentscript files:
35
36- Go to: https://github.com/backspaces/agentscript
37- Click on the large green `Code` button
38- Click on `Download ZIP`. The creates the file agentscript-master.zip
39- Unzip this. Creates agentscript-master/
40- Rename/Move to where you want it.
41
42## Files
43
44Our directory layout is:
45
46### The core agentscript directories:
47
48- [models/](https://github.com/backspaces/agentscript/tree/master/models): simple sample/demo models. All are es6 modules used in onepagers below
49- [src/](https://github.com/backspaces/agentscript/tree/master/src): all the agentscript source code. All are es6 modules
50- [docs/](https://code.agentscript.org/docs/) Documentation for all the individual modules used by the programmer.
51
52### Developer directories:
53
54- [bin/](https://github.com/backspaces/agentscript/tree/master/bin): workflow scripts
55- [dist/](https://unpkg.com/browse/agentscript/dist/): the umd and esm bundles with their min.js versions and src/.
56- [test/](https://github.com/backspaces/agentscript/tree/master/test): testing using Deno with it's browser environment running all models/ using its test feature to report errors.
57- [config/](https://github.com/backspaces/agentscript/tree/master/config): tools for creating "bundles".<br>
58
59## Run demos
60
61The models directory contains the individual Models JavaScript files. I.e. HelloModel.js exports the HelloModel etc. It is the only demo directory with .js files, the rest are "onepagers" .html files.
62
63[models](https://code.agentscript.org/models/)
64
65The views1 onepagers import models from the models/ dir and run for 500 steps, printing out a sample of the model's data.
66
67[views1](https://code.agentscript.org/views1/)
68
69The views2 onepagers import models from the models/ dir and add a 2D Canvas view.
70
71[views2](https://code.agentscript.org/views2/)
72
73The views25 onepagers import models from the models/ dir and add a Three.js webgl 2.5D view.
74
75[views25](https://code.agentscript.org/views25/)
76
77The views3 onepagers import models from the models/ dir and add a Three.js webgl 3D view.
78
79They are similar to the views25 onepagers but use
80[src/Model3D.js](https://github.com/backspaces/agentscript/blob/master/src/Model3D.js)
81and [src/Turtle3D.js](https://github.com/backspaces/agentscript/blob/master/src/Turtle3D.js)
82which are subclasses of their 2D counterparts:
83[src/Model.js](https://github.com/backspaces/agentscript/blob/master/src/Model.js)
84and [src/Turtle.js](https://github.com/backspaces/agentscript/blob/master/src/Turtle.js)
85
86[views3](https://code.agentscript.org/views3/)
87
88The mvc onepagers are combine Models, Views, and Controls into "apps".
89
90[mvc](https://code.agentscript.org/mvc/)
91
92AgentScript provides a way to include your models on a map. These two sets of onepagers use gis & geojson utilities to create and view models running on [Leaflet](https://leafletjs.com/) and [maplibre](https://github.com/maplibre/maplibre-gl-js#readme/) maps.
93
94[leaflet](https://code.agentscript.org/leaflet)
95
96and
97
98[maplibre](https://code.agentscript.org/maplibre/)
99
100<!-- [fb](./fb/README.md)
101
102An experimental distributed framework for running models in one page while listening & getting results in another. We call these Model Transforms. They currently show their results in the browser console. -->
103
104## Developer Information
105
106Most users need not worry about this, you can access all the AgentScript code as described above using local files or servers. This is for those wishing to build the AgentScript system itself.
107
108To clone the github repo:
109
110- cd to where you want the agentscript/ dir to appear.
111- git clone https://github.com/backspaces/agentscript
112- cd agentscript # go to new repo
113- yarn install # install all dev dependencies.
114- yarn build # install all our dependencies.
115 Note: Fine to use npm rather than yarn.
116
117All workflow is npm run scripts. See package.json's scripts, or use `yarn/npm run` for a list of all scripts. [JavaScript Standard Style](https://standardjs.com/) is used, see the [prettierrc.js](https://github.com/backspaces/agentscript/blob/master/.prettierrc.js).
118
119## License
120
121Copyright Owen Densmore, RedfishGroup LLC, 2012-2023<br>
122AgentScript may be freely distributed under the GPLv3 license:
123
124AgentScript is free software: you can redistribute it and/or modify
125it under the terms of the GNU General Public License as published by
126the Free Software Foundation, either version 3 of the License, or
127(at your option) any later version.
128
129This program is distributed in the hope that it will be useful,
130but WITHOUT ANY WARRANTY; without even the implied warranty of
131MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132GNU General Public License for more details.
133
134You should have received a copy of the GNU General Public License
135along with this program, see LICENSE within the distribution.
136If not, see <http://www.gnu.org/licenses/>.