From f579ce1824ce130a821da6a125d0a3039ffb8fe6 Mon Sep 17 00:00:00 2001 From: vmagnin Date: Fri, 1 Mar 2024 19:11:26 +0100 Subject: [PATCH] example/demo.f90 and example/demo_reverse.f90: changed the discrete colormap with a red cabbage vs. pH colormap --- CHANGELOG.md | 3 ++- example/demo.f90 | 35 ++++++++++++++++++++--------------- example/demo_reverse.f90 | 34 +++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 130545b..373fcf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` @@ -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`. diff --git a/example/demo.f90 b/example/demo.f90 index 872fedc..6c58794 100644 --- a/example/demo.f90 +++ b/example/demo.f90 @@ -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 @@ -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: @@ -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') diff --git a/example/demo_reverse.f90 b/example/demo_reverse.f90 index d9d61a1..b453761 100644 --- a/example/demo_reverse.f90 +++ b/example/demo_reverse.f90 @@ -21,9 +21,11 @@ ! 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 @@ -31,17 +33,24 @@ program demo_reverse 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: @@ -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')