fplot 1.7.1
A Fortran library providing a convenient interface for plotting with Gnuplot.
Loading...
Searching...
No Matches
fplot_colors.f90
1! fplot_colors.f90
2
3submodule(fplot_core) fplot_colors
4contains
5! ------------------------------------------------------------------------------
6 pure module function clr_to_hex_string(this) result(txt)
7 ! Arguments
8 class(color), intent(in) :: this
9 character(6) :: txt
10
11 ! Local Variables
12 integer(int32) :: r, g, b, clr
13
14 ! Clip each color if necessary
15 if (this%red < 0) then
16 r = 0
17 else if (this%red > 255) then
18 r = 255
19 else
20 r = this%red
21 end if
22
23 if (this%green < 0) then
24 g = 0
25 else if (this%green > 255) then
26 g = 255
27 else
28 g = this%green
29 end if
30
31 if (this%blue < 0) then
32 b = 0
33 else if (this%blue > 255) then
34 b = 255
35 else
36 b = this%blue
37 end if
38
39 ! Build the color information
40 clr = ishft(r, 16) + ishft(g, 8) + b
41
42 ! Convert the integer to a hexadecimal string
43 write(txt, '(Z6.6)') clr
44 end function
45
46! ------------------------------------------------------------------------------
47 pure module subroutine clr_copy_from(this, clr)
48 class(color), intent(inout) :: this
49 class(color), intent(in) :: clr
50 this%red = clr%red
51 this%green = clr%green
52 this%blue = clr%blue
53 end subroutine
54
55! ******************************************************************************
56! ADDED: JAN. 09, 2024 - JAC
57! ------------------------------------------------------------------------------
58 pure module subroutine clr_assign(x, y)
59 type(color), intent(out) :: x
60 class(color), intent(in) :: y
61 call x%copy_from(y)
62 end subroutine
63
64! ------------------------------------------------------------------------------
65 pure module function clr_equals(x, y) result(rst)
66 type(color), intent(in) :: x, y
67 logical :: rst
68 rst = .true.
69 if (x%red /= y%red .or. &
70 x%green /= y%green .or. &
71 x%blue /= y%blue &
72 ) then
73 rst = .false.
74 end if
75 end function
76
77! ------------------------------------------------------------------------------
78 pure module function clr_not_equals(x, y) result(rst)
79 type(color), intent(in) :: x, y
80 logical :: rst
81 rst = .not.clr_equals(x, y)
82 end function
83
84! ------------------------------------------------------------------------------
85end submodule
fplot_core