在 TikZ 中画一只独角兽

在 TikZ 中画一只独角兽

我目前正在阅读通用人工智能的火花:GPT-4 的早期实验这篇由微软员工撰写的论文实验了 ChatGPT 的后继者 GPT-4 的功能。其中一项任务是用 tikz 画一只独角兽。ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

他们声称:

GPT-4 产生的输出令人印象深刻,其输出至少与人类的输出相当(如果不是更胜一筹的话)。

谁想证明他们错了?

答案1

\documentclass{standalone}
\usepackage{tikzducks}
\usepackage{pgf-spectra}
\pgfspectrashade[v](380,780){myShadeC}

\begin{document}
    
\begin{tikzpicture}[shading=myShadeC]
 \duck[body=pink]
 \shade[shading angle=45] \duckpathlonghair;
 \duck[invisible,body=pink,unicorn=magenta!60!violet]
\end{tikzpicture}
    
\end{document}

在此处输入图片描述

答案2

好吧,参加聚会有点晚了,但是女士们先生们,让我向你们介绍我的独角兽 Clavileño,这些年来我忠实的伙伴:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d,perspective}

\colorlet{brownxy}{brown!40!red}
\colorlet{brownxz}{brown!65!red}
\colorlet{brownyz}{brown!90!red}

\tikzset
{%
   declare function={
     rh=4*(1-cos(30)); % runner height
     },
   xy/.style={canvas is xy plane at z=#1},
   xz/.style={canvas is xz plane at y=#1},
   yz/.style={canvas is yz plane at x=#1},
   pics/runner/.style={
     code={%
       \draw[xz=0 ,fill=brownxz] (0,4) ++ (240:4) arc (240:300:4) -- cycle;
       \draw[xy=rh,fill=brownxy] (2,0) rectangle (-2,-0.2);
      }},
   pics/leg/.style={
     code={%
       \path[xz=0]                 (0,0) --++ (0,1.5) arc (0:135:0.15) coordinate (aux) ;
       \draw[xz=-0.4,fill=brownyz] (0,0) --++ (0,1.5) arc (0:135:0.15) -- (aux) arc (135:0:0.15) --++ (0,-1.5) -- cycle;
       \draw[xz=0,fill=brownxz]    (0,0) --++ (0,1.5) arc (0:180:0.15) |- cycle;
       \fill[fill opacity=0.5]   (0,0,0) --++ (-0.3,0,0) --++ (0,0,0.2) --++ (0.3,0,0) --++ (0,-0.4,0) --++ (0,0,-0.2) -- cycle;
       \draw (0,-0.2,0) --++ (0,0,0.2);
       \foreach\i in {-0.1,-0.2}
         \fill[xz=0,black] (\i,1.5) circle (0.2mm);
     }},
   pics/body/.style={
     code={%
       \draw[xz=0,pic actions] (-1.3,1.5) coordinate (-A) --++ (2.6,0)       coordinate (-B) --++
                               (70:1.2)   coordinate (-C) arc  (160:60:0.2)  coordinate (-D) --++
                               (-30:0.6)  coordinate (-E) arc  (240:390:0.3) coordinate (-F) --++
                               (120:1.2)  coordinate (-G) arc  (30:140:0.5)  coordinate (-H) --++
                               (230:1.5)  coordinate (-I) arc  (-40:-90:0.2) coordinate (-J) --++
                               (-1.9,0)   coordinate (-K) |- cycle;
       % mouth
       \fill[xz,black,fill opacity=0.5] (-E) ++ (60:0.3) coordinate (aux) circle (0.3);
       \draw[xz]               (aux) --++ (10:0.3);
       % eye
       \fill[xz=0,black]       (2.1,3.5) circle (0.1);
     }},
   pics/ear/.style={
     code={%
       \draw[xz=0,rotate=-15,pic actions] (0,0) -- (240:0.4) arc (150:390:0.2) -- cycle;
     }},
}


\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,isometric view,rotate around z=180]
% runners
\pic at (0,-0.8,0) {runner};
\foreach\i in {1.3,-1}
{
  \draw[xy=rh,fill=brownxy] (\i,0.8) rectangle++ (-0.3,-1.6);
  \draw[yz=\i,fill=brownyz] (0.8,rh) rectangle++ (-1.6,-0.2);
}
\pic at (0,1,0) {runner};
\node[xz=1,anchor=south,yshift=.5mm,xscale=-1,fill=none,text=yellow] at (0,0) {\bfseries Clavileño};
\foreach\i in {1.1,1.2,-1.1,-1.2}
  \fill[xz=1,fill=black] (\i,rh-0.1) circle (0.2mm);
% legs
\pic at (1.3,-0.4,rh) {leg};
\pic at (-1 ,-0.4,rh) {leg};
% body coordinates
\pic[fill=none,draw=none] (back)  at (0,-0.4,0) {body};
\pic[fill=none,draw=none] (front) at (0, 0.4,0) {body};
% tail
\path (front-K) -- (back-K) coordinate[pos=0.5] (aux);
\draw[xz,xscale=-1,shift={(aux)},fill=brownxz]
   (0,-0.2) to[out=10,in=180]  (0.5,0) to[out=0,in=140] (1,-2)
            to[out=200,in=270] (0.3,-0.8) arc(0:90:0.3) -- cycle;
% saddle
\draw[xy=0,fill=brownxy] (back-K) ++ (2,0) -- (back-K) -- (front-K) -| cycle;
\path (front-K) ++ (0.5,0,0) coordinate (aux1) --++ (0.1,0,0) coordinate (aux2);
\path[yz=0] (aux2) arc (0:135:0.4) coordinate (aux3);
\draw[fill=gray!70!black] (aux2) {[yz=0] arc (0:180:0.4)} {[xy=0] arc (-90:90:0.8 and 0.4)};
\draw (aux2) --++ (0,-0.8,0);
\draw[yz=0,fill=gray] (aux1) arc (0:135:0.4) -- (aux3)  arc (135:0:0.4) -- cycle;
% body and ears
\path[xz=0,fill=none] (front-G) arc (30:135:0.5)  coordinate (aux1);
\path[xz=0,fill=none] (front-F) arc (390:315:0.3) coordinate (aux2);
\path (back-B) -- (back-C) coordinate[pos=1.1]  (aux3);
\pic[fill=brown!30!orange] at (2.2,-0.4,4.4)    {ear};
\draw[fill=brown] (front-B) --++ (0,-0.8,0)  -- (aux3) --++ (0,0.8,0) -- cycle;
\draw[fill=brown!70!red] (aux1) --++ (0,-0.8,0) {[xz=0] arc (135:30:0.5) -- (back-F) arc (390:315:0.3) -- (aux2)} -- cycle;
\pic[fill=brownxz]         at (0,0.4,0)      {body};
\pic[fill=brown!30!orange] at (2.2,0.4,4.4)  {ear};
\pic[draw=none,fill=black!60!brown,scale=0.6] at (2.15,0.4,4.25) {ear};
% more legs
\pic at (1.3,0.8,rh) {leg};
\pic at (-1,0.8 ,rh) {leg};
% handle
\path[xz=0.4,draw=red] (1.4,3.5) coordinate (aux1) ++ (135:0.1) coordinate (aux2) arc (135:-45:0.1) coordinate (aux3);
\path (aux3) --++ (0,0.4,0) coordinate (aux4);
\path (aux1) --++ (0,0.4,0) coordinate (aux5);
\draw[fill=gray,xz=0.4] (aux1) circle (0.15);
\draw[fill=gray!50!black,xz=0] (aux2) arc (135:-45:.1) -- (aux4) arc (-45:135:0.1) -- cycle;
\draw[xz=0,fill=gray] (aux5) circle (0.1);
% unicorn
\path (front-F) -- (back-G) coordinate[pos=0.5] (aux);
\draw[shift={(aux)},rotate around y=60,fill=yellow] (4:0.1) arc (4:190:0.1) -- (0,0,1) -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

更新:在这里你可以看到他毫无畏惧地奔跑。 在此处输入图片描述

答案3

显然,使用 tikz 只是自动化的标志。

有眼光的艺术家使用乳胶图片模式 飞机 或者 驴子 或独角兽,也就是有角的驴子

\setlength{\unitlength}{0.00083333in}
\usepackage{epic}
\begin{document}

\begin{picture}(4974,3714)(0,-10)
\drawline(2037,1362)(1962,12)(2112,1362)
\drawline(1887,2412)(4437,2412)(4437,1437)
    (1887,1437)(837,2262)(462,1812)
    (12,2187)(687,3012)(837,3687)
    (837,3087)(1812,2412)
\drawline(1887,1437)(1512,12)(1962,1437)
\put(687,2637){\circle{150}}
\drawline(4362,1437)(4287,162)(4287,1437)
\drawline(4137,1437)(3987,162)(3987,1437)
\drawline(4437,2412)(4962,1587)
\drawline(580,2900)(-200,3300)(660,3010)
\end{picture}

\end{document}

在此处输入图片描述

答案4

MS-SPO 合并好主意较早的答案我的:

\documentclass[border=10Mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

% Original Image: Hszone/Wirestock Creators / stock.adobe.com
% https://stock.adobe.com/de/images/unicorn-pixel-art-vector/501392488
\begin{filecontents}{image.dat} 
.2 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  .2 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  .2 .2 0  0  0  0  0  0  0  0  0  .5 0  0  0  0  0  0  0  0  0  0  0  0 
0  0  .2 .2 .2 0  0  0  0  0  0  .5 0  .5 0  0  0  0  0  0  0  0  0  0  0 
0  0  .2 .2 .2 .2 0  0  0  0  0  .5 0  .5 0  0  0  0  0  0  0  0  0  0  0 
0  0  0  .2 .2 .2 .2 .8 .8 .8 .8 0  0  0  .8 .8 .8 .8 0  0  0  0  0  0  0
0  0  0  0  .2 .8 .8 .8 .8 .8 .8 0  0  .8 .8 .8 .8 .8 .8 .8 0  0  0  0  0
0  0  0  0  0  .8 .8 .8 0  0  0  0  0  .8 .8 .8 .8 .8 .8 .8 .8  0 0  0  0
0  0  .8 0  .8 .8 .8 0  0  0  0  0  0  0  .8 .8 .8 .8 .8 .8 .8 .8 0  0  0
0  0  0  .8 .8 0  0  0  0  0  0  0  0  0  0  .6 .6 .6 .8 .8 .8 .8 .8 0  0
0  0  0  0  .5 0  0  0  0  0  0  0  0  0  0  0  .6 .6 .6 .6 .8 .8 .8 0  0
0  0  0  .5 0  0  0  1  0  0  0  0  0  0  0  0  0  .4 .6 .6 .6 .8 .8 .8 0
0  0  .5 0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .6 .6 .6 .8 .8 .8 .8
0  .5 0  0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  0  0  0  0  0  0  0  0  0  0  .5 0  0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  .5 0  0  0  0  0  .5 .5 .5 .5 0  0  0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  0  0  0  0  .5 .5 0  .5 0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 .8 .8 .8
0  .5 .5 .5 .5 .5 0  0  0  0  .5 0  0  0  0  .4 .4 .4 .6 .6 .6 .6 .8 .8 .8
0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .4 .4 .4 .6 .6 .6 .6 .8 .8 .8
0  0  0  0  0  0  0  0  0  0  .5 0  .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0
0  0  0  0  0  0  0  0  0  0  .5 .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0
0  0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 .8 0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 .8 0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 .6 .6 .6 .8 .8 0  0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 0  0  .8 0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 0  0  0  .8 0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  .4 .4 .6 .6 0  0  0  0  .8 0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  .6 .6 0  0  0  0  0  0  0  0  0  0  0
\end{filecontents}

\pgfplotstableread{image.dat}{\pixeldata}

\begin{document}
\begin{tikzpicture}

\pgfplotstablegetcolsof{\pixeldata}
\pgfmathsetmacro{\datacols}{\pgfplotsretval-1}
\pgfplotstablegetrowsof{\pixeldata}
\pgfmathsetmacro{\datarows}{\pgfplotsretval-1}
\foreach \i in {0,...,\datarows} {
    \foreach \j in {0,...,\datacols} {
        \pgfplotstablegetelem{\i}{\j}\of{\pixeldata}
        \pgfmathsetmacro{\pixelvalue}{\pgfplotsretval*100}
        \fill[black!\pixelvalue] (\j,-\i) rectangle +(1,1);
    }
}
\end{tikzpicture}
\end{document}

在此处输入图片描述


让我们添加一些塞巴斯蒂亚诺的回答至此:

\documentclass[border=10Mm]{standalone}
\usepackage{emoji}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

% Original Image: Hszone/Wirestock Creators / stock.adobe.com
% https://stock.adobe.com/de/images/unicorn-pixel-art-vector/501392488
\begin{filecontents}{image.dat} 
.2 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  .2 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  .2 .2 0  0  0  0  0  0  0  0  0  .5 0  0  0  0  0  0  0  0  0  0  0  0 
0  0  .2 .2 .2 0  0  0  0  0  0  .5 0  .5 0  0  0  0  0  0  0  0  0  0  0 
0  0  .2 .2 .2 .2 0  0  0  0  0  .5 0  .5 0  0  0  0  0  0  0  0  0  0  0 
0  0  0  .2 .2 .2 .2 .8 .8 .8 .8 0  0  0  .8 .8 .8 .8 0  0  0  0  0  0  0
0  0  0  0  .2 .8 .8 .8 .8 .8 .8 0  0  .8 .8 .8 .8 .8 .8 .8 0  0  0  0  0
0  0  0  0  0  .8 .8 .8 0  0  0  0  0  .8 .8 .8 .8 .8 .8 .8 .8  0 0  0  0
0  0  .8 0  .8 .8 .8 0  0  0  0  0  0  0  .8 .8 .8 .8 .8 .8 .8 .8 0  0  0
0  0  0  .8 .8 0  0  0  0  0  0  0  0  0  0  .6 .6 .6 .8 .8 .8 .8 .8 0  0
0  0  0  0  .5 0  0  0  0  0  0  0  0  0  0  0  .6 .6 .6 .6 .8 .8 .8 0  0
0  0  0  .5 0  0  0  1  0  0  0  0  0  0  0  0  0  .4 .6 .6 .6 .8 .8 .8 0
0  0  .5 0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .6 .6 .6 .8 .8 .8 .8
0  .5 0  0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  0  0  0  0  0  0  0  0  0  0  .5 0  0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  .5 0  0  0  0  0  .5 .5 .5 .5 0  0  0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  0  0  0  0  .5 .5 0  .5 0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 .8 .8 .8
0  .5 .5 .5 .5 .5 0  0  0  0  .5 0  0  0  0  .4 .4 .4 .6 .6 .6 .6 .8 .8 .8
0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .4 .4 .4 .6 .6 .6 .6 .8 .8 .8
0  0  0  0  0  0  0  0  0  0  .5 0  .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0
0  0  0  0  0  0  0  0  0  0  .5 .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0
0  0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 .8 0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 .8 0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 .6 .6 .6 .8 .8 0  0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 0  0  .8 0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 0  0  0  .8 0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  .4 .4 .6 .6 0  0  0  0  .8 0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  .6 .6 0  0  0  0  0  0  0  0  0  0  0
\end{filecontents}

\pgfplotstableread{image.dat}{\pixeldata}

\begin{document}
\begin{tikzpicture}[x=0.33cm, y=0.33cm]

\pgfplotstablegetcolsof{\pixeldata}
\pgfmathsetmacro{\datacols}{\pgfplotsretval-1}
\pgfplotstablegetrowsof{\pixeldata}
\pgfmathsetmacro{\datarows}{\pgfplotsretval-1}
\foreach \i in {0,...,\datarows} {
    \foreach \j in {0,...,\datacols} {
        \pgfplotstablegetelem{\i}{\j}\of{\pixeldata}
        \pgfmathsetmacro{\pixelvalue}{\pgfplotsretval}
        \ifdim\pixelvalue pt>0pt\relax
            \node[scale=\pixelvalue] at (\j,-\i) {\emoji{unicorn}};
        \fi
    }
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

具有镜像“眼睛像素”的变化:

\documentclass[border=10Mm]{standalone}
\usepackage{emoji}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

% Original Image: Hszone/Wirestock Creators / stock.adobe.com
% https://stock.adobe.com/de/images/unicorn-pixel-art-vector/501392488
\begin{filecontents}{image.dat} 
.2 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  .2 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  .2 .2 0  0  0  0  0  0  0  0  0  .5 0  0  0  0  0  0  0  0  0  0  0  0 
0  0  .2 .2 .2 0  0  0  0  0  0  .5 0  .5 0  0  0  0  0  0  0  0  0  0  0 
0  0  .2 .2 .2 .2 0  0  0  0  0  .5 0  .5 0  0  0  0  0  0  0  0  0  0  0 
0  0  0  .2 .2 .2 .2 .8 .8 .8 .8 0  0  0  .8 .8 .8 .8 0  0  0  0  0  0  0
0  0  0  0  .2 .8 .8 .8 .8 .8 .8 0  0  .8 .8 .8 .8 .8 .8 .8 0  0  0  0  0
0  0  0  0  0  .8 .8 .8 0  0  0  0  0  .8 .8 .8 .8 .8 .8 .8 .8  0 0  0  0
0  0  .8 0  .8 .8 .8 0  0  0  0  0  0  0  .8 .8 .8 .8 .8 .8 .8 .8 0  0  0
0  0  0  .8 .8 0  0  0  0  0  0  0  0  0  0  .6 .6 .6 .8 .8 .8 .8 .8 0  0
0  0  0  0  .5 0  0  0  0  0  0  0  0  0  0  0  .6 .6 .6 .6 .8 .8 .8 0  0
0  0  0  .5 0  0  0  1  0  0  0  0  0  0  0  0  0  .4 .6 .6 .6 .8 .8 .8 0
0  0  .5 0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .6 .6 .6 .8 .8 .8 .8
0  .5 0  0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  0  0  0  0  0  0  0  0  0  0  .5 0  0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  .5 0  0  0  0  0  .5 .5 .5 .5 0  0  0  0  0  .4 .4 .6 .6 .6 .8 .8 .8
.5 0  0  0  0  0  .5 .5 0  .5 0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 .8 .8 .8
0  .5 .5 .5 .5 .5 0  0  0  0  .5 0  0  0  0  .4 .4 .4 .6 .6 .6 .6 .8 .8 .8
0  0  0  0  0  0  0  0  0  0  .5 0  0  0  .4 .4 .4 .4 .6 .6 .6 .6 .8 .8 .8
0  0  0  0  0  0  0  0  0  0  .5 0  .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0
0  0  0  0  0  0  0  0  0  0  .5 .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0
0  0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .8 .8 0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 .8 0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 .8 0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .4 .6 .6 .6 .6 .6 .6 .6 .8 0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 .6 .6 .6 .8 .8 0  0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 .6 0  0  .8 0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  .4 .4 .4 .6 .6 0  0  0  .8 0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  .4 .4 .6 .6 0  0  0  0  .8 0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  .6 .6 0  0  0  0  0  0  0  0  0  0  0
\end{filecontents}

\pgfplotstableread{image.dat}{\pixeldata}

\begin{document}
\begin{tikzpicture}[x=0.33cm, y=0.33cm]

\pgfplotstablegetcolsof{\pixeldata}
\pgfmathsetmacro{\datacols}{\pgfplotsretval-1}
\pgfplotstablegetrowsof{\pixeldata}
\pgfmathsetmacro{\datarows}{\pgfplotsretval-1}
\foreach \i in {0,...,\datarows} {
    \foreach \j in {0,...,\datacols} {
        \pgfplotstablegetelem{\i}{\j}\of{\pixeldata}
        \pgfmathsetmacro{\pixelvalue}{\pgfplotsretval}
        \pgfmathsetmacro{\pixelmirror}{(\i == 11 && \j == 7 ? 1 : 0)}
        \ifdim\pixelvalue pt>0pt\relax
            \ifnum\pixelmirror=1\relax
                \node[xscale=-\pixelvalue, yscale=\pixelvalue] 
                    at (\j,-\i) {\emoji{unicorn}};
            \else
                \node[scale=\pixelvalue] 
                    at (\j,-\i) {\emoji{unicorn}};
            \fi
        \fi
    }
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容