[Tex/LaTex] How to change color of TikZ node fill and text color

beamertikz-pgf

In a beamer presentation, I observed that the speaker has a TikZ diagram of a system and in the next instant, the node fill color changes (at 3:08).

I am aware that

\tikzstyle{every state}=[fill=red,draw=none,text=white]

is used to add fill color, text color to the node.

My query is: How do you change the node fill color, or text color dynamically during a beamer presentation?

Other queries on SE point to changing color of edges, using

\only<2>{\color{red}}

To begin with, I am providing a MWE of a borrowed TikZ diagram.

% Author: Till Tantau
% Source: The PGF/TikZ manual
%http://texample.net/tikz/examples/feature/automata-and-petri-nets/

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}

\begin{document}

\begin{comment}
:Title: State machine
:Tags: Manual, Automata, Graphs

Another examle from the manual.

| Author: Till Tantau
| Source: The PGF/TikZ manual

\end{comment}

 \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick]
%         \tikzstyle{every state}=[fill=red,draw=none,text=white]             
  \tikzstyle{every state}=[draw=none]

  \node[initial,state] (A)                    {$q_a$};
 \node[state]         (B) [above right of=A] {$q_b$};
 \node[state]         (D) [below right of=A] {$q_d$};
 \node[state]         (C) [below right of=B] {$q_c$};
\node[state]         (E) [below of=D]       {$q_e$};

\path (A) edge              node {0,1,L} (B)
        edge              node {1,1,R} (C)
    (B) edge [loop above] node {1,1,L} (B)
        edge              node {0,1,L} (C)
    (C) edge              node {0,1,L} (D)
        edge [bend left]  node {1,0,R} (E)
    (D) edge [loop below] node {1,1,R} (D)
        edge              node {0,1,R} (A)
    (E) edge [bend left]  node {1,0,R} (A);
\end{tikzpicture}

\end{document}

Implementing the suggestion: \only<1>{\tikzstyle{every state}=[draw=none]} \only<2->{\tikzstyle{every state}=[fill=red,draw=none,text=white]}

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usetheme{default}
\begin{document}    
\begin{frame}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node   distance=2.8cm,
 semithick]         
\tikzstyle{every state}=[draw=none]
\node[initial,state] (A)                    {$q_a$};
\node[state]         (B) [above right of=A] {$q_b$};
\node[state]         (D) [below right of=A] {$q_d$};
\node[state]         (C) [below right of=B] {$q_c$};
\node[state]         (E) [below of=D]       {$q_e$};
\only<1>{\tikzstyle{every state}=[draw=none]} \only<2->{\tikzstyle{every state}=[fill=red,draw=none,text=white]}
\path (A) edge              node {0,1,L} (B)
  edge              node {1,1,R} (C)
 (B) edge [loop above] node {1,1,L} (B)
   edge              node {0,1,L} (C)
  (C) edge              node {0,1,L} (D)
  edge [bend left]  node {1,0,R} (E)
 (D) edge [loop below] node {1,1,R} (D)
 edge              node {0,1,R} (A)
 (E) edge [bend left]  node {1,0,R} (A);
 \end{tikzpicture}
 \end{frame}
 \end{document}

Best Answer

You can achieve it with only<>.

\only<1>{\tikzset{every state/.style={draw=none}}}
\only<2->{\tikzset{every state/.style={fill=red,draw=none,text=white}}}

You have to put these lines before the node (state) placement.

enter image description here

Complete code

\documentclass[11pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usetheme{default}
\begin{document}    
\begin{frame}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]         

\only<1>{\tikzset{every state/.style={draw=none}}}
\only<2->{\tikzset{every state/.style={fill=red,draw=none,text=white}}}

\node[initial,state] (A)                {$q_a$};
\node[state]         (B) [above right of=A] {$q_b$};
\node[state]         (D) [below right of=A] {$q_d$};
\node[state]         (C) [below right of=B] {$q_c$};
\node[state]         (E) [below of=D]       {$q_e$};

\path 
  (A) edge              node {0,1,L} (B)
      edge              node {1,1,R} (C)
  (B) edge [loop above] node {1,1,L} (B) 
      edge              node {0,1,L} (C)
  (C) edge              node {0,1,L} (D)
      edge [bend left]  node {1,0,R} (E)
  (D) edge [loop below] node {1,1,R} (D)
      edge              node {0,1,R} (A)
  (E) edge [bend left]  node {1,0,R} (A);
\end{tikzpicture}
\end{frame}
\end{document}