GithubHelp home page GithubHelp logo

backspaces / agentscript Goto Github PK

View Code? Open in Web Editor NEW
104.0 104.0 14.0 25.81 MB

An Agent Based Modeling system (ABM)

Home Page: http://backspaces.github.io/agentscript/

License: GNU General Public License v3.0

JavaScript 72.01% HTML 27.00% CSS 0.16% TypeScript 0.84%

agentscript's People

Contributors

ankitskvmdam avatar backspaces avatar bennlich avatar m0ose avatar stigmergic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

agentscript's Issues

Consider merging both options objects for `TwoDraw` into one

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?

turtles have patches but those patches do not have the turtles

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:

don't allow override of turtle id

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?

new repo for agentscript.org

@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.

Example of addPath

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.

// Use "addPath()" to add your own new shapes.

Also is it possible to add new shapes from the editor showing examples?

How to use CoreAs?

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

ButtonsModel

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.

docs 404

I found this during a hackathon. I really like the simplicity... but the docs don't work, it 404's on github pages.

how domain specific is this language?

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)

}

Is there a way to run a model headless through node?

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?

How to change the render size of a TwoView?

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.

flock model wiggle regression

Here's a pebble showing the boid wiggle behavior that I think is a regression:

FlockModel 2021-04-24T18_39_13 124Z

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.

Mouse model complains if my world is not square

MouseModel 2021-05-23T03_24_20 505Z

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.

Improve error handling

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.

Ask all Turtles to die can't remove all turtle agent from agentset

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.

slope on droplets off

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])
        }

Turtles leave trails when using transparent patches

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!

World wrap "edge cases"

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:

TutorialModel 2021-04-26T23_41_19 102Z

Add a helpful warning for non-int world size

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.

model.world is not set

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.

Passing a TypedColor into patchesColor doesn't seem to work

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

New Release?

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.