.png)
不透明度が徐々に変化するディスクを作成したいと考えています。赤いディスクの黒い線で不透明度を 1 に設定し、この不透明度を円に沿って両方向に徐々に下げてディスクの反対側の端でゼロにしたいと考えています。作成することは可能ですか? 可能であれば、どのように作成しますか?
この画像は次のコードで作成されました:
\documentclass[a4paper,14pt]{scrartcl}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{calc,decorations.text}
\usepgfplotslibrary{fillbetween}
\usepackage{calc}
\pgfplotsset{compat=newest}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{2pt}
\definecolor{green}{rgb}{0.0, 0.5, 0.0}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\filldraw [red,opacity=0.2] (0,0) circle(1);
\filldraw [blue] (0,0) circle (0.1);
\draw (0,0) -- (0,1);
\end{tikzpicture}
\end{preview}
\end{document}
答え1
こんな感じですか?不透明度の異なる直線を使って円を塗りつぶしました。
コード:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\radius{3cm}
\begin{tikzpicture}
\foreach \Angle in {0,0.5,...,180}
{
\draw[draw=red!30,opacity=1-(1/180)*\Angle] (0,0) -- (90+\Angle:\radius);
\draw[draw=red!30,opacity=1-(1/180)*(180-\Angle)] (0,0) -- (-90+\Angle:\radius);
}
\draw[thick] (0,0) -- (90:\radius);
\filldraw[blue] (0,0) circle [radius=4pt];
\end{tikzpicture}
\end{document}
バリエーション。不透明度の異なる円形セクターを使用して円を塗りつぶしたため、変化がよりスムーズになりました。\step を使用すると、使用する円弧の数を制御できます (= 180/\step
)。を使用する\step=5
と、例のように、結果の効果は前のオプションほどクールではありませんが、\step
1 に変更すると (円形セクターがほぼ直線になります)、クールさが回復します。
コード:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\radius{3cm}
\def\step{5}
\begin{tikzpicture}
\def\iterations{\numexpr180/\step\relax}
\foreach \Valor in {1,2,...,\numexpr\iterations-1\relax}
{
\fill[red!60,opacity=(-1/\iterations)*\Valor+1]
(0,0) -- ({90+(\Valor-0.5)*\step}:\radius)
arc [start angle=90+(\Valor-0.5)*\step,end angle=90+(\Valor+0.5)*\step,radius=\radius] -- cycle;
\fill[red!60,opacity=(-1/\iterations)*\Valor+1]
(0,0) -- ({90-(\Valor-0.5)*\step}:\radius)
arc [start angle=90-(\Valor-0.5)*\step,end angle=90-(\Valor+0.5)*\step,radius=\radius] -- cycle;
}
\filldraw[red!60,opacity=1]
(0,0) -- ({90-0.5*\step}:\radius)
arc [start angle=90-0.5*\step,end angle=90+0.5*\step,radius=\radius] -- cycle;
\draw[thick] (0,0) -- (90:\radius);
\filldraw[blue] (0,0) circle [radius=4pt];
\end{tikzpicture}
\end{document}
または、円と網掛けを使用します。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\radius{3cm}
\begin{tikzpicture}
\shade[top color=red!30,bottom color=white,middle color=red!10]
(0,0) circle [radius=3cm];
\draw[thick] (0,0) -- ++(90:\radius);
\filldraw[blue] (0,0) circle [radius=4pt];
\end{tikzpicture}
\end{document}
\step=6
では、 2 番目の方法を使用するアニメーションを見てみましょう。
アニメーションのコード:
\documentclass{beamer}
\usepackage{tikz}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
}
}
\begin{document}
\begin{frame}
\centering
\def\radius{3cm}
\def\step{6}
\begin{tikzpicture}
\def\iterations{\numexpr180/\step\relax}
\foreach \Valor [count=\xi from 3] in {1,2,...,\numexpr\iterations-1\relax}
{
\fill[red!60,opacity=(-1/\iterations)*\Valor+1,visible on=<\xi->]
(0,0) -- ({90+(\Valor-0.5)*\step}:\radius)
arc [start angle=90+(\Valor-0.5)*\step,end angle=90+(\Valor+0.5)*\step,radius=\radius] -- cycle;
\fill[red!60,opacity=(-1/\iterations)*\Valor+1,visible on=<\xi->]
(0,0) -- ({90-(\Valor-0.5)*\step}:\radius)
arc [start angle=90-(\Valor-0.5)*\step,end angle=90-(\Valor+0.5)*\step,radius=\radius] -- cycle;
}
\filldraw[red!60,opacity=1,visible on=<2->]
(0,0) -- ({90-0.5*\step}:\radius)
arc [start angle=90-0.5*\step,end angle=90+0.5*\step,radius=\radius] -- cycle;
\draw[thick] (0,0) -- (90:\radius);
\filldraw[blue] (0,0) circle [radius=4pt];
\end{tikzpicture}
\end{frame}
\end{document}
ターミナルで実行する
convert -verbose -delay 12 -loop 0 -density 300 b.pdf b.gif
答え2
これはバリエーションですゴンサロ・メディナの2番目の方法:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\radius{3cm}
\begin{tikzpicture}
\clip (0,0) circle (\radius);
\shade [inner color=white, outer color=red!30] (0,-\radius) circle (2*\radius);
\draw [thick, ] (0,0) -- ++(90:\radius);
\filldraw [blue] (0,0) circle [radius=4pt];
\end{tikzpicture}
\end{document}