un celebre disegno

  • Creatore
    Topic
  • #86683
    claudio
    Partecipante
      Up
      0
      Down
      ::


      cerco di riprodurre un famoso disegno sull’integrazione esclusione inclusione
      ecco il risultato
      `
      \usetikzlibrary{shadows}
      \begin{tikzpicture}
      \tikzstyle{bianco_circle} = [ shape=circle, minimum size=4cm, draw=black]
      \tikzstyle{_circle} = [ shape=circle, minimum size=2cm, draw=black]
      \tikzstyle{green_circle} = [ shape=circle, minimum size=0.1cm, draw=black,bottom color=green!80]
      \tikzstyle{red_circle} = [ shape=circle, minimum size=0.1cm, draw=black,bottom color=red!80]
      \tikzstyle{blue_circle} = [ shape=circle, minimum size=0.1cm, draw=black,bottom color=blue!80]
      \node at (0,0) [bianco_circle,label=SEGREGAZIONE] {};
      \node at (-5,0) [bianco_circle,label=ESCLUSIONE] {};
      \node at (5,0) [bianco_circle,label=INTEGRAZIONE] {};
      \node at (0,5) [bianco_circle,label=INCLUSIONE] {};
      \node [_circle] at (5.5,-0.5) {};
      \node [_circle] at (2,-2.5) {};
      %inclusione
      \node [green_circle] at (0,6) {};
      \node [green_circle] at (1,6) {};
      \node [green_circle] at (1,5) {};
      \node [green_circle] at (1,4) {};
      \node [green_circle] at (0,4) {};
      \node [green_circle] at (-1,5) {};
      \node [green_circle] at (-1,6) {};
      \node [green_circle] at (-1,4) {};
      \node [green_circle] at (-1,5) {};
      \node [green_circle] at (0,5) {};
      \node [green_circle] at (-0.5,6.5) {};
      \node [green_circle] at (0.5,6.5) {};
      \node [red_circle] at (-0.5,5.5) {};
      \node [red_circle] at (0.5,5.5) {};
      \node [red_circle] at (-1.5,6) {};
      \node [red_circle] at (-0.5,4.5) {};
      \node [blue_circle] at (1.5,5.5) {};
      \node [blue_circle] at (0.5,4.5) {};
      \node [blue_circle] at (-1.5,5.5) {};
      \node [blue_circle] at (-1.5,4.5) {};
      \node [blue_circle] at (-0.5,3.5) {};
      \node [blue_circle] at (1.5,4.5) {};
      \node [blue_circle] at (0.5,3.5) {};
      \node [blue_circle] at (0,5.5) {};
      \node [blue_circle] at (-1.5,5) {};
      \node [blue_circle] at (-1,5.5) {};
      \node [green_circle] at (0,4.5) {};
      \node [red_circle] at (0.5,4) {};
      \node [red_circle] at (0,3.5) {};
      \node [red_circle] at (1.5,5) {};
      \node [red_circle] at (1,5.5) {};

      %esclusione

      \node [green_circle] at (-5.5,1.5) {};
      \node [green_circle] at (-5,1.5) {};
      \node [green_circle] at (-5,1) {};
      \node [green_circle] at (-4.5,0.5) {};
      \node [green_circle] at (-4.5,1) {};
      \node [green_circle] at (-5,-0.5) {};
      \node [green_circle] at (-5.5,-0.5) {};
      \node [green_circle] at (-6,0.5) {};
      \node [green_circle] at (-6,0.5) {};
      \node [green_circle] at (-6,0) {};
      \node [green_circle] at (-4,0.5) {};
      \node [green_circle] at (-4,-0.5) {};
      \node [green_circle] at (-4,0) {};
      \node [green_circle] at (-4.5,-1.5) {};
      \node [green_circle] at (-5.5,-1) {};
      \node [green_circle] at (-5,0.5) {};
      \node [green_circle] at (-6,1.5) {};
      \node [green_circle] at (-6.5,-0.5) {};
      \node [green_circle] at (-6,-1) {};
      \node [green_circle] at (-5.5,-1.5) {};
      \node [green_circle] at (-4.5,-0.5) {};
      \node [green_circle] at (-5,-1) {};
      \node [green_circle] at (-3.5,1) {};
      \node [green_circle] at (-4.5,1.5) {};
      \node [green_circle] at (-6,1) {};
      \node [green_circle] at (-5.5,0.5) {};
      \node [green_circle] at (-4,-1) {};
      \node [green_circle] at (-3.5,0) {};
      \node [green_circle] at (-5,0) {};
      \node [red_circle] at (-3.5,2) {};
      \node [red_circle] at (-7,1.5) {};
      \node [red_circle] at (-7.2,1) {};
      \node [red_circle] at (-7.0,-0.5) {};
      \node [blue_circle] at (-7.2,0.5) {};
      \node [red_circle] at (-3,-1.5) {};
      \node [red_circle] at (-3.5,0.5) {};
      \node [red_circle] at (-3.5,-0.5) {};
      \node [red_circle] at (-6.6,-1.5) {};
      \node [red_circle] at (-5.5,-2.5) {};
      \node [red_circle] at (-4,-2) {};
      \node [red_circle] at (-3.5,-2) {};
      \node [blue_circle] at (-7,-1) {};
      \node[blue_circle] at (-6,-2) {};
      \node[blue_circle] at (-5,-2.5) {};
      \node[blue_circle] at (-3,-1) {};
      \node[blue_circle] at (-3,1.5) {};
      \node [blue_circle]at (-6.5,2) {};
      \node [green_circle] at (0,1.5) {};
      \node [green_circle] at (-0.5,1) {};
      \node [green_circle] at (-1,1) {};
      \node [green_circle] at (-1.5,0) {};
      \node [green_circle] at (-1,-0.5) {};
      \node [green_circle] at (-0.5,-1) {};
      \node [green_circle] at (1.5,-0.5) {};
      \node [green_circle] at (1,1) {};
      \node [green_circle] at (0.5,0.5) {};
      \node [green_circle] at (-0.5,0.5) {};
      \node [green_circle] at (0,-1) {};
      \node [green_circle] at (0.5,-0.5) {};
      \node [green_circle] at (0.5,-1.5) {};
      \node [green_circle] at (1,-1) {};
      \node [green_circle] at (1.5,0.5) {};
      \node [green_circle] at (1,0) {};
      \node [green_circle] at (0,1) {};
      \node [green_circle] at (0,0) {};
      \node [green_circle] at (0,-0.5) {};
      \node [green_circle] at (0,-1.5) {};
      \node [green_circle] at (-1,0) {};
      \node [red_circle] at (2,-2) {};
      \node [red_circle] at (2.5,-2) {};
      \node [red_circle] at (2.5,-2.5) {};
      \node [blue_circle] at (1.5,-2) {};
      %\node [blue_circle] at (1,-2.5) {};
      \node [blue_circle] at (2,-3) {};
      \node [blue_circle] at (2.5,-3) {};
      \node [red_circle] at (1.5,-2.5) {};
      \node [red_circle] at (1.5,-3) {};
      \node [blue_circle] at (2,-2.5) {};
      \node [green_circle] at (4,1.5) {};
      \node [green_circle] at (5,1.5) {};
      \node [green_circle] at (5.5,1) {};
      \node [green_circle] at (4.5,0.5) {};
      \node [green_circle] at (4,0.5) {};
      \node [green_circle] at (3.5,0) {};
      \node [green_circle] at (4.5,-1) {};
      \node [green_circle] at (4,-0.5) {};
      \node [green_circle] at (4,-1) {};
      \node [green_circle] at (5,-1.5) {};
      \node [green_circle] at (6.5,0.5) {};
      \node [green_circle] at (6,1) {};
      \node [green_circle] at (4.5,1) {};
      \node [green_circle] at (3.5,1) {};
      \node [red_circle] at (5.5,-0.5) {};
      \node [red_circle] at (5.5,0) {};
      \node [red_circle] at (6,-0.5) {};
      \node [blue_circle] at (5,-0.5) {};
      \node [blue_circle] at (5.5,-1) {};
      \node [blue_circle] at (6,-1) {};
      \node [red_circle] at (5,-1) {};
      \node [blue_circle] at (6,0) {};
      \end{tikzpicture}

      `
      ma non c’è qualcosa di più efficiente per realizzarlo?
      ciao
      claudio

    Visualizzazione 1 filone di risposte
    • Autore
      Risposte
      • #86684
        Up
        0
        Down
        ::


        Dalla documentazione di tikz, minimamente modificato:`
        % !TEX encoding = UTF-8

        \documentclass{book}
        \usepackage{tikz}

        \begin{document}

        \begin{pgfpicture}
        \foreach \x in {1,…,50}{
        \pgfmathrandominteger{\a}{1}{50}
        \pgfmathrandominteger{\b}{1}{50}
        \pgfpathcircle{\pgfpoint{+\a pt}{+\b pt}}{+2pt}
        \color{blue!40!white}
        \pgfsetstrokecolor{green!80!black}
        \pgfusepath{stroke, fill}
        }
        \foreach \x in {1,…,10}{
        \pgfmathrandominteger{\a}{1}{50}
        \pgfmathrandominteger{\b}{1}{50}
        \pgfpathcircle{\pgfpoint{+\a pt}{+\b pt}}{+2pt}
        \color{red!40!white}
        \pgfsetstrokecolor{red!80!black}
        \pgfusepath{stroke, fill}
        } \end{pgfpicture}

        \end{document}`

        Questo ti evita di posizionare manualmente tutti quei cerchi. In questo modo c’è qualche sovrapposizione che tuttavia, secondo me, non è poi così male, perché rende meglio l’idea di causalità che il disegno, mi pare, vuole comunicare.

        Ciao
        Ivan

      • #86685
        Up
        0
        Down
        ::


        Effettivamente c’è da diventare matti a scrivere tutto 😀

        Ivan ha avuto l’intuizione giusta, ma credo che al giorno d’oggi trovare qualcuno che si metta ad imparare PGF sia difficile: è molto più macchinoso di TikZ che è nato appunto per essere un’interfaccia più user-friendly di PGF. Una piccola pecca al codice di Ivan è che genera si cerchi casualmente distribuiti, ma non su un cerchio: definendo infatti casualmente le coordinate x e y i punti si dispongono su un quadrato/rettangolo a seconda dei massimi consentiti.

        Su TeX.SX ci sono un paio di interventi per problemi simili, ma sempre su rettangoli: qui e qui (nel secondo si tiene conto di come non far sovrapporre i cerchi).

        Qui il problema è diverso: i cerchi devono essere distribuiti su un cerchio. Quindi serve una sintassi diversa per generare un angolo e una distanza dal centro: in questo modo si può scrivere `
        \node[opzioni] at ($(inc.center)!\distanza!(inc.angolo)$){};` dove [tt]inc[/tt] è un nodo di tipo circle già esistente.

        Ecco un esempio completo: `
        \documentclass{article}
        \usepackage{tikz}
        \usetikzlibrary{calc}

        \begin{document}
        \tikzset{bianco_circle/.style={circle,minimum size=4cm, draw}}
        \tikzset{_circle/.style={circle,minimum size=2cm, draw}}
        \tikzset{green_circle/.style={circle,minimum size=0.1cm, draw,bottom color=green!80}}
        \tikzset{red_circle/.style={circle,minimum size=0.1cm, draw,bottom color=red!80}}
        \tikzset{blue_circle/.style={circle,minimum size=0.1cm, draw,bottom color=blue!80}}

        \begin{tikzpicture}
        \pgfmathsetseed{123456}
        \node (inc) at (0,5) [bianco_circle,label=INCLUSIONE] {};

        \foreach \circle in {1,…,10}{
        \pgfmathrandom{0,360}
        \pgfmathtruncatemacro\angle\pgfmathresult
        \pgfmathrnd
        \pgfmathsetmacro\distance\pgfmathresult
        \node[green_circle] at ($(inc.center)!\distance!(inc.\angle)$){};
        }

        \foreach \circle in {1,…,10}{
        \pgfmathrandom{0,360}
        \pgfmathtruncatemacro\angle\pgfmathresult
        \pgfmathrnd
        \pgfmathsetmacro\distance\pgfmathresult
        \node[red_circle] at ($(inc.center)!\distance!(inc.\angle)$){};
        }

        \foreach \circle in {1,…,10}{
        \pgfmathrandom{0,360}
        \pgfmathtruncatemacro\angle\pgfmathresult
        \pgfmathrnd
        \pgfmathsetmacro\distance\pgfmathresult
        \node[blue_circle] at ($(inc.center)!\distance!(inc.\angle)$){};
        }

        \end{tikzpicture}

        \end{document}
        `

        Dimenticavo: a parte l’uso dei cicli e numeri casuali per ridurre il numero di righe di codice, altri miglioramenti riguardano come hai scritto le opzioni. Abituati ad usare tikzset e non tikzstyle che oltre ad essere non raccomandato è più pericoloso perché è più facile da modificare: se copiando ed incollando ti scappa un solo + rischi di sovrascrivere uno stile. Con tikzset è più difficile fare questi pasticci.

        Altra cosa: non c’è motivo di specificare cose come [tt]shapes=[/tt] o [tt]=black[/tt]. Sono predefinite.

        Ciao
        Claudio

    Visualizzazione 1 filone di risposte
    • Devi essere connesso per rispondere a questo topic.

    Go to top