AndreA
AndreA

Reputation: 789

Netlogo - Id like to set the size of a turtle as the size of the patch it's standing on

Id like to set the size of a turtle as the size of the patch it's standing on. Even better I need turtles which are bigger as 4 or 16 patches.

If for example i have a squared world with 16x16 patches id like to have turtles that can be big 1x1 or 2x2 or 4x4 etc.... and the turtle should overlap perfectly the patches: it might be 1 patch (1x1 case), 4 (2x2 case) etc...

abott setting the size of the turtle equal to the sie of the patch for perfect overlapping in trying wit this code:

 hatch-turtle 1 [set size [size] of patch-here ]

but it gives me the error:

A patch can't access a turtle variable without specifying which turtle.

Upvotes: 3

Views: 3902

Answers (3)

Saeed
Saeed

Reputation: 121

This answer comes years after the question was asked, but I leave it here hoping that it helps others who may encounter the same problem (as I did). Below I first clarify the problem and then offer a solution.

Clarification: It is implied by the problem that OP has defined a square shape for the turtles. The default size of square turtles in NetLogo is 1, which means that by default a square turtle should completely fill a patch. However, OP still observed blank space between square turtles that are placed next to each other. The aim of this answer is to remove that blank space for square turtles of size 1.

Solution: To solve this problem, note that the default square shape of turtles in NetLogo is made up of a colored inner area and a thick colorless border. The blank space that the OP observed between the turtles was in fact composed of the colorless borders of square shapes. In order to produce a figure with colored squares placed immediately adjacent to each other (that is, without any apparent space between them), it suffices to define a new square shape with no border. This new square shape should be defined such that the inner area of the square fills the entire patch. This can be done using the Turtle Shapes Editor from the Tools menu: find the square shape, create a duplicate of it, and modify the new shape in the graphical editor. To modify the shape, click on its top-left corner and drag that corner to the top-left corner of the graphical editor window. Then do the same with the bottom-right corner.

Upvotes: 0

Seth Tisue
Seth Tisue

Reputation: 30453

Maybe try some variation of:

ask turtles [ set size patch-size ]

perhaps scaling by a multiplier as needed. Note that size is a per-turtle variable, but patch-size is a global reporter, because all patches are always the same size in pixels.

Note that size is measured in patches, while patch-size is measured in pixels.

I really don't understand at all what you're trying to do here, but the above is legal NetLogo code, anyway.

Upvotes: 4

Seth Tisue
Seth Tisue

Reputation: 30453

A turtle's size is measured in units of patches, so if you want your turtles to be the same size as the patches they are standing on, that's:

ask turtles [ set size 1 ]

but 1 is the default size, so in order to get this behavior, you actually don't need to do anything at all.

Upvotes: 1

Related Questions