我正在尝试使用以下方法创建透明颜色的自定义调色板gnuplot:
a=127
rgb(i,a)=int(255*256**(i%3)+(i/3)*96*256**((i+1)%3)+a*256**3)
Run Code Online (Sandbox Code Playgroud)
然后我确实获得了所需的颜色:
plot x w l lc rgb rgb(0,a) lw 32, x+1 w l lc rgb rgb(1,a) lw 32
Run Code Online (Sandbox Code Playgroud)
问题,如果a等于或大于 128,则int返回一个负数,该负数不被识别为颜色。有没有办法在 gnuplot 中获得一个无符号整数?或者任何其他方式将数字理解为超出 #80000000 的十六进制?
使用运算符左移无符号<<,检查help operators binary。
另请检查:https : //stackoverflow.com/a/60257784/7295599
代码:
### 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
Run Code Online (Sandbox Code Playgroud)
结果: