Linus Heck

Posted on December 10, 2022

ChatGPT can create cool images using TikZ

Image of a giraffe riding a bicycle as generated by ChatGPT

I discovered that you can use ChatGPT to draw images after all! You need to get it into the flow by getting it to draw some simple shapes for you, otherwise it will state that it is not made to draw images, like “Draw a rectangle using TikZ”. Then, it will happily accept other stuff, like “Draw Rudolph the red-nosed reindeer using TikZ”:

Image of rudolph the red-nosed reindeer

It can also be creative and draw artwork without any further specification:

Creative artwork

You can make it illustrate poems like “This is just to say” by William Carlos Williams:

A poem illustrated

You can combine mathematical and real stuff and make it draw “a commutative diagram on a sunny field”:

A commutative diagram on a sunny field

It can illustrate the feeling of cold morning air:

The feeling of cold morning air

I made it write a poem about a rubber duck in a fridge and illustrate it using tikz:

In the cold and dark of night,
A rubber duck sat out of sight.
Nestled in the fridge so neat,
A lonely duck without a seat.

But as the days went passing by,
The duck began to catch the eye.
A lonely duck no more, it seems,
A friend in the fridge it deems.

The fridge is now a happy place,
With a duck to keep the pace.
No longer cold and dark inside,
The fridge is now a cozy hide.

So here's to you, dear rubber duck,
A loyal friend in fridge or truck.
A symbol of our love and care,
A duck that's always there.

Illustration of the duck poem

Finally, I made it invent a character for pen-and-paper roleplaying and draw it (I added the line breaks in the description):

Illustration of the Zara the elf

TikZ code generated by ChatGPT

Giraffe on the bicycle:

\begin{tikzpicture}

% Draw the frame
\draw[fill=gray] (0,0) rectangle (2,1);

% % Draw the wheel
\draw[fill=black] (0,0) circle (0.5);
\draw[fill=black] (2,0) circle (0.5);

% Draw the tire
\draw[fill=black!10] (0,0) circle (0.4);
\draw[fill=black!10] (2,0) circle (0.4);

% Draw the spokes
\foreach \angle in {0,30,...,360} {
    \draw (0,0) -- ({0.5*cos(\angle)},{0.5*sin(\angle)});
    \draw (2,0) -- ({2.5*cos(\angle)},{0.5*sin(\angle)});
}

% Draw the pedals
\draw[fill=gray] (0,0) -- (0.2,0.1) -- (0.2,-0.1);
\draw[fill=gray] (2,0) -- (1.8,0.1) -- (1.8,-0.1);

% Draw the giraffe
\draw[fill=yellow!50] (1,1) -- (1,3) -- (1.5,3.5) -- (0.5,3.5) -- cycle;
\draw[fill=yellow!50] (1,2) -- (1.5,2.5) -- (1.5,2) -- cycle;
\draw[fill=yellow!50] (1,3) -- (1.5,3.5) -- (1.5,3) -- cycle;
\draw[fill=yellow!50] (1,3) -- (1.5,3.5) -- (2,3.5) -- (1.5,3) -- cycle;

% Draw the neck
\draw[fill=yellow!50] (1.5,3.5) -- (1.5,4) -- (1.3,4.5) -- (1.7,4.5) -- cycle;

% Draw the head
\draw[fill=yellow!50] (1.3,4.5) -- (1.7,4.5) -- (1.8,5) -- (1.2,5) -- cycle;

% Draw the eyes
\draw[fill=black] (1.2,5) circle (0.1);
\draw[fill=black] (1.8,5) circle (0.1);

% Draw the mouth
\draw[fill=black] (1.5,4.8) circle (0.1);

\end{tikzpicture}

Rudolph the red-nosed reindeer:

\begin{tikzpicture}

% Head
\draw (0,0) ellipse (1.5 and 2);

% Antlers
\draw (-2,2) -- (-1.5,1.5) -- (-1,1) -- (-0.5,0.5);
\draw (2,2) -- (1.5,1.5) -- (1,1) -- (0.5,0.5);

% Eyes
\draw (-0.75,-0.5) ellipse (0.25 and 0.5);
\draw (0.75,-0.5) ellipse (0.25 and 0.5);

% Nose
\draw (0,0) ellipse (0.5 and 0.75);
\draw (0,0) ellipse (0.25 and 0.375);

% Mouth
\draw (0,-1) ellipse (1 and 0.25);

% Body
\draw (0,-2) rectangle (3,-4);

% Legs
\draw (1,-4) -- (1.5,-5) -- (2,-5);
\draw (2,-4) -- (2.5,-5) -- (3,-5);

\end{tikzpicture}

Creative artwork:

\begin{tikzpicture}

% Set the color palette
\definecolor{c1}{RGB}{255,0,0}
\definecolor{c2}{RGB}{0,255,0}
\definecolor{c3}{RGB}{0,0,255}
\definecolor{c4}{RGB}{255,255,0}
\definecolor{c5}{RGB}{0,255,255}
\definecolor{c6}{RGB}{255,0,255}

% Draw the first row of shapes
\fill[c1] (0,0) circle (0.5);
\fill[c2] (1,0) circle (0.5);
\fill[c3] (2,0) circle (0.5);
\fill[c4] (3,0) circle (0.5);
\fill[c5] (4,0) circle (0.5);

% Draw the second row of shapes
\fill[c2] (0.5,-1) circle (0.5);
\fill[c3] (1.5,-1) circle (0.5);
\fill[c4] (2.5,-1) circle (0.5);
\fill[c5] (3.5,-1) circle (0.5);
\fill[c6] (4.5,-1) circle (0.5);

% Draw the third row of shapes
\fill[c3] (1,-2) circle (0.5);
\fill[c4] (2,-2) circle (0.5);
\fill[c5] (3,-2) circle (0.5);
\fill[c6] (4,-2) circle (0.5);
\fill[c1] (5,-2) circle (0.5);

% Draw the fourth row of shapes
\fill[c4] (1.5,-3) circle (0.5);
\fill[c5] (2.5,-3) circle (0.5);
\fill[c6] (3.5,-3) circle (0.5);
\fill[c1] (4.5,-3) circle (0.5);
\fill[c2] (5.5,-3) circle (0.5);

% Draw the fifth row of shapes
\fill[c5] (2,-4) circle (0.5);
\fill[c6] (3,-4) circle (0.5);
\fill[c1] (4,-4) circle (0.5);
\fill[c2] (5,-4) circle (0.5);
\fill[c3] (6,-4) circle (0.5);

\end{tikzpicture}

The poem “This is just to say”:

\begin{tikzpicture}

% Set the font size and style
\fontsize{16}{18}\selectfont
\sffamily

% Draw the first line of the poem
\draw (0,0) node[align=center] {This is just to say};

% Draw the second line of the poem
\draw (0,-1) node[align=center] {I have eaten};

% Draw the plate to hold the plums
\draw (0,-2) rectangle (1,-3);

% Draw the plums on the plate
\fill[purple] (0.25,-2.25) circle (0.1);
\fill[purple] (0.75,-2.25) circle (0.1);
\fill[purple] (0.25,-2.75) circle (0.1);
\fill[purple] (0.75,-2.75) circle (0.1);

% Draw the fourth line of the poem
\draw (0,-4) node[align=center] {that were in};

% Draw an icebox to represent the fifth line of the poem
\draw (0,-5) rectangle (1,-6);
\draw (0.5,-5.5) -- (0.5,-6) -- (1,-6);

% Draw the sixth line of the poem
\draw (0,-7) node[align=center] {and which};

% Draw the seventh line of the poem
\draw (0,-8) node[align=center] {you were probably};

% Draw the eighth line of the poem
\draw (0,-9) node[align=center] {saving};

% Draw the ninth line of the poem
\draw (0,-10) node[align=center] {for breakfast};

% Draw the tenth line of the poem
\draw (0,-11) node[align=center] {Forgive me};

% Draw the eleventh line of the poem
\draw (0,-12) node[align=center] {they were delicious};

% Draw the twelfth line of the poem
\draw (0,-13) node[align=center] {so sweet};

% Draw the thirteenth line of the poem
\draw (0,-14) node[align=center] {and so cold};

\end{tikzpicture}

Commutative diagram on a sunny field:

\begin{tikzpicture}

% Set the color palette
\definecolor{c1}{RGB}{255,255,0}
\definecolor{c2}{RGB}{255,128,0}
\definecolor{c3}{RGB}{0,255,0}
\definecolor{c4}{RGB}{0,0,255}
\definecolor{c5}{RGB}{255,0,0}

% Draw the sun
\fill[c1] (0,0) circle (1);
\fill[c2] (0,0) circle (0.5);

% Draw the sky
\fill[c1,c2] (0,0) rectangle (4,-4) {};

% Draw the grass
\fill[c3] (0,-4) rectangle (4,0) {};

% Draw the first object in the diagram
\draw (-1,-2) node[circle, draw=c4, fill=c4!30, minimum size=1cm] (A) {$A$};

% Draw the second object in the diagram
\draw (1,-2) node[circle, draw=c5, fill=c5!30, minimum size=1cm] (B) {$B$};

% Draw the first arrow in the diagram
\draw[->,>=stealth, shorten >=2pt, shorten <=2pt, c4] (A) to node[above] {$f$} (B);

% Draw the second arrow in the diagram
\draw[->,>=stealth, shorten >=2pt, shorten <=2pt, c5] (B) to node[below] {$g$} (A);

\end{tikzpicture}

The feeling of cold morning air:

\begin{tikzpicture}

% Set the color palette
\definecolor{c1}{RGB}{0,0,255}
\definecolor{c2}{RGB}{128,128,255}

% Draw the sky
\fill[c1,c2] (0,0) rectangle (4,-4) {};

% Draw the ground
\fill[black!20] (0,-4) rectangle (4,0) {};

% Draw the trees
\draw (-2,-1) -- (-1.5,-3) -- (-1,-1) -- cycle;
\draw (-1,-1) -- (-0.5,-3) -- (0,-1) -- cycle;
\draw (0,-1) -- (0.5,-3) -- (1,-1) -- cycle;
\draw (1,-1) -- (1.5,-3) -- (2,-1) -- cycle;

% Draw the text
\fontsize{16}{18}\selectfont
\sffamily
\draw (0,-2) node[align=center] {The cold morning air};
\draw (0,-3) node[align=center] {brings a chill to my bones};

\end{tikzpicture}

The rubber duck in the fridge poem illustrated

\begin{tikzpicture}

% Set the color palette
\definecolor{c1}{RGB}{255,255,0}
\definecolor{c2}{RGB}{255,0,0}
\definecolor{c3}{RGB}{255,128,0}

% Draw the fridge
\draw (0,0) rectangle (3,-3);
\draw (1.5,-1.5) -- (1.5,-3) -- (3,-3);

% Draw the duck
\fill[c1] (1,-1) circle (0.5);
\fill[c2] (1,-1) ellipse (0.4 and 0.2);
\draw (1,-1.4) -- (1,-1.6);

% Draw the text
\fontsize{16}{18}\selectfont
\sffamily
\draw (1,-2.25) node[align=center] {In the cold and dark of night};
\draw (1,-2.75) node[align=center] {A rubber duck sat out of sight};
\draw (1,-3.25) node[align=center] {Nestled in the fridge so neat};
\draw (1,-3.75) node[align=center] {A lonely duck without a seat};

\end{tikzpicture}

Zara the elf:

\begin{tikzpicture}

% Set the color palette
\definecolor{c1}{RGB}{0,255,0}
\definecolor{c2}{RGB}{128,255,128}
\definecolor{c3}{RGB}{255,255,0}

% Draw the character
\fill[c1] (0,0) ellipse (0.75 and 1);
\fill[c2] (0,0) ellipse (0.5 and 0.75);
\fill[c3] (0,0.5) circle (0.1);
\draw (-0.75,0) -- (0.75,0);
\draw (0,0.25) -- (0,-1);
\draw (0,-0.5) -- (0.5,-1);

% Draw the text
\fontsize{16}{18}\selectfont
\sffamily
\draw (0,-1.5) node[align=center] {Zara the Wise};
\draw (0,-2) node[align=center] {Race: Elf};
\draw (0,-2.5) node[align=center] {Class: Mage};
\draw (0,-4) node[align=center] {Appearance: Zara is a tall and slender elf,\\ with long silver hair and piercing green eyes.\\ She wears a flowing blue robe adorned with silver embroidery,\\ and carries a staff topped with a glowing crystal.};

\end{tikzpicture}