backspaces / agentscript Goto Github PK
View Code? Open in Web Editor NEWAn Agent Based Modeling system (ABM)
Home Page: http://backspaces.github.io/agentscript/
License: GNU General Public License v3.0
An Agent Based Modeling system (ABM)
Home Page: http://backspaces.github.io/agentscript/
License: GNU General Public License v3.0
I've been fooled twice! Once a few months ago, and then again the other day. In the examples I see:
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 40
})
and then in the source for TwoDraw
I see that patchesColor
is a config option, so I immediately try:
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 40,
patchesColor: 'white'
})
But it's really supposed to go in the second options object, like so:
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 40
}, {
patchesColor: 'white'
})
I think this is really confusing, especially because there's an option called turtlesSize
which can't go next to patchSize
๐ค
Can we just have one options object?
Where do turtles initially get added to a patch?
Running into issues when I spawn or hatch a turtle and trying to figure out where the disconnect is happening.
Replacing the spawn or hatch with a turtles.createOne() and calling the following:
this.turtles.ask((t) => {
if (!t.patch.turtlesHere().contains(t))
t.patch.turtles.push(t)
})
before attempting to move turtles is a work around:
It turns out that it turtle list is sorted by id, and if you set the id it will mess some internal things, like turtle removal.
Maybe the turtle id should be private, or have a setter that gives you a warning to avoid shooting yourself in the foot?
@backspaces when you get the chance, can you make me a new repo called something like agentscript.org
or agentscript-website
or agentscript-homepage
? Then I'll delete landing-page-src and landing-page from this repo.
I would appreciate if you could show some examples of adding custom turtle shapes with addPath function in src/Shape.js.
I was trying to add custom shapes and found the comments below, but I'm not sure how to do it.
Line 138 in bd71835
Also is it possible to add new shapes from the editor showing examples?
I tried to use it in a similar way to asx ...
import {Model, util} from '../../dist/AS.module.js'
util.toWindow({ Model, util })
class SnorlaxInvaders extends Model {
setup () {
}
step () {
}
}
const options = Model.defaultWorld(1, 80)
const model = new SnorlaxInvaders(document.body, options)
model.setup()
model.start()
const {world, patches, turtles} = model
util.toWindow({ world, patches, turtles, model })
and I got an error
running: ./src/airAttack.js dir: src name: airAttack.js
AS.module.js:130 toWindow: Model, util
AS.module.js:2518 Uncaught TypeError: Cannot read property 'reset' of undefined
at AirAttackers.reset (AS.module.js:2518)
at new Model (AS.module.js:2467)
at new AirAttackers (airAttack.js:8)
at airAttack.js:20
reset @ AS.module.js:2518
Model @ AS.module.js:2467
AirAttackers @ airAttack.js:8
(anonymous) @ airAttack.js:20
Revert to usual objects w/o the two layers, way too slick and hard to reason about.
Need to see how defaults would be implemented.
Currently, only the largest cluster of buttons is indicated by color. It would make the formation of groups easier to see if every cluster was assigned a unique color. Then you would be able to see the distribution of groups more clearly.
bit.ly/AgentscriptIntro
should I put this issue in Redfish-IDE Github instead?
Line 8 in 844d7f4
This line of the package.json file is outdated. It is causing the skypack version to not work.
I found this during a hackathon. I really like the simplicity... but the docs don't work, it 404's on github pages.
When rotating certain meshes, especially cubes, and you connect a link from one object to another, the link is offset by a slight distance. To be more specific, the links usually connect to a spot above the mesh. An example is as follows: https://playground.realtime.earth/linkDebug.html
It looks like Dataset normalize is not working because lerp is not defined.
Line 425 in d95a303
There does not seem to be an atEdge condition to let the agent continue off into space forever. https://github.com/backspaces/agentscript/blob/master/src/Turtle.js#L174-L180
Maybe it could be called 'nothing' or 'continue'?
model.turtles.with(t => t.id>10).ask(t => t.heading=0)
)
function forward(val) { this.forward(val) }
askWithBind(f) {
return ask(t => f.bind(t)(t))
}
model.turtles.askWithBind( function () {
forward(100)
}
I just wanted to try and run a model multiple times just by calling node
.
Is there an example on how to do it?
So far for commands like these:
import {Model} from 'agentscript';
I just get a bunch of "ReferenceError: document is not defined" when called through node
.
Is there a different approach to achieve the same task?
It looks like the size of a TwoDraw
canvas is closely related to the coordinate system of the model. It would be awesome to have a view class that decoupled these. I'm working with views that occupy the full viewport, so I need to be able change the render-size of a view when the user resizes their browser window.
Currently, if I manually change the canvas size, some weird things happen. In sprites mode, patches resize as I would expect, but agents do not. In non-sprites mode, I think I would need to calculate a new euclidean transform.
Line 217 in d97ac75
The function getBBoxDataSet requires a Leaflet map and an elevation layer to be added to that map. It would be nice to be able to load elevation for a bbox without the leaflet map at all.
agentscript/gis/LeafletDataSet.js
Lines 83 to 84 in 3e2a6e7
Here's a pebble showing the boid wiggle behavior that I think is a regression:
You should be able to download that image, then drag it over to https://gentleplants.com/as/editor/ (testing this pebble mechanism at the same time :-P)
If you watch a single boid, you'll see that instead of flying smoothly, it has a very small oscillation back and forth around its heading.
A place to keep track of missing items in the docs so we don't forget. cc @stigmergic @stephenguerin
It would be cool to support not only rectangular grids. An obvious alternative would be a hex grid.
https://en.wikipedia.org/wiki/Hexagonal_tiling#/media/File:Uniform_tiling_63-t0.svg
We need to update mvc/ to new gui, keyboard, and mouse modules
Also add plots, decide on how to make them easily added.
I took the mouse model and set the world options as follows:
{minX: 1, maxX: 9, minY: 1, maxY: 5}
This pebble causes an error:
agentscript.js:4163 Uncaught Error: World patchSize: x/y sizes differ 64.55555555555556, 64.6
at World.patchSize (agentscript.js:4163)
at Mouse.setXY (agentscript.js:36459)
at Mouse.generalHandler (agentscript.js:36442)
at Mouse.handleMouseUp (agentscript.js:36451)
at HTMLBodyElement.Mouse.mouseUp (agentscript.js:36411)
No weeoe when I specify a square world.
I would like to set the world to be twice as wide as it is high.
See #20
The center is guessed from the bbox. It might be nice to guess the Z value also.
agentscript/gis/leafletInit.js
Line 68 in 8e999fe
Deprecation warnings are useful but get annoying if they are printed with every use
Right now turtle.forward('dogs')
or just turtle.forward(undefined)
leaves turtle
in a broken state, stranded at NaN, NaN. Instead, turtle.forward('dogs')
should raise a ValueError.
I noticed this when editing running code in the landing page tutorial.
First of all. Thank you for making this web-based netlogo. I really enjoy combining the expressive modeling experience of NL semantics and the powerful javascript and web ecosystem.
The issue:
let m = new AS.Model();
m.turtles.create(100, (t) => t.setxy(0, 0));
m.turtles.ask((t) => t.die());
Not all turtles will be dead. It will often kill half of the turtles.
I was looking at the slopes on the droplets model https://code.agentscript.org/views2/droplets.html , and it occurred to me that the slopes look wrong. If you look at model.slopes
they are all values like 1.4 which is like 80 degrees. I was not expecting slopes bigger than like 10 degrees for that area.
I think it has to do with the way dzdx and dzdy are calculated. They are treating the z values in meters, but the x,y values in terms of pixel dimensions. I think that the x and y should be in terms of meters too.
I wrote some helper functions that seem to work. My question is wether you would be interested in me putting those into a pull request? would we be interested in another class for GeoDatasets?
/**
* utils
*
* */
function geoDzdx(elevation, widthInMeters) {
const pixelScale = widthInMeters / elevation.width
const dzdx = elevation.dzdx(2, (1/8) * (1/pixelScale)) // (1/8) for the kernel and 1/pixelscale to get units right
return dzdx
}
function geoDzdy(elevation, heightInMeters) {
const pixelScale = heightInMeters / elevation.height
const dzdy = elevation.dzdy(2, (1/8) * (1/pixelScale))
return dzdy
}
function slope(dzdx, dzdy) {
const slopes = dzdx.map((x, i) => {
const y = dzdy.data[i]
const a = Math.hypot(-x, -y)
const sl = (Math.PI / 2) - Math.atan2(1, a)
return sl
})
return slopes
}
/**
* Calculate the slope of elevation Dataset in meters
* @param {DataSet} elevationDS
* @param {number} widthMeters The width in meters of the elevation dataset
* @param {number} heightMeters The height in meters of the elevation dataset
* @return {DataSet} slopes The slopes in radians
* */
function slopeFromElevationDS(elevationDS, widthMeters, heightMeters) {
const dzdx = geoDzdx(elevationDS, widthMeters)
const dzdy = geoDzdy(elevationDS, heightMeters)
const slopes = slope(dzdx, dzdy)
return slopes
}
/**
* Calculate the slope of elevation Dataset in meters
* @param {DataSet} elevationDS
* @param {[west, south, east, north]} bounds
* @return {DataSet} slopes The slopes in radians
* */
function slopeFromElevationDS_bounds(elevationDS, bounds) {
const sizeMeters = bboxMetricSize(bounds)
return slopeFromElevationDS(elevationDS, sizeMeters[0], sizeMeters[1])
}
I'm using a MapDraw and so have set the patches to transparent except where pheromones exist, in which case a non zero opacity is set.
Due to using the transparent patches the turtles leave a non-disappearing trail: is there a way to flush or evaporate old turtle positions?
Thanks!
As I was working on an agentscript model based on netlogo's slime, I noticed that the patchAhead
functions do not wrap, so you have to write code like:
if (!patchRight) {
turtle.left(90)
} else if (!patchLeft) {
turtle.right(90)
}
Or, from AntsModel:
if (p.isOnEdge()) {
t.rotate(180)
}
I think it would make life easier for new modelers if they didn't have to think about that.
I also noticed that patches.diffuse()
does not wrap either. I think it would be more correct if it did (if the world wraps sometimes, it should wrap all the time).
My 6th sense tells me this is a conversation that happened long ago and I am arriving late... I hope it's not a can o' worms :-P
Model pebble:
@backspaces I'm looking w/ my dad at https://github.com/backspaces/agentscript/blob/master/src/Patches.js#L301 :
const dv = p[v] * rate
const dvn = dv / n
const neighbors = n === 8 ? p.neighbors : p.neighbors4
const nn = neighbors.length
p._diffuseNext += p[v] - dv + (n - nn) * dvn
I'm having trouble understanding the last term on the last line. Isn't (n - nn)
always 0?
Currently, if you accidentally use a float for minX
, maxX
, minY
, or maxY
in your model constructor, this error gets thrown:
Uncaught (in promise) TypeError: Cannot read property 'rectCache' of undefined
at Patches.patchRect (Patches.js:183)
at Patches.patchRectXY (Patches.js:204)
at Turtles.inPatchRectXY (Turtles.js:74)
at Turtles.inPatchRect (Turtles.js:66)
at Turtles.inRadius (Turtles.js:85)
at LandingPageFlockModel.flock (FlockModel.js:42)
at FlockModel.js:38
at Turtles.ask (AgentSet.js:272)
at LandingPageFlockModel.step [as step0] (FlockModel.js:37)
at LandingPageFlockModel.stepAndTick (Model.js:110)
Would be nice to catch this upstream and print a more helpful error.
When constructing TwoView, I'm running into the error: "Cannot read width of undefined"
I'm noticing model.world is being set later than I need for making views.
Download html's have broken relative links to docs and examples
E.g. in flock.html, try replacing https://github.com/backspaces/agentscript/blob/master/views2/flock.html#L17-L20 with the following:
import Color from '../src/Color.js'
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 15,
}, {
patchesColor: Color.typedColor('white')
}) // defalt drawOptions!
It seems to work if you change view.clear(patchesColor)
to view.clear(patchesColor.css)
here: https://github.com/backspaces/agentscript/blob/master/src/TwoDraw.js#L108
It looks like the ants lost their motivation to wander. They seem to move out in a straight line from their nest now: https://agentscript.org/views2/ants.html. Maybe has something to do with the radians/degrees refactor?
jsDoc does not allow export default to be used directly on the object within the module where it is defined.
Instead the object has to be declared without the export default and a single separate export used:
export default Foo
Use a jsDoc plugin such as https://github.com/ckeditor/ckeditor5-dev to correct this.
Line 94 in b344c57
Firstly, thanks for this incredibly interesting project.
I see that the latest release is from January but that there has been some more recent activity in the repo. (e.g. GIS modules)
Curious if there will be new releases and what the approximate roadmap is.
This is a very exciting project and I'm hoping it continues development!
At least for our tutorials and IDE, I think it would be nice to support degrees by default when dealing with angles.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.