问题描述
在这里,我试图在蜘蛛/雷达图上实现雷达效果。理想情况下,我希望在给定时间后绘制的线条消失(例如,在 30 秒后,绘制的线条逐渐变透明,我正在考虑更改为顺序颜色图或绘制的线条被删除/清除),但这可能会导致问题。因此,如果绘制的线条过渡/淡入淡出透明将减少整个绘图的混乱。这是可能的,但对我来说很棘手..
set grid ls 10
set xtics axis format "" scale 0
set ytics axis format ""
set size square
set style line 9 lt 1 lw 2 pt 2 ps 2
set multiplot layout 1,2
plot 'somedata' using 1:5 t "" w lp ls 9
unset multiplot
pause 90
replot
我怎样才能在 Gnuplot 中做到这一点? 在我的阅读中,我遇到了一种叫做 Lerp/Lerping 颜色的东西,但是我没有使用 Csharp 或 Unity。
输出显示需要淡化/清除的标记。 主要区别在于,只有 1 个,而不是 9 个
example of points that need to transition/fade to transparent
解决方法
根据您的描述,我仍然不清楚您的期望是什么。所以,这里有一个我认为是“雷达效应”的例子,即淡化颜色。
它在 while 循环中设置透明颜色(选中 help while
),您可以通过按 x
停止(选中 help bind
)。
代码当然可以进一步优化,但我希望您可以根据自己的需要进行调整。
代码:
### attempt to mimic a radar screen
reset session
# create some test landscape
set xrange [-8:8]
set yrange [-8:8]
set samples 50
set isosamples 50
set contour
set cntrparam level 5
set table $Data
splot (sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))*3
unset table
unset contour
set angle degrees
Angle(dx,dy) = dx==dx && dy==dy ? dx==0 ? dy==0 ? NaN : \
abs(sgn(dy))*180-sgn(dy)*90 : dx<0 ? 180+atan(dy/dx) : \
dy<0 ? atan(dy/dx)+360 : atan(dy/dx) : NaN
r(x,y) = sqrt(x**2 + y**2)
set table $Contour
plot $Data u (Angle($1,$2)):(r($1,$2)) index 1::1
unset table
set size ratio 1
set polar
unset border
set border polar lc "green"
unset xtics
unset ytics
set format r ""
unset raxis
set rtics scale 0
set format t ""
set grid lw 2 lc "green"
set obj 1 rect from screen 0,0 to screen 1,1 fc "black" behind # black background
stop = 0
bind x "stop=1"
$Data <<EOD
45 5
0 4
123 3.5
325 3.5
EOD
unset key
set trange [0:360]
set rrange [0:8]
alpha(a,a0) = int((1-exp(-real(a)/a0))*255)<<24 # transparency "decay"
myBaseColor = 0x00ff00
myColorA(a) = myBaseColor + alpha(a,45) # decay for radar "beam"
AngleDiff(a,b) = b>a ? b-a : 360-a+b
myColorB(a,b) = myBaseColor + alpha(AngleDiff(a,b),220) # decay for data
a=90; step=5
while (!stop) {
a = a<step ? a=a+360-step : a-step
do for [i=0:180] {
set obj 100+i circle at 0,0 size 8 arc [a+i:a+i+2] fs solid noborder fc rgb myColorA(i) behind
}
plot $Data u 1:2:(myColorB(a,$1)) w p pt 7 lc rgb var,\
$Contour u 1:2:(myColorB(a,$1)) w l lc rgb var
}
### end of code
结果:(使用 ScreenToGif 从 wxt 终端截取的屏幕截图)