NetLogo GbCC 3.0 View Extensions

Layers in a NetLogo View

Patches + Drawing + Turtles

Patches + Javascript Extension + Image Extension + Drawing + Turtles

View Extensions

Graph

Map

Physics

Image

Graph Extension


Geogebra API https://wiki.geogebra.org/en/Reference:JavaScript

Graph Commands

  extensions [ graph ]
GRAPH
graph:show-graphgraph:hide-graphgraph:show-toolbargraph:hide-toolbargraph:bring-to-frontgraph:send-to-backgraph:set-graph-offset [ left top width height ] show graph:get-graph-offset ;; returns [ left top width height ]graph:set-opacity 0.5 show graph:get-opacity ;; returns any number between 0 and 1show graph:center-view  [ x y ] show graph:mouse-on *** new ***show graph:mouse-off *** new ***
graph:set-all "long-string-of-xml" show graph:get-all ;; returns "long-string-of-xml"graph:import-ggb-file "filename.txt"*** new ***graph:export-ggb "filename.txt"graph:import-ggb*** new ***

POINTS
graph:create-point "Point1" [ 0 0 ]
✓ graph:create-points  [ [ "Point1" [ 0 2 ] ] [ "point-2" [ 0 0 ] ] ]
✓ show graph:get-point "Point1"  ;; [ "Point1" [ 0 2 ] ]show graph:get-points  ;; [ [ "Point1" [ 0 2 ] ] [ "point-2" [ 0 0 ] ] ]graph:delete-point "Point1" graph:delete-points 
graph:set-x "Point1" 0 graph:set-y "Point1" 2 graph:set-xy "Point1" [ 0 2 ] 
✓ show graph:get-x "Point1" ;; returns 0show graph:get-y "Point1" ;; returns 2show graph:get-xy "Point1" ;; returns [ 0 2 ] 
OBJECTS (Including Points)
set  new-object graph:get-object  "MyTriangle1" ;; returns a list with a name and a descriptionset  new-objects graph:get-objects ;; returns list of names and definitions of objects, in order of creation graph:create-object  new-object graph:create-objects  new-objects  graph:delete-object  "Triangle1" graph:delete-objects
show graph:get-value  "MyTriangle1"  ;; returns getValueshow graph:get-object-type  "MyTriangle1"  ;; returns typeshow graph:object-exists  "MyTriangle1"  ;; returns booleangraph:rename-object  "MyTriangle1" "MyTriangle2" graph:show-object  "MyTriangle1" graph:hide-object  "MyTriangle1" graph:show-object-label  "MyTriangle1" graph:hide-object-label  "MyTriangle1" graph:set-draggable "Point1" true *** new ***show graph:get-draggable "Point1" ;; returns true *** new ***show graph:get-command-string  "MyTriangle1"  ;; returns command string like Polygon(A, B, C) *** new ***show graph:get-value-string  "f"  ;; returns value string like "f(x) = 0.25x + 3.75" *** new ***
TRANSLATION between Patch Coordinates and GeoGebra Coordinates
show graph:graph-to-patch [ 0 0 ] ;; returns graph coordinatesshow graph:patch-to-graph [ 0 0 ] ;; returns patch coordinatesgraph:update-graph ;; upon changing center or zoom of graph, sync graph coords and patch coords
GeoGebra Eval Commands
graph:eval-command geogebra-command 
show graph:eval-reporter geogebra-command ;; returns a value

Ideas

Maps Extension


LeafletJS http://leafletjs.com/
GeoJson https://leafletjs.com/examples/geojson/

Maps Extension

  extensions [ graph ]
MAP
maps:show-mapmaps:hide-mapmaps:bring-to-frontmaps:send-to-backmaps:set-map-offset [ left top width height ] show maps:get-map-offset ;; returns [ left top width height ]maps:set-opacity 0.5 show maps:get-opacity ;; returns any number between 0 and 1show maps:mouse-on *** new ***show maps:mouse-off *** new ***
maps:set-all "long-string-of-json" show maps:get-all ;; returns "long-string-of-json" 
MAP SETTINGS
maps:set-zoom 3show maps:get-zoom  ;; returns 3maps:set-center-latlng [ 30 97 ]
✓ show maps:get-center-latlng ;; returns [ 30 97 ]
MARKERS
maps:create-marker "marker-1" [ 0 0 ]
✓ maps:create-markers  [ [ "marker-1" [ 0 0 ] ] [ "marker-2"[ 0 0 ] ] ]
✓ show maps:get-marker  ;; [ "marker-1" [ 0 0 ] ]
✓ show maps:get-markers  ;; [ [ "marker-1" [ 0 0 ] ] [ "marker-2" [ 0 0 ] ] ]
✓ maps:delete-marker "marker-1"maps:delete-markers
maps:set-lat "marker-1" 30 maps:set-lng "marker-1" 97 maps:set-latlng "marker-1" [  30 97 ] 
✓ show maps:get-lat "marker-1" ;; returns 30show maps:get-lng "marker-1" ;; returns 97show maps:get-latlng "marker-1" ;; returns [ 30 97 ] 
maps:set-draggable "marker-1" true *** new ***show maps:get-draggable "marker-1" ;; returns true *** new ***maps:update-my-latlng *** new ***show maps:get-my-latlng ;; returns [ 30 97 ] *** new ***
PATHS
maps:create-path "path-1" [ 0 0 ] 
✓ maps:create-paths  [ [ "path-1" [ 0 0 ] ] [ "marker-2"[ 0 0 ] ] ] 
✓ maps:delete-path "path-1"maps:delete-pathsmaps:set-path-color "path-1" "#555555" show maps:get-path-color "path-1" ;; returns "#555555"maps:set-path-vertices "path-1" [ [ 30 60 ] [ 31 59 ] [ 39 59 ] ] show maps:get-path-vertices "path-1" ;; returns [ [ 30 60 ] [ 31 59 ] [ 39 59 ] ] 
OBJECTS (Including Markers and Paths)
set  new-object maps:get-object  "path-1" ;; returns a list with a name and definitionmaps:create-object  new-object set  new-objectsmaps:get-objects ;; returns list of names and definitions of objects, in order of creation maps:create-objects  new-objects maps:delete-object  "path-1" maps:delete-objects 
show maps:object-exists  "path-1"  ;; returns booleanmaps:hide-object  "path-1" maps:show-object  "path-1"   
TRANSLATION between Patch Coordinates and Latitude / Latitude
✓ show maps:latlng-to-patch [ 30 -97 ] ;; returns latitude and longitudeshow maps:patch-to-latlng [ 0 0 ] ;; returns patch coordinatesmaps:update-map ;; upon changing center or zoom of map, sync lat-lng and patch coords 

Physics Extension

Box2DWeb Library. https://github.com/hecht-software/box2dweb
Documentation. https://github.com/hecht-software/box2dweb
Physics UI https://remmler.org/gbcc/v3/video.html

NetLogo/Physics Example: Import a world with friction, gravity, wrapping, linear impulses and angular impulses. The world can contain moving shapes, static shapes, joints and targets, any of which can be represented by turtles.

Objects in a Box2D Physics World


A line has two endpoints and is a member of a body.
A line has friction, density and restitution.
A line can be defined with an absolute position, or with a position relative to a body.

A circle has a center and a radius and is a member of a body.
A circle has friction, density and restitution.
A circle can be defined with an absolute position, or with a position relative to a body.

A polygon has vertices and is a member of a body.
A polygon has friction, density and restitution.
A polygon can be defined with an absolute position, or with a position relative to a body.

A body can be comprised of shapes such as lines, circles and polygons.
A body can be rotated around it's center.
A body has linear and angular velocity.
A body is defined with an absolute position.
Bodies can be dynamic (move and collide) or be static (only collide) or be a ghosts (only move).

A target is a location on a body, to which forces can be applied.

Physics Extension

  extensions [ physics ]
WORLD
physics:show-worldphysics:hide-worldgraph:show-toolbargraph:hide-toolbar 
physics:bring-to-front
physics:send-to-back
physics:set-world-offset [ left top width height ] 
show physics:get-world-offset ;; returns [ left top width height ] 
physics:set-opacity 0.5 
show physics:get-opacity ;; returns any number between 0 and 1 
physics:set-all "long-string-of-json" show physics:get-all ;; returns "long-string-of-json" 
physics:reset-ticksphysics:tick 
✓ <show physics:get-tick ;; returns list of collisions since last tickphysics:repaint 
;; WORLD SETTINGS
✓ physics:set-gravity-xy [ false true ]show physics:get-gravity-xy  ;; returns [ false true ]physics:set-wrap-xy [ true true ] ;; show physics:get-wrap-xy  ;; returns [ true true ]


;; LINES

;; CIRCLES

;; RECTANGLES
 
;; POLYGONS
 
;; SHAPES
   
;; BODIES

;; TARGETS

;; OBJECTS
   
;; SHAPES AND BODIES
   
;; APPLY FORCE AT TARGET
✓ physics:apply-force "target-1" 10 180 ;; applies with force of 10 and angle of 180 degreesphysics:apply-force-relative-angle "target-1" 10 20 ;; applies with force of 10 and relative angle of 20 degreesphysics:apply-linear-impulse "target-1" 10 180 ;; applies with force of 10 and angle of 180 degrees physics:apply-linear-impulse-relative-angle "target-1" 10 20 ;; applies with force of 10 and relative angle of 20 degrees physics:apply-torque "target-1" 10  ;; applies with force of 10 physics:apply-angular-impulse "target-1" 10 ;; applies with force of 10
  
  ;; Connections between Turtles and Objects
✓ physics:connect-who-to-object who object-idshow physics:get-connected;; get list of pairs of turtle ids to object ids physics:disconnect-who who 

Ideas

Image Extension

Image Extension

extensions [ image ]

Commands

image:clear

image:import-file "cats.png";; imports an image file, local to the app