Class: ABM.Patches

Defined in: src/
Inherits: ABM.BreedSet


Patches is a singleton 2D matrix of Patch instances, each patch representing a 1x1 square in patch coordinates (via 2D coordinate transformations).

All the instance variables are from, set by Model.

Variables Summary

model =

The model this object belongs to. Set by Model.

patchSize =

Pixel height & width of each patch. From Model world.

isTorus =

True if coordinate system wraps around at edges. From Model world.

min =

.x & .y, minimum patch coordinate, integer. From Model world.

max =

.x & .y, maximum patch coordinate, integer. From Model world.

width =

Width of grid in patches, integer. From Model world.

height =

Height of grid in patches, integer. From Model world.

pxWidth =

Width of grid in pixels, integer. From Model world.

pxHeight =

Height of grid in pixels, integer. From Model world.

minCoordinate =

.x & .y, maximum float coordinate (calculated). From Model world.

maxCoordinate =

.x & .y, maximum float coordinate (calculated). From Model world.

Variable inherited from ABM.BreedSet


Instance Method Summary

Inherited Method Summary

Methods inherited from ABM.BreedSet

#create #push #remove #pop #reBreed .from #setDefault #exclude #draw #show #hide #inRadius #inCone #toFixed #any #empty #clear #clone #first #last #select #reject #sample #contains #removeItem #shuffle #min #max #sum #average #median #histogram #sort #uniq #flatten #concat #normalize #normalizeInt #ask #with #getProperty #setProperty #other

Constructor Details

# (void) constructor()

Constructor: super creates the empty BreedSet instance and sets the agentClass (breed) variable shared by all the Patches in this set.

Patches are created from top-left to bottom-right.

Instance Method Details

# (void) create(position)

Setup patch world from world parameters. Note that this is done as separate method so like other agentsets, patches are started up empty and filled by "create" calls.

# (void) patch(point)

Return patch at x, y float values according to topology.

# (void) coordinate(point, minPoint = @minCoordinate, maxPoint = @maxCoordinate)

Return x, y float values to be between min/max patch values using either clamp/wrap above according to isTorus topology. returns a valid world coordinate (real, not int).

# (void) clamp(point, minPoint = @minCoordinate, maxPoint = @maxCoordinate)

Return x, y float values to be between min/max patch coordinate values.

# (void) wrap(point, minPoint = @minCoordinate, maxPoint = @maxCoordinate)

Return x, y float values to be modulo min/max patch coordinate values.

# (void) isCoordinate(point, minPoint = @minCoordinate, maxPoint = @maxCoordinate)

Returns true if the points x, y float values are between min/max patch values.

# (void) isOnWorld(point)

Return true if on world or torus, false if non-torus and off-world. Because toruses wrap.

# (void) patchIndex(point)

Return the patch id/index given integer x, y in patch coordinates.

# (void) randomPoint()

Return a random valid float {x, y} point in patch space.

# (void) toBits(patch)

Convert patch measure to pixels.

# (void) fromBits(bit)

Convert bit measure to patches.

# (void) patchRectangle(patch, dx, dy, meToo = false)

Return an array of patches in a rectangle centered on the given patch patch, dx, dy units to the right/left and up/down. Exclude patch unless meToo is true, default false.

Will contain no duplicates if torus and larger than the world.

# (void) patchRectangleNullPadded(patch, dx, dy, meToo = false)

# (void) importDrawing(imageSrc, f)

Draws, or "imports" an image URL into the drawing layer. The image is scaled to fit the drawing layer.

This is an async load, see this new Image() tutorial. We draw the image into the drawing layer as soon as the onload callback executes.

# (void) installDrawing(image, context = @model)

Direct install image into the given context, not async.

# (void) pixelByteIndex(patch)

Utility function for pixel manipulation. Given a patch, returns the native canvas index i into the pixel data.

The top-left order simplifies finding pixels in data sets.

# (void) pixelWordIndex(patch)

# (void) pixelXYtoPatchXY(x, y)

Convert pixel location (top/left offset i.e. mouse) to patch coordinates (float).

# (void) patchXYtoPixelXY(x, y)

TODO refactor Convert patch coordinates (float) to pixel location (top/left offset i.e. mouse).

# (void) drawScaledPixels(context)

Draw the patches via pixel manipulation rather than 2D drawRect. See Mozilla pixel manipulation article

# (void) drawScaledPixels8(context)

The 8-bit version for drawScaledPixels. Used for systems w/o typed arrays.

# (void) drawScaledPixels32(context)

The 32-bit version of drawScaledPixels, with both little and big endian hardware.

# (void) diffuse(variable, rate, color)

Diffuse the value of patch variable patch.variable by distributing rate percent of each patch's value of variable to its neighbors. If a color color is given, scale the patch's color to be patch.variable of color. If the patch has less than 8 neighbors, return the extra to the patch.

# (void) usePixels(drawWithPixels = true)

Draw patches using scaled image of colors. Note anti-aliasing may occur if browser does not support smoothing flags.

# (void) setPixels()

Setup pixels used for drawScaledPixels and importColors.

# (void) draw(context)

Draw patches. Three cases:

  • Pixels: use pixel manipulation rather than canvas draws
  • Monochrome: just fill canvas w/ patch default
  • Otherwise: just draw each patch individually

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: