2

I am trying to create a custom palette of transparent colours with gnuplot:

a=127
rgb(i,a)=int(255*256**(i%3)+(i/3)*96*256**((i+1)%3)+a*256**3)

then I do obtain the desired colours:

plot x w l lc rgb rgb(0,a) lw 32, x+1 w l lc rgb rgb(1,a) lw 32

Problem, if a is equal or greater than 128, int returns a negative number which is then not recognized as a colour. Is there a way to get an unsigned int in gnuplot? Or any other way to get numbers understood as hex beyond #80000000 ?

Joce
  • 2,220
  • 15
  • 26

1 Answers1

5

Use the operator left shift unsigned <<, check help operators binary.

Also check this: https://stackoverflow.com/a/60257784/7295599

Code:

### create your own transparent palette
reset session

# a,r,g,b should be integers between 0 and 255 (or 0x00 and 0xff)
a = 127   # transparency
r = 0xff  # red
g = 0x00  # green
b = 0x00  # blue
myColor(a,r,g,b) = (a<<24) + (r<<16) + (g<<8) + b

# put some objects in the background to demonstrate transparency
set object 1 rect from -7,0 to -3,250 fs solid 1.0 fc rgb "green" behind
set object 2 rect from 3,0 to 7,250 fs solid 1.0 fc rgb "blue" behind

plot for [a=0:250:10] a w l lw 5 lc rgb myColor(a,r,g,b) notitle
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72