color Derived Type

type, public :: color


Components

Type Visibility Attributes Name Initial
integer(kind=ik), private :: b = 0_ik

rgb

integer(kind=ik), private :: c = 0_ik

cmyk

character(len=256), private :: color_name

color name

integer(kind=ik), private :: decimal = 0_ik

decimal

integer(kind=ik), private :: g = 0_ik

rgb

real(kind=rk), private :: h = 0.0_rk

hsv

character(len=7), private :: hex = '#000000'

hex

real(kind=rk), private :: hl = 0.0_rk

hsl

integer(kind=ik), private :: k = 0_ik

cmyk

integer(kind=ik), private :: m = 0_ik

cmyk

integer(kind=ik), private :: r = 0_ik

rgb

real(kind=rk), private :: s = 0.0_rk

hsv

real(kind=rk), private :: sl = 0.0_rk

hsl

real(kind=rk), private :: v = 0.0_rk

hsv

real(kind=rk), private :: vl = 0.0_rk

hsl

real(kind=rk), private :: xyz_x = 0.0_rk

xyz

real(kind=rk), private :: xyz_y = 0.0_rk

xyz

real(kind=rk), private :: xyz_z = 0.0_rk

xyz

integer(kind=ik), private :: y = 0_ik

cmyk


Type-Bound Procedures

generic, public :: assignment(=) => copy_color

  • private pure elemental subroutine copy_color(this, from)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    class(color), intent(in) :: from

procedure, public :: convert

  • private pure elemental subroutine convert(this, to)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in) :: to

procedure, public :: find_nearest

  • private pure elemental subroutine find_nearest(this, nearest_color)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    type(color), intent(out) :: nearest_color

procedure, public :: get

  • private pure elemental subroutine get(this, name, r, g, b, c, m, y, k, decimal, hex, h, s, v, hl, sl, vl, xyz_x, xyz_y, xyz_z)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(out), optional :: name
    integer(kind=ik), intent(out), optional :: r
    integer(kind=ik), intent(out), optional :: g
    integer(kind=ik), intent(out), optional :: b
    integer(kind=ik), intent(out), optional :: c
    integer(kind=ik), intent(out), optional :: m
    integer(kind=ik), intent(out), optional :: y
    integer(kind=ik), intent(out), optional :: k
    integer(kind=ik), intent(out), optional :: decimal
    character(len=7), intent(out), optional :: hex
    real(kind=rk), intent(out), optional :: h
    real(kind=rk), intent(out), optional :: s
    real(kind=rk), intent(out), optional :: v
    real(kind=rk), intent(out), optional :: hl
    real(kind=rk), intent(out), optional :: sl
    real(kind=rk), intent(out), optional :: vl
    real(kind=rk), intent(out), optional :: xyz_x
    real(kind=rk), intent(out), optional :: xyz_y
    real(kind=rk), intent(out), optional :: xyz_z

procedure, public :: get_b

  • private pure elemental function get_b(this) result(b)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

    Return Value integer(kind=ik)

procedure, public :: get_g

  • private pure elemental function get_g(this) result(g)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

    Return Value integer(kind=ik)

procedure, public :: get_r

  • private pure elemental function get_r(this) result(r)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

    Return Value integer(kind=ik)

procedure, public :: print

  • private impure elemental subroutine print(this, option)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in), optional :: option

procedure, public :: print_available_colors

  • private impure elemental subroutine print_available_colors(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this

procedure, public :: save

  • private impure elemental subroutine save(this, file_name, height, width)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in), optional :: file_name
    integer, intent(in), optional :: height
    integer, intent(in), optional :: width

procedure, public :: save_available_colors

  • private impure elemental subroutine save_available_colors(this, file_name, height, width)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in), optional :: file_name
    integer, intent(in), optional :: height
    integer, intent(in), optional :: width

procedure, public :: set

  • private pure elemental subroutine set(this, name, r, g, b, c, m, y, k, decimal, hex, h, s, v, hl, sl, vl, xyz_x, xyz_y, xyz_z, use_library)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in) :: name
    integer(kind=ik), intent(in), optional :: r
    integer(kind=ik), intent(in), optional :: g
    integer(kind=ik), intent(in), optional :: b
    integer(kind=ik), intent(in), optional :: c
    integer(kind=ik), intent(in), optional :: m
    integer(kind=ik), intent(in), optional :: y
    integer(kind=ik), intent(in), optional :: k
    integer(kind=ik), intent(in), optional :: decimal
    character(len=*), intent(in), optional :: hex
    real(kind=rk), intent(in), optional :: h
    real(kind=rk), intent(in), optional :: s
    real(kind=rk), intent(in), optional :: v
    real(kind=rk), intent(in), optional :: hl
    real(kind=rk), intent(in), optional :: sl
    real(kind=rk), intent(in), optional :: vl
    real(kind=rk), intent(in), optional :: xyz_x
    real(kind=rk), intent(in), optional :: xyz_y
    real(kind=rk), intent(in), optional :: xyz_z
    logical, intent(in), optional :: use_library

procedure, private :: copy_color

  • private pure elemental subroutine copy_color(this, from)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    class(color), intent(in) :: from

procedure, private :: get_cmyk

  • private pure elemental subroutine get_cmyk(this, c, m, y, k)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    integer(kind=ik), intent(out) :: c
    integer(kind=ik), intent(out) :: m
    integer(kind=ik), intent(out) :: y
    integer(kind=ik), intent(out) :: k

procedure, private :: get_decimal

  • private pure elemental subroutine get_decimal(this, decimal)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    integer(kind=ik), intent(out) :: decimal

procedure, private :: get_hex

  • private pure elemental subroutine get_hex(this, hex)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    character(len=*), intent(out) :: hex

procedure, private :: get_hsl

  • private pure elemental subroutine get_hsl(this, h, s, l)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    real(kind=rk), intent(out) :: h
    real(kind=rk), intent(out) :: s
    real(kind=rk), intent(out) :: l

procedure, private :: get_hsv

  • private pure elemental subroutine get_hsv(this, h, s, v)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    real(kind=rk), intent(out) :: h
    real(kind=rk), intent(out) :: s
    real(kind=rk), intent(out) :: v

procedure, private :: get_name

  • private pure elemental subroutine get_name(this, name)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    character(len=*), intent(out) :: name

procedure, private :: get_rgb

  • private pure elemental subroutine get_rgb(this, r, g, b)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    integer(kind=ik), intent(out) :: r
    integer(kind=ik), intent(out) :: g
    integer(kind=ik), intent(out) :: b

procedure, private :: get_xyz

  • private pure elemental subroutine get_xyz(this, x, y, z)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this
    real(kind=rk), intent(out) :: x
    real(kind=rk), intent(out) :: y
    real(kind=rk), intent(out) :: z

procedure, private :: print_cmyk

  • private impure elemental subroutine print_cmyk(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_decimal

  • private impure elemental subroutine print_decimal(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_hex

  • private impure elemental subroutine print_hex(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_hsl

  • private impure elemental subroutine print_hsl(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_hsv

  • private impure elemental subroutine print_hsv(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_name

  • private impure elemental subroutine print_name(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_rgb

  • private impure elemental subroutine print_rgb(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: print_xyz

  • private impure elemental subroutine print_xyz(this)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(in) :: this

procedure, private :: set_by_name

  • private pure elemental subroutine set_by_name(this, name)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in) :: name

procedure, private :: set_cmyk

  • private pure elemental subroutine set_cmyk(this, c, m, y, k)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    integer(kind=ik), intent(in) :: c
    integer(kind=ik), intent(in) :: m
    integer(kind=ik), intent(in) :: y
    integer(kind=ik), intent(in) :: k

procedure, private :: set_decimal

  • private pure elemental subroutine set_decimal(this, decimal)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    integer(kind=ik), intent(in) :: decimal

procedure, private :: set_hex

  • private pure elemental subroutine set_hex(this, hex)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in) :: hex

procedure, private :: set_hsl

  • private pure elemental subroutine set_hsl(this, h, s, l)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    real(kind=rk), intent(in) :: h
    real(kind=rk), intent(in) :: s
    real(kind=rk), intent(in) :: l

procedure, private :: set_hsv

  • private pure elemental subroutine set_hsv(this, h, s, v)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    real(kind=rk), intent(in) :: h
    real(kind=rk), intent(in) :: s
    real(kind=rk), intent(in) :: v

procedure, private :: set_name

  • private pure elemental subroutine set_name(this, name)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    character(len=*), intent(in) :: name

procedure, private :: set_rgb

  • private pure elemental subroutine set_rgb(this, r, g, b)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    integer(kind=ik), intent(in) :: r
    integer(kind=ik), intent(in) :: g
    integer(kind=ik), intent(in) :: b

procedure, private :: set_xyz

  • private pure elemental subroutine set_xyz(this, x, y, z)

    Author
    Seyed Ali Ghasemi
    License
    BSD 3-Clause

    Arguments

    Type IntentOptional Attributes Name
    class(color), intent(inout) :: this
    real(kind=rk), intent(in) :: x
    real(kind=rk), intent(in) :: y
    real(kind=rk), intent(in) :: z

Source Code

   type :: color
      integer(ik)        , private :: r=0_ik, g=0_ik, b=0_ik                   !! rgb
      integer(ik)        , private :: c=0_ik, m=0_ik, y=0_ik, k=0_ik           !! cmyk
      integer(ik)        , private :: decimal=0_ik                             !! decimal
      character(len=7)   , private :: hex='#000000'                            !! hex
      real(rk)           , private :: h=0.0_rk, s=0.0_rk, v=0.0_rk             !! hsv
      real(rk)           , private :: hl=0.0_rk, sl=0.0_rk, vl=0.0_rk          !! hsl
      real(rk)           , private :: xyz_x=0.0_rk, xyz_y=0.0_rk, xyz_z=0.0_rk !! xyz
      character(len=256) , private :: color_name                               !! color name
   contains
      procedure :: set
      procedure, private :: set_by_name
      procedure, private :: set_name
      procedure, private :: set_rgb
      procedure, private :: set_hex
      procedure, private :: set_decimal
      procedure, private :: set_cmyk
      procedure, private :: set_hsv
      procedure, private :: set_hsl
      procedure, private :: set_xyz
      procedure :: get
      procedure, private :: get_name
      procedure, private :: get_rgb
      procedure, private :: get_hex
      procedure, private :: get_decimal
      procedure, private :: get_cmyk
      procedure, private :: get_hsv
      procedure, private :: get_hsl
      procedure, private :: get_xyz
      procedure :: get_r
      procedure :: get_g
      procedure :: get_b
      procedure :: print
      procedure, private :: print_name
      procedure, private :: print_rgb
      procedure, private :: print_hex
      procedure, private :: print_decimal
      procedure, private :: print_cmyk
      procedure, private :: print_hsv
      procedure, private :: print_hsl
      procedure, private :: print_xyz
      procedure, private :: copy_color
      generic :: assignment(=) => copy_color
      procedure :: convert
      procedure :: find_nearest
      procedure :: print_available_colors
      procedure :: save
      procedure :: save_available_colors
   end type color