NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

Download
If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".(The run link is disabled because this model uses external files.)

WHAT IS IT?

A drawing tool for NetLogo, implemented in NetLogo 2.0.
The usual tools are here: brush, line, circle, box, fill, plus a multi-level undo / redo feature.
Patch colors can be saved and loaded in a simple text format called .NIM, or in specially non-disruptive netlogo world files in .CSV format. PNG files can be saved as well.

Drawing-Tool can be used to draw initial patch color arrangements for experiments, or just for fun! It was designed for those times when using a program or algorithm to draw the initial arrangement isn't practical, or it would be easier to just draw the configuration.

HOW IT WORKS

The "setup" routine is run automatically.
Click "Drawing Tool ON" to begin.
Choose a tool and effect from the pick-lists.
Choose a brush width and brush-color.
Click in the patch area to draw.

BRUSH-WIDTH
Use to set the brush-width used by the tools. Is always odd, as the brush is always centered on a patch.

BRUSH-COLOR
Sets the color of the brush, in increments of .0001

STRENGTH - CYCLES
strength: controls the "strength" of various effects.
blend: stronger means less transparent
dapple: stronger means a wider range of shades
diffuse: stronger diffuses more
--use for any control or effect that requires a float value from 0.0 to 1.0
cycle: diffuse: repeats the diffuse function that many times
--use for any control of effect that requires an integer value

THE COLOR PALETTE

buttons: Sets the brush to the named color.
lighter,
darker: Affect the brush color (by even 0.5 increments)
pure: Sets the brush color to the "pure" color, aka the center color.
Example: If brush is 19.455 (light red),
changes it to 15.000 (red)
Note: Pure uses the Center function, so darker grays become black,
brighter grays become white, and middle grays become gray.
_0.0000: Sets the brush to the darkest shade of the current color.
Example: If brush is 117.500 (lighter violet),
changes color to 110.000 (darkest violet).
_9.9999: Sets the brush to the lightest shade of the current color

canvas: Sets the canvas color
<=brush: Makes the current brush-color the canvas color, but does not clear the canvas
clear-
canvas: Wipes the canvas with the current canvas color

THE TOOLS

Tools alter the canvas in different ways, using the current brush color and / or effect. (Except for pick-color, which just changes the brush color)
Drawing tools use the press-drag-release method:
Press and hold the mouse button to start, drag to the end, release.
Note that dragging outside the drawing frame border "releases" the mouse button!

brush: click and drag to paint
lines: draws a line with rounded endpoints using the brush-width
frames: draws a rectangular outline as thick as the brush width
boxes: draws a filled rectangle, brush width is not used
fill: fills the selected solid-color region
fill-shades: like fill, but fills through shades of the selected color.
circles: draws a filled circle
rings: draws a ring, using brush thickness
pick-color: click on the canvas to change the brush color to the
color of the selected patch
change-color: click on the canvas to change every patch with that color to the brush color

THE EFFECTS

solid: draws in the selected color
dappled: draws in random shades of the selected color
change the strength slider to adjust the range of shades
center: changes the current patch color to the pure shade of that color,
Grays are special. Darker gray becomes black and lighter gray becomes white
undapple: changes the current patch color to the pure shade of that color
darken: changes the current patch color to be slightly darker
lighten: changes the current patch color to be slightly lighter
blend: draws in the slected color, blended with the current patch color.
set the opacity with the strength slider.

SAVING AND LOADING

Save-nim: Save the patch colors, using nim 2.0 format
Load-nim: Load the patch colors, expecting nim 2.0 format
Save-csv: Save the patch colors and screen-dimentions,
using netlogo 2.0 export-world cvs format.
Load-csv: Load the patch colors and set the screen-dimentions,
using netlogo 2.0 export-world cvs format.

Save-Png: Save the graphics window as a png file
Clear-cursors: Removes the paint-tool cursor, so it does not appear in the png image.

Set-Current-Directory: Lets you set the current directory for subsequent prompts
This will NOT change the directory of the current file!

Difference between NIM and CSV
drawing-tool-2004 can write and read two formats, nim and csv. It can also write PNG files using the built-in export-graphics primitive.

NIM is a custom format that contains the image dimensions and the patch colors.
CSV is a dumbed-down netlogo export-world file, that contains patch coordinates and colors.

The main difference is that loading a csv file will change the world dimensions to match the dimensions saved in the file, just like import-world, and csv load clears the undo history.

The advantage of CSV format is that any netlogo model can load the data using import-world, with no additional coding.

The advantage of NIM is that is lets one overlay smaller images, or crop larger images. It also makes slightly smaller files.

ADDITIONAL TOOLS / EFFECTS / CONTROLS
setup: resets the drawing cursor and clears the canvas

SHIFT, FLIP, and ROTATE
~~~~~~~~~~~~~~~~~~~~~~~
shifters: shifts the patch colors in the indicated direction, by the amount of the shift slider
flip <-->: Flips the world along the center vertical axis
flip /\\/: Flips the world along the center horizontal axis
rotate: rotates the patches 90 degrees.
Caution: if the world is not square, color data in patches
outside the center square will be lost

UNDO

~~~~
undo-on?: enables or disables the undo feature
undo: removes the last change.
redo: reapplies the changes removed by undo.
clear-undo: deletes the undo-history
undo-levels: sets the maximum number of changes that can be recorded.
each change after than will cause the oldest change
to be forgotten

SPECIAL EFFECT BUTTONS

~~~~~~~~~~~~~~~~~~~~~~

You can make your own special effect buttons. These are nothing more than buttons that call netlogo procedures that do various graphics things.
You could insert you model's patch setup code, and then test it with a button here.

dapple-all: sets all patches to a random shade of their current color
breadth of shades determined by strength
0.0 = use pure color
0.5 = use mostly middle shades
1.0 = use all shades
posterize: sets all patches to their pure color.
shade-edges: sets color brightness based on number
of neighbors with same base-color
diffuse: performs diffusion at the specified strength
for the specified number of cycles
blur: blurs the patch colors together

SPECIAL PROGRAMMING NOTES

To interactively show the user the line, circle or box that will be drawn, "marker" turtles are created and destroyed. The number of marker turtles varies, depending on the screen-size. The markers can be boxes or lines.

To reduce the number of global variables, the model makes use of turtle variables and turtle inheritance when making the markers.

The flood fill functions use recursion to fill the patches.

The model makes use of a turtle's ability to directly access the variables of the patch the turtle is on: The pointer turtle performs most of the tasks, so it can directly refer to the patch color, etc.

The model uses several custom-designed turtle-shapes as the various drawing cursors.

Where there are two reporters with nearly the same name, like "blend" and "blend?" the unadorned reporter refers to the brush color, whereas the "?" reporter always requires a color argument. For example: "dappled" reports a random shade of the brush color, but "dappled? red" reports a random shade of red.

Many of the effects depend on the base-color and tint reporters.

Base-color gives the black version of the color (i.e. the even multiple of 10 for the color)

E.g. the base-color of red (15) is 10.

Tint could also be called "shade": it gives the amount above the base-color. The tint of a pure color is alway 5. The tint of black is 0, the tint of white is 9.9999.

Black, white and gray are strange cases. They all share a base color (0) and therefore, the pure color (base + 5) of all three is 5. So, undapple will always turn black and white to gray. However, center is a smarter undapple: It examines the shade of gray and turns darker gray to black (0.0), lighter gray to white (9.9999), and medium grays to gray (5.0).

Setting the size and shape every cycle caused the turtles to flicker. To avoid flicker of the cursors, the size and shape is tested first, and only set if it doesn't match.

Likewise, the x and y coordinates are set only if the mouse moves to a different patch.

**********

A note on coding style: The code style is rather inconsistant, as I went through several phases of "preferred formatting" styles during developement. Also, I am too busy / lazy and too eager to get this model out there to spend any more time on code formatting. Please forgive me, and please emulate only the best coding styles shown here, not the worst!

**********

Thanks to everyone on the NetLogo users list for your support!

COPYRIGHT & LICENSE
This work is Copyright © 2004 James P. Steiner.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

(back to the NetLogo User Community Models)