Painting with the Mouse

Using the Program

Paint  is a very simple program to use and to create. Here's a portrait of Gumby done using Paint:

Implementing Paint

The paint button forever calls the paint procedure. Each time it is called, the pain procedure asks if the mouse is down. If so, it determines the patch selected by the mouse, then asks all patches within a radius determined by the brush width slider to color themselves a color determined by the color selector.

The clear button simply calls NetLogo's pre-defined clear-patches procedure (cp).

Choosing Colors

The input box control panel allows us to specify the type of data to be inputed:

When the user clicks on the box, NetLogo displays a grid of colors to select from:

Agents, Agent Sets, and Perception

Patches and turtles are both types of agents. Patches are stationary agents while turtles are mobile agents. The agent concept is used in philosophy to refer to people, robots, zombies, animals, or any other autonomous, goal-directed, decision-making entities.

To make decisions, an agent must gather information about other agents in its environment. Unfortunately, the "vision" of an agent is usually limited to its immediate neighborhood.

NetLogo provides many procedures for gathering information about other nearby agents:

in-radius X    ; reports the set of agents within radius X of self

neighbors      ; reports all patches adjacent to self

patch-at dx dy ; reports the patch with coordinates pxcor + dx and pycor + dy

distance other ; reports distance from self to other agent

turtles-here   ; reports all turtles on this patch

agents with [property]  ; reports the subset of agents having some property

[property] of agents    ; reports a list of values of property for some set of agents

ask agents [commands]   ; asks all agents in set to execute some commands

Example:

ask patch 0 0 [ask patches in-radius 3 with [pcolor = green] [set pcolor orange]]

Painting versus Drawing

The computer screen can be viewed as a two-dimensional array of Pixels. Each Pixel has a color that can be changed.

A painting program allows users to set the colors of individual Pixels. This is done using a virtual pen. Our program is a paint program. A "painting" is a two dimensional array of Pixels (corresponding to some subset of the screen) with individual colors set. This is also called a bitmap or raster graphics.

By contrast, a drawing program creates images out of primitive shapes such as circles, lines, and rectangles. These shapes can be sized and repositioned using the mouse. Several shapes can be grouped together to form a new shape. This is called vector graphics.

Here's a vector-graphics drawing of a car:

Input-Output

Here's the design of a typical program. Note that the user communicates with the program through the program's user interface using various input and output devices:

 

Notes:

Input Devices: mouse, keyboard

Output Devices: monitor

Input-Output Devices: modem

User Interface has controls such as buttons, sliders, choosers, etc. Controls receive input from the user.

The user interface has views such as plotters, monitors, and message boxes.

Setting Resolution

The size of a patch (in PIXELS) and the number of patches can be modified by clicking the "Settings" button on the interface tab: