
我想製作不透明度逐漸變化的磁碟。我希望紅色圓盤的黑線上的不透明度=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
為什麼不,在第二種方法中使用動畫:
動畫的程式碼:
\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
這是一個變體貢薩洛·梅迪納的第二種方法:
\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}