Label Position Example

Label Position Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

ccl 

Tagged by Modeling Commons System over 13 years ago

code example 

Tagged by Reuven M. Lerner over 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 1356 times • Downloaded 112 times • Run 0 times
Download the 'Label Position Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This example demonstrates a means of using the TIE command to make turtle labels you can position how you want them.

NetLogo always positions turtle labels the same way, in the lower right corner of the turtle's bounding box, and right justified.

You can sometimes adjust horizontal positioning of labels to your liking by using labels with space characters in them, e.g.:

  set label "     foo"
  set label "foo     "

This example demonstrates a technique that gives you even more control.

HOW IT WORKS

Instead of setting the label on our turtle directly, we make a second turtle, attach a label to it, position it how we want, and use the TIE command to attach the second turtle so when the first turtle moves, the second turtle comes with it.

We use a directed link from the first turtle to the second turtle, so the "tie" relationship is one-way, so we're free to move the label around without affecting the main turtle.

HOW TO USE IT

Press SETUP, then GO. You can adjust the BANNER-ANGLE and BANNER-DISTANCE sliders as the model runs.

NETLOGO FEATURES

Note the use of the TIE primitive.

RELATED MODELS

Halo Example

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [circles circle]
breed [banners banner]

to setup
  clear-all
  set-default-shape circles "circle"
  create-circles 20 [
    setxy random-xcor random-ycor
    set size 2 + random 5
    attach-banner who
  ]
  reset-ticks
end 

to attach-banner [x]  ;; circle procedure
  hatch-banners 1 [
    set size 0
    set label x
    create-link-from myself [
      tie
      hide-link
    ]
  ]
end 

to reposition  ;; banner procedure
  move-to one-of in-link-neighbors
  set heading banner-angle
  fd banner-distance
end 

to go
  ask circles [ fd 0.01 ]
  ask banners [ reposition ]
  tick
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 4 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 12 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 13 years ago Updated version tag Download this version
Uri Wilensky over 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 13 years ago Updated from NetLogo 5.0 Download this version

Attached files

File Type Description Last updated
Label Position Example.png preview Preview for 'Label Position Example' over 12 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.