TeX 단계가 아닌 PostScript 단계에서 불투명 키에 임의의 값을 할당하는 방법은 무엇입니까?

TeX 단계가 아닌 PostScript 단계에서 불투명 키에 임의의 값을 할당하는 방법은 무엇입니까?

임의의 불투명도를 갖고 싶지만 fp패키지를 사용하고 싶지 않습니다. 간단히 말해서 PostScript 표현식을 에 전달할 수 있습니까 opacity?

다음은 시간을 절약하기 위해 작동하지 않는 최소한의 예입니다.

\documentclass[pstricks,border=12pt]{standalone}
\SpecialCoor
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
    \psframe*[linecolor=gray,opacity={!Rand}](2,2)
\end{pspicture}
\end{document}

경고 !

Rand원래 동작(0과 0.5 사이의 임의의 실수 생성)에서 새로운 동작(0과 1 사이의 임의의 실수 생성)으로 암묵적으로 수정되었습니다. 을 처음 사용하는 경우 Rand좋습니다. 기존 코드에서는 코드를 업데이트할 필요가 없습니다.

답변1

매우 쉬운 방법은 인수를 포스트스크립트 코드로 사용하는 새 키를 정의하는 것입니다.

\documentclass[pstricks]{standalone}
\usepackage{multido}
\makeatletter
\define@key[psset]{pstricks}{psopacity}[1]{%
  \edef\psk@opacityalpha{#1 }%
}%
\makeatother
\begin{document}
\begin{pspicture}(5,2)
  \psset{fillstyle=solid, fillcolor=red, linestyle=none, linewidth=0pt}
  \multido{\ra=0+0.5,\rb=0.5+0.5}{11}{%
    \psframe[psopacity=Rand](\ra,0)(\rb,2)}%
\end{pspicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

불투명도를 정의하기 위해 포스트스크립트 표현식을 전달하는 방법이 있지만 PSTricks opacity옵션을 직접 사용하지는 않습니다. 대신 Ghostscript/Postscript 연산자를 .setshapealpha사용할 수 있습니다. (보다Ghostscript 추가 연산자).

여기 MWE가 있습니다

\documentclass[pstricks,border=12pt]{standalone}
\SpecialCoor
\begin{document}

\makeatletter
\def\myRandomOpacity{\pst@Verb{Rand .setshapealpha}}
\def\myResetOpacity{\pst@Verb{1.0 .setshapealpha}}
\makeatother


\begin{pspicture}[showgrid,linecolor=red,unit=4cm](-1,-1)(1,1)
  \psdot(! 0 Rand)
  \psdot(! 0 Rand)
  \myRandomOpacity
  \psframe*[linecolor=green](0,0)(1,1)%
  \myRandomOpacity
  \psframe*[linecolor=green](0,0)(1,-1)
  \myRandomOpacity
  \psframe*[linecolor=green](0,0)(-1,-1)
  \myRandomOpacity
  \psframe*[linecolor=green](0,0)(-1,1)  
  \myResetOpacity
\end{pspicture}
\end{document}

.setshapealpha또한 PSTricks에서 내부적으로 사용됩니다 . 실제로 pst-new08에서는 다음과 같이 말합니다.pstricks supports transparent colors with Ghostscript’s .setopacityalpha, .setblendmode, and .setshapealpha. These functions are not known to VTEX or Adobes Distiller. The optional argument vtex disables transparencies and distiller overrides the Ghostscript functions with the ones from the Distiller.

MWE의 결과는 다음과 같습니다.

MWE의 결과

관련 정보