Raster Painter

Raster Painter preview image

1 collaborator

Default-person Garrett Love (Author)

Tags

raster 

Tagged by Garrett Love over 9 years ago

tool 

Tagged by Garrett Love over 9 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.5 • Viewed 181 times • Downloaded 16 times • Run 0 times
Download the 'Raster Painter' modelDownload this modelEmbed this model

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


Comments and Questions

Info for the model

## WHAT IS IT? This "model" is a tool for creating a raster of patch colors that can be used as initial conditions in other NetLogo models ## HOW TO USE IT Select "GREY" or "USER" from the SETUP-PALETTE chooser and click the SETUP button. The display will create two regions: a 44 selection 'palette' of colors on the left and a white bordered "canvas" on the right, either all in plain grey ("GREY") or with a default color pattern ("USER") Select a PIXEL-SIZE from the slider to establish whether edits to the canvas will be made with 1x1, 3x3, 5x5 or 7x7 block increments. Use the largest values if you wish to change the color of large areas and the smaller values for detailed changes. DRAW will initiate the process for editing the canvas. When DRAW is active, click the mouse on a patch in the 'palette' to change to the corresponding Color Value. Then click within the 'canvas' to modify the colors within. CREATE EXPORT CODE will fill the textbox with NetLogo code (";PASTE THIS CODE...") The created code can then be cut-and-paste for use in another NetLogo model To test the export code, replace the code within this model ( in the area ";;;REPLACE BELOW WITH TEST CODE") with code generated from the export text box. DRAW-CANVAS will redraw the screen with the canvas pattern centered as it would appear if exported into another code. If the program is saved ("File -&rt; Save") with the replacement code in place, the "USER" pattern from the SETUP-PALETTE chooser will correspond with whatever pattern is currently in the code. Patterns can be edited in this fashion. ## THINGS TO NOTICE CHANGES OF SCREEN SIZE The tool should be robust to most changes of screen and patch size. The canvas height and width will each be 7 patches smaller than the overall screen, and so the canvas, and perhaps portions of the palette, will be missing for smaller screens. The canvas data is reproduced from the lower left hand corner, so lower left hand data will be retained for smaller screens. For larger screens, SETUP will add additional grey space to the right and top of the screen, but DRAW-CANVAS will create a white border that centers the data. ## AUTHORSHIP Created by Garrett Love Dept. of Environmental, Earth and Geospatial Sciences North Carolina Central University Posted July 15, 2014

Posted over 9 years ago

Click to Run Model

globals [draw-color palette frame canvas canvas-width canvas-height stop-draw? canvas-on?]

to setup
  ca
  set stop-draw? false
  set canvas-on? true
  set canvas patches with
     [ (pycor <= max-pycor - 2 and pycor >= min-pycor + 6) and 
       (pxcor <= max-pxcor - 2 and pxcor >= min-pxcor + 6) ]
  ask canvas [set pcolor grey]
  if setup-palette = "USER" [
  let initmat user-colormat
  fill-canvas initmat (min-pxcor + 6) (min-pycor + 6)
  ]
  set canvas-width max-pxcor - min-pxcor - 7
  set canvas-height max-pycor - min-pycor - 7
  set frame patches with
     [ (pxcor = min-pxcor + 5 and pycor <= max-pycor - 1 and pycor >= min-pycor + 5) or 
       (pxcor = max-pxcor - 1 and pycor <= max-pycor - 1 and pycor >= min-pycor + 5) or 
       (pycor = min-pycor + 5 and pxcor <= max-pxcor - 1 and pxcor >= min-pxcor + 5) or 
       (pycor = max-pycor - 1 and pxcor <= max-pxcor - 1 and pxcor >= min-pxcor + 5)  ]
  ask frame [set pcolor white]
  set palette patches with [ pxcor >= min-pxcor + 1 and pxcor <= min-pxcor + 3 
                         and pycor >= max-pycor - 16 and pycor <= max-pycor - 1 ]       
  ask palette [set pcolor 10 * (max-pycor - pycor) + 2 * (min-pxcor + 2 - pxcor) + 5 ]
  ask palette [if pycor = (max-pycor - 15) [set pcolor black]]
  ask palette [if pycor = (max-pycor - 16) [set pcolor white]]
  ask patches [if not member? self (patch-set palette frame canvas) [set pcolor sky]] 
  set draw-color white  
  reset-ticks 
end 

to draw
  if stop-draw? [set stop-draw? false stop]
  if not canvas-on? [setup]
  if mouse-down? 
    [ let click-patch patch mouse-xcor mouse-ycor
      ifelse member? click-patch palette [set draw-color [pcolor] of click-patch] ; set palette color
      [ let paint-patches canvas with  
        [ (abs(pxcor - mouse-xcor) <= pixel-size / 2) and 
          (abs(pycor - mouse-ycor) <= pixel-size / 2) ]
        if member? click-patch canvas [ ask paint-patches [set pcolor draw-color]]
      ]
    ]
   tick
end 

to export
  set stop-draw? true
  clear-output
  output-print ";PASTE THIS CODE INTO THE NETLOGO CODE REGION"
  output-print ";AND CREATE A 'DRAW_PALETTE' BUTTON ON THE INTERFACE"
  output-print "to draw-canvas"
  output-print "  ask patches [set pcolor white]"
  output-print "  let colormat user-colormat" 
  output-print "  let xbord max list 0 (world-width - length item 1 colormat ) / 2"
  output-print "  let ybord max list 0 (world-height - length colormat ) / 2"
  output-print "  fill-canvas colormat (min-pxcor + xbord) (min-pycor + ybord)"
  output-print "end"
  output-print "to fill-canvas [matrix xstart ystart]"
  output-print "  let row 0"
  output-print "  repeat length matrix"
  output-print "  [ "
  output-print "  let col 0"
  output-print "  repeat length item 1 matrix"
  output-print "  ["
  output-print "  ask patch (xstart + col) (ystart + row)" 
  output-print " [if xstart + col <= max-pxcor and ystart + row <= max-pycor" 
  output-print "            [set pcolor item col (item row matrix)]]"
  output-print "  set col col + 1" 
  output-print "  ]"
  output-print "  set row row + 1"
  output-print "  ]"
  output-print "end"
  output-print "to-report user-colormat"
  output-print "report"     
  output-print "["
  let row 0
  repeat canvas-height
  [ let rowlist (list)
    set row row + 1
    foreach sort-on [pxcor] canvas with [pycor = min-pycor + 5 + row] [ask ? [set rowlist lput pcolor rowlist]]
    output-print rowlist
  ]
  output-print "]"
  output-print "end"
end 

;;; REPLACE BELOW WITH TEST CODE

to draw-canvas
  ask patches [set pcolor white]
  let colormat user-colormat
  let xbord max list 0 (world-width - length item 1 colormat ) / 2
  let ybord max list 0 (world-height - length colormat ) / 2
  fill-canvas colormat (min-pxcor + xbord) (min-pycor + ybord)
end 

to fill-canvas [matrix xstart ystart]
  let row 0
  repeat length matrix
  [ 
  let col 0
  repeat length item 1 matrix
  [
  ask patch (xstart + col) (ystart + row)
 [if xstart + col <= max-pxcor and ystart + row <= max-pycor
            [set pcolor item col (item row matrix)]]
  set col col + 1
  ]
  set row row + 1
  ]
end 

to-report user-colormat
report
[
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 65 65 65 65 65 65 65 65 65]
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 65 65 65 65 65 65 65 65 65]
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 65 65 65 65 65 65 65 65 65]
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 65 65 65 65 65 65 65 65 65]
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 65 65 65 65 65 65 65 65 65]
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 5 5 5 5 65 65 65 65 65]
[125 125 125 125 125 125 125 125 125 125 125 5 5 5 5 5 5 5 5 5 65 65 65 65 65]
[125 125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 65 65 65 65 65]
[125 125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 65 65 65 65 65]
[125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 65 65 65 65 65]
[125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 65 65 65 65 65]
[125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5]
[125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5]
[125 125 125 125 125 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5]
[125 125 125 125 125 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 5 5 5]
[5 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 5 5 5]
[5 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 5 5 5]
[5 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 5 5 5]
[5 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 5 5 5]
[5 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 45 45 45]
[15 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 45 45 45]
[15 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 45 45 45]
[15 5 5 5 5 5 5 5 5 103 103 103 103 103 103 103 5 5 5 5 5 5 45 45 45]
[15 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 45 45 45 45 45]
[15 15 15 15 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 45 45 45 45 45]
]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Garrett Love over 9 years ago Confirming initial upload Download this version
Garrett Love over 9 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Raster Painter.png preview Preview for 'Raster Painter' over 9 years ago, by Garrett Love Download

This model does not have any ancestors.

This model does not have any descendants.