Skip to content

danielvartan/colorbar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ColorBar

Project Status: Active - The project has reached a stable, usable state and is being actively developed. NetLogo Web DOI Badge FAIR Checklist Badge fair-software.eu GPLv3 License Badge Contributor Covenant 3.0 Code of Conduct Badge

Overview

ColorBar is a NetLogo model demonstrating how to create a simple color bar plot. Since NetLogo does not include a built-in color bar widget, this model provides a workaround by drawing one using temporary plot pens.

Click here to see this model online on NetLogo Web!

A NetLogo extension may be developed in the future to simplify color bar creation. For now, this model serves as a practical example.

For another color bar implementation in NetLogo, see the LogoClim model.

How It Works

The color bar can be drawn in any plot using the plot-color-bar procedure. This procedure takes the plot name as an argument and creates a random color bar with 10 different colors. The implementation can be adapted to fulfill specific requirements.

to plot-color-bar [#plot-name]
  set-current-plot #plot-name
  clear-plot
  set-plot-x-range 0 1
  set-plot-y-range 0 1

  let #pen (range 1 11)
  let #pen-length length #pen
  let #pen-interval 1 / #pen-length
  let #pen-color n-values #pen-length [random-float 100]

  let #pen-range map [
    #i -> (list ((#i - 1) / #pen-length) (#i / #pen-length))
  ] #pen

  let #line-step-size 0.01
  let #line-step 0

  (foreach #pen #pen-color #pen-range [
    [#i #j #k] ->
      create-temporary-plot-pen (word #i)
      set-plot-pen-interval #pen-interval
      set-plot-pen-color #j

      while [#line-step < 1] [
        plotxy (first #k) #line-step
        plotxy (last #k) #line-step

        set #line-step #line-step + #line-step-size
      ]

      set #line-step 0
  ])
end

How to Use It

Setup

To get started, ensure you have NetLogo installed. This model was developed using NetLogo 7.0.3, so it is recommended to use this version or later.

Downloading the Model

You can download the latest release of the model from its GitHub Releases page. For the development version, you can clone or download its GitHub repository directly.

Running the Model

Once everything is set, open the colorbar.nlogox file located in the nlogox folder to start exploring!

Refer to the Info tab in the model for additional details.

How to Contribute

Contributor Covenant 3.0 Code of Conduct Badge

Contributions are always welcome! Whether you want to report bugs, suggest new features, or help improve the code or documentation, your input makes a difference.

Before opening a new issue, please check the issues tab to see if your topic has already been reported.

License

GPLv3 License Badge

Copyright (C) 2025 Daniel Vartanian

ColorBar is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.