6

How can I define a scope and have multiple fading with Tkiz or something similar? What I would like to do is this:

this image

I used the svg2tkiz tool to convert the svg, but it gives me an exception and just does the paths, not the colors. Then I modified it a bit and got this:

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\definecolor{lineBlue}{RGB}{37,102,176}
\definecolor{gradientBlue}{RGB}{55,123,191}

% fading speed
% <http://tex.stackexchange.com/a/49802/20977>
\makeatletter
\tikzset{
    fading speed/.code={
        \pgfmathtruncatemacro\tikz@startshading{50-(100-#1)*0.25}
        \pgfmathtruncatemacro\tikz@endshading{50+(100-#1)*0.25}
        \pgfdeclareverticalshading[%
            tikz@axis@top,tikz@axis@middle,tikz@axis@bottom%
        ]{axis#1}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@startshading)=(tikz@axis@bottom);
            color(50bp)=(tikz@axis@middle);
            color(\tikz@endshading)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)
        }
        \tikzset{shading=axis#1}
    }
}
\makeatother

\begin{tikzpicture}[y=0.50pt,x=0.50pt,yscale=-1, inner sep=0pt, outer sep=0pt]
% path12 - Blue Circle
\path[draw=lineBlue,line width=5.152pt, color=lineBlue]
    (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390) -- cycle;

%\filldraw[gradientBlue, top color=black!20, bottom color=gradientBlue!30, middle color=gradientBlue]
\fill[black, top color=white, bottom color=gradientBlue, fading speed=50]
    (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390)
    -- cycle;

\end{tikzpicture}
\end{document}

But this code just mimics the top of the fading and the fading goes all down. I maybe need a scope that apply the complete fading effect until the middle of the image.

tikz image

2

I used the \clip command and made two "fadings", one the reverse of the other to get the desired effect.

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\definecolor{lineBlue}{RGB}{37,102,176}
\definecolor{gradientBlue}{RGB}{55,123,191}


\makeatletter
\tikzset{
    fading speed/.code={
        \pgfmathtruncatemacro\tikz@startshading{50-(100-#1)*0.25}
        \pgfmathtruncatemacro\tikz@endshading{50+(100-#1)*0.25}
        \pgfdeclareverticalshading[%
            tikz@axis@top,tikz@axis@middle,tikz@axis@bottom%
        ]{axis#1}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@startshading)=(tikz@axis@bottom);
            color(50bp)=(tikz@axis@middle);
            color(\tikz@endshading)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)
        }
        \tikzset{shading=axis#1}
    }
}
\makeatother

\begin{tikzpicture}[y=0.50pt,x=0.50pt,yscale=-1, inner sep=0pt, outer sep=0pt]
% Border
\path[draw=lineBlue,line width=5.152pt, color=lineBlue]
    (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390) -- cycle;
% Inside gradient
\begin{scope}\clip (413.2380,96.6390) .. controls
    (440.4760,161.3900) and (383.2330,247.2470) .. (285.3920,288.4050) .. controls
    (187.5490,329.5610) and (86.1460,310.4350) .. (58.9110,245.6810) .. controls
    (31.6740,180.9310) and (88.9110,95.0710) .. (186.7550,53.9140) .. controls
    (284.6020,12.7590) and (386.0060,31.8860) .. (413.2380,96.6390) -- cycle;
\fill[black, top color=white, bottom color=gradientBlue, fading speed=50] (31,12) rectangle (440,168.5);
\fill[black, top color=gradientBlue, bottom color=white, fading speed=50] (31,168.5) rectangle (440,329);
\end{scope}
\end{tikzpicture}
\end{document}

The result:

enter image description here

Note that once you give \clip a path, anything in the scope which it is inside gets clipped by that path.

I chose boundary points for the "faded" rectangles based on the maxima and minima of the x- and y-values used to define the boundary, in this case 440 and 31, and 329 and 12, respectively. Then I took the midpoint of the max y-values, namely 168.5, and used that as the midpoint of the shape. I suppose by making the rectangles taller you can have the gradient go all the way to the bottom and top of the image.

Finally, depending on what I'm viewing it with, I get a thin black line down the middle of the shape, and I'm not sure what's causing it (in Preview, but not in Acrobat). To get rid of it permanently, put something like \draw[color=gradientBlue, line width=5pt] (31,168.5)--(440,168.5); inside the scope environment, after the two rectangles.

  • Thanks! I just modified the \fill a little bit to be more similar with the real image: \fill[gradientBlue, top color=white, bottom color=gradientBlue, fading speed=55] (31,-10) rectangle (440,168.5); \fill[gradientBlue, top color=gradientBlue, bottom color=gradientBlue!55, fading speed=60] (31,168.5) rectangle (440,329); – gbc921 Apr 24 '14 at 16:42
  • Actually, this is better yet: \definecolor{gradientTopBlue}{RGB}{190,181,221} and the first fading by: \fill[gradientBlue, top color=gradientTopBlue!15, bottom color=gradientBlue, fading speed=60] (31,-20) rectangle (440,168.5); – gbc921 Apr 24 '14 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.