1

I am interested in creating the following figure using TikZ, although I am really new to this "machinery".

enter image description here

Thanks to this old post, I managed to create the following

enter image description here

QUESTIONS:

  1. How can I add all these little balls inside and around the shape?
  2. How can I add the corresponding letter notation?
  3. Is there a way that the color of the boundary can be changed?

Many many thanks in advance for the time and the help!

  • 2
    Your questions refer to very basic functions of tikz: 1.
    \node[circle, fill=red] (c) at (0,0){};, 2. \node (o) at (x, y) {$\Omega$};, 3. set draw=<color> in the options. I recommend learning some basics about tikz. Furthermore, only one question per page should be asked here.
    – dexteritas Aug 30 '22 at 11:26
  • 1
    Reading the "Minimal Intro" at https://www.ctan.org/pkg/pgf already will help you, so the big manual will be less frightening, but a consulting source. Also checking the Tikz gallery might be inspiring: https://texample.net/tikz/examples/ . – MS-SPO Aug 30 '22 at 11:54
  • @dexteritas thank you very much, but I was in a kind of rush, this is why I thought to ask first here. In any case, next time I'll try to show more effort by my side. But Tikz have been always scary to me :/ – kaithkolesidou Sep 01 '22 at 16:25

1 Answers1

8

While you are waiting for some tikz-help, here is a version in Metapost making use of the two random number generators: uniformdeviate n and normaldeviate.

enter image description here

You should compile this with lualatex (or work out how to adapt it for plain MP):

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
% make some nice colours
color orange, berry, claret, pine;
orange = 1/256(252, 128, 8);
berry = 1/256(70, 122, 168);
claret = 1/256(168, 75, 68);
pine = 1/256(74, 170, 122);

% define a roughly circular boundary path boundary; boundary = for i=0 upto 7: (50 + uniformdeviate 20) * dir (45i-30) .. endfor cycle;

% and draw it with a thick pen and in orange draw boundary withpen pencircle scaled 3 withcolor orange;

% put 12 random green circles inside the boundary for i=1 upto 12: path p; p = fullcircle scaled 4 shifted (uniformdeviate 7/8)[origin, point uniformdeviate 8 of boundary]; fill p withcolor pine; draw p; endfor

% and now add n red/blue circles round the outside numeric t, n, dt; t = 0; n = 32; 2 dt = arclength boundary / n; for i=1 upto n-1: t := t + 5/4 dt + 3/2 uniformdeviate dt; numeric a; a = arctime t of boundary; path p; p = fullcircle scaled 4 shifted point a of boundary shifted 4 unitvector(direction a of boundary rotated -90); fill p withcolor if normaldeviate > 0: claret else: berry fi; draw p; endfor

% add labels, the "-30" in the definition of boundary % means that the 0 point is roughly bottom right label.ulft("$\Omega$", point 0 of boundary); label.lrt("$\Gamma$", point 0 of boundary) withcolor orange;

endfig; \end{mplibcode} \end{document}

It will (of course) give you slightly different output each time you compile it, and as I did not put in any aesthetic checking for collisions you may need to compile it several times before you get a nice looking diagram.

You can find tutorials and reference material for Metapost by following the link at the top.

Notes

  • uniformdeviate n returns a random number, uniformly distributed between 0 and n, where n is any valid MP number. The mean value returned will be roughly 1/2 n if you call it enough times.

  • normaldeviate returns a random number that is normally distributed with mean = 0 and standard deviation = 1. Roughly half the numbers returned will be negative, and very few of them will be outside the range (-3, 3).

  • The colours are defined as RGB colours. MP uses a tuple of three numbers to represent an RGB colour, and expects each of the three elements to be between 0 and 1. Any values less than 0 are clipped to 0 and any value > 1 are clipped to 1. So to represent the WebSafe colour #FF6633, you need first to make it into a decimal tuple (255, 102, 51), then reduce all the values to the range 0 to 1 instead of 0 to 255. You can do this simply by dividing the tuple by 255 like so (255, 102, 51)/255 or because MP supports fraction constants and implicit multiplication 1/255(255, 102, 51).

  • If you prefer to use regular colours defined in your Latex doc, then using another bit of luamplib magic, you can still access them in a MP graphic. So if you have (say) \definecolor{mmm}{rgb}{.6, .3, .1} in your regular LaTeX preamble, then you could use this directly inside an mplibcode environment like this:

      draw boundary withcolor \mpcolor{mmm};
    
Thruston
  • 42,268
  • Many thanks for the time and the effort! Just one quick question: How can I change the colors here? I see you define them in a way other than the usual (to me), that is \definecolor, rgb, etc...Where can I find these combinations so for instance to change the orange color? Once again thank u:) – kaithkolesidou Sep 01 '22 at 17:20
  • Look up the Metapost reference manual §6.1 for details of how to define a color variable. But I will update the notes here as well. – Thruston Sep 01 '22 at 18:10