Skip to content

Commit

Permalink
example/demo.f90 and example/demo_reverse.f90: changed the discrete c…
Browse files Browse the repository at this point in the history
…olormap with a red cabbage vs. pH colormap
  • Loading branch information
vmagnin committed Mar 1, 2024
1 parent c99c91f commit f579ce1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ All notable changes to the gtk-fortran project are documented in this file. The
* A link toward the page *ForColormap Collection Categories* was added in the `README.md` to help users choose a colormap.
* A GitHub workflow for the CMake build by @jchristopherson.
* CMake support by @jchristopherson.
* A `logo` directory with SVG files by @aslozada.
* A `logo` directory with SVG files by @alozada.
* A `black_body` colormap (`miscellaneous_colormaps` module).
* An `extract()` type-bound procedure to the Colormap type to extract colors from a colormap. The extracted number should be within the range [2, levels].
* `example/extract.f90`
Expand All @@ -37,6 +37,7 @@ All notable changes to the gtk-fortran project are documented in this file. The
* A `colorbar()` type-bound procedure to write a PPM file with the colorbar.

### Changed
* In `example/demo.f90` and `example/demo_reverse.f90`, the discrete colormap created from an array is now a colormap designed by @alozada resembling the color changes in red cabbage (containing Anthocyanins) with pH.
* Subroutine `test_colormap()`: the `encoding` argument is now optional (binary by default).
* The colormap `inverted_rainbow` was renamed `inv_rainbow`.
* `TODO.md` was refactored and renamed `ROADMAP.md`.
Expand Down
35 changes: 20 additions & 15 deletions example/demo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
! SOFTWARE.
!-------------------------------------------------------------------------------
! Contributed by vmagnin: 2023-09-26
! Last modification: gha3mi 2024-01-28, vmagnin 2024-02-22
! Last modification: gha3mi 2024-01-28, vmagnin 2024-03-01
!-------------------------------------------------------------------------------

!> This example will create colorbar files for each available colormap and
!> the corresponding test images. It also demonstrates how you can create your
!> own colormap defined in an array, or import it from a text file.
program demo
use forcolormap, only: Colormap, colormaps_list, wp
use forcolormap_utils, only: test_colormap
Expand All @@ -32,17 +35,24 @@ program demo
integer :: i
type(Colormap) :: cmap, custom_cmap
integer, allocatable :: colors(:,:)
! A discrete colormap with 8 levels, from black to white:

!> A discrete colormap with 8 levels, by @alozada, resembling the color
!> changes in red cabbage (containing Anthocyanins) with pH:
integer, dimension(0:7, 3) :: my_colormap = reshape( [ &
0, 0, 0, &
255, 0, 0, &
0, 255, 0, &
0, 0, 255, &
255, 255, 0, &
0, 255, 255, &
255, 0, 255, &
255, 255, 255 ], &
198, 29, 32, &
189, 21, 56, &
171, 82, 150, &
102, 81, 156, &
38, 53, 108, &
5, 65, 40, &
221, 199, 44, &
237, 191, 44 ], &
shape(my_colormap), order = [2, 1] )
!> You can create your own colormap using that array. The name of your
!> colormap must conform to the max length defined in colormap_parameters.f90
call custom_cmap%create('red_cabbage', 0.0_wp, 2.0_wp, my_colormap)
call custom_cmap%colorbar('red_cabbage_colorbar')
call test_colormap(custom_cmap, 'red_cabbage_test')

!> We create PPM files (binary encoded by default) for each built-in colormap.
!> The built-in z=f(x,y) test function is in the [0, 2] range:
Expand All @@ -59,11 +69,6 @@ program demo
call cmap%colorbar('cubehelix_customized_colorbar')
call test_colormap(cmap, 'cubehelix_customized_test')

! You can create your own colormap defined in an array:
call custom_cmap%create('discrete', 0.0_wp, 2.0_wp, my_colormap)
call custom_cmap%colorbar('discrete_colorbar')
call test_colormap(custom_cmap, 'discrete_test')

! Or you can download it from a .txt file:
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp)
call custom_cmap%colorbar('a_loaded_colorbar')
Expand Down
34 changes: 19 additions & 15 deletions example/demo_reverse.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,36 @@
! SOFTWARE.
!-------------------------------------------------------------------------------
! Contributed by vmagnin: 2023-09-26
! Last modification: gha3mi 2023-11-01, vmagnin 2024-02-22
! Last modification: gha3mi 2023-11-01, vmagnin 2024-03-01
!-------------------------------------------------------------------------------

!> This example demonstrates the use of the 'reverse' optional argument to
!> reverse the order of a colormap.
program demo_reverse
use forcolormap, only: Colormap, colormaps_list, wp
use forcolormap_utils, only: test_colormap
implicit none

integer :: i
type(Colormap) :: cmap, custom_cmap
! A discrete colormap with 8 levels, from black to white:

!> A discrete colormap with 8 levels, by @alozada, resembling the color
!> changes in red cabbage (containing Anthocyanins) with pH:
integer, dimension(0:7, 3) :: my_colormap = reshape( [ &
0, 0, 0, &
255, 0, 0, &
0, 255, 0, &
0, 0, 255, &
255, 255, 0, &
0, 255, 255, &
255, 0, 255, &
255, 255, 255 ], &
198, 29, 32, &
189, 21, 56, &
171, 82, 150, &
102, 81, 156, &
38, 53, 108, &
5, 65, 40, &
221, 199, 44, &
237, 191, 44 ], &
shape(my_colormap), order = [2, 1] )
!> You can create your own colormap using that array. The name of your
!> colormap must conform to the max length defined in colormap_parameters.f90
call custom_cmap%create('red_cabbage_reverse', 0.0_wp, 2.0_wp, my_colormap, reverse=.true.)
call custom_cmap%colorbar('red_cabbage_reverse_colorbar')
call test_colormap(custom_cmap, 'red_cabbage_reverse_test')

!> We create PPM files (binary encoded by default) for each built-in colormap.
!> The built-in z=f(x,y) test function is in the [0, 2] range:
Expand All @@ -58,11 +67,6 @@ program demo_reverse
call cmap%colorbar('cubehelix_customized_reverse_colorbar')
call test_colormap(cmap, 'cubehelix_customized_reverse_test')

! You can create your own colormap defined in an array:
call custom_cmap%create('discrete', 0.0_wp, 2.0_wp, my_colormap, reverse=.true.)
call custom_cmap%colorbar('discrete_reverse_colorbar')
call test_colormap(custom_cmap, 'discrete_reverse_test')

! Or you can download it from a .txt file:
call custom_cmap%load("test_map_to_load.txt", 0.0_wp, 2.0_wp, reverse=.true.)
call custom_cmap%colorbar('a_loaded_reverse_colorbar')
Expand Down

0 comments on commit f579ce1

Please sign in to comment.