forked from CambridgeNuclear/SCONE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CambridgeNuclear#103 from Mikolaj-A-Kowalski/colou…
…r-mat User defined colours for plotting materials
- Loading branch information
Showing
7 changed files
with
550 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module colours_test | ||
use numPrecision | ||
use colours_func, only : rgb24bit | ||
use pFUnit_mod | ||
|
||
implicit none | ||
|
||
contains | ||
|
||
|
||
@Test | ||
subroutine testColourConversions() | ||
|
||
! Test by comparison with some hex values | ||
@assertEqual(int(z"123456"), rgb24bit(18, 52, 86)) | ||
|
||
@assertEqual(int(z"000000"), rgb24bit(0, 0, 0)) | ||
@assertEqual(int(z"ffffff"), rgb24bit(255, 255, 255)) | ||
|
||
@assertEqual(int(z"ff0000"), rgb24bit(255, 0, 0)) | ||
@assertEqual(int(z"00ff00"), rgb24bit(0, 255, 0)) | ||
@assertEqual(int(z"0000ff"), rgb24bit(0, 0, 255)) | ||
|
||
end subroutine testColourConversions | ||
|
||
end module colours_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
!! | ||
!! Contains function to deal with colours | ||
!! | ||
module colours_func | ||
use numPrecision | ||
use genericProcedures, only: numToChar | ||
use errors_mod, only: fatalError | ||
implicit none | ||
|
||
public :: rgb24bit | ||
|
||
contains | ||
|
||
|
||
!! | ||
!! Return integer with 24bit colour value from r,g,b components | ||
!! | ||
!! Args: | ||
!! r [in] -> red component in [0-255] range | ||
!! g [in] -> green component in [0-255] range | ||
!! b [in] -> blue component in [0-255] range | ||
!! | ||
function rgb24bit(r, g, b) result(col) | ||
integer(shortInt), intent(in) :: r | ||
integer(shortInt), intent(in) :: g | ||
integer(shortInt), intent(in) :: b | ||
integer(shortInt) :: col | ||
character(100), parameter :: Here = "rgb24bit (colours_func.f90)" | ||
|
||
! Check that the values are in the correct range | ||
if (r < 0 .or. r > 255) then | ||
call fatalError(Here, "Red value is out of [0-255] range: " // numToChar(r)) | ||
end if | ||
if (g < 0 .or. g > 255) then | ||
call fatalError(Here, "Green value is out of [0-255] range: " // numToChar(g)) | ||
end if | ||
if (b < 0 .or. b > 255) then | ||
call fatalError(Here, "Blue value is out of [0-255] range: " // numToChar(b)) | ||
end if | ||
|
||
! Compute the 24 bit colour | ||
! Note inversion, blue is the least significant bits | ||
col = b + 256 * g + 256 * 256 * r | ||
|
||
end function rgb24bit | ||
|
||
|
||
end module colours_func |
Oops, something went wrong.