Questa è la risposta più precisa che possiamo darti, però studiala attentamente e vedi se si adatta al tuo lavoro.
Soluzione:
Codice 1
documentclass[tikz,border=2pt]{standalone}
usetikzlibrary{matrix}
makeatletter
newcounter{[email protected]@omino}
newcounter{[email protected]@[email protected]}
newcounter{[email protected]@[email protected]}
tikzset{
omino/.style={/tikz/omino/.cd,#1},
omino/distance/.initial=1,
omino/radius/.initial=.5,
omino/at/.style={/tikz/shift={(#1)}},
omino/rotate/.style={/tikz/rotate=#1},
omino/s/.code=
setcounter{[email protected]@omino}{0}%
setcounter{[email protected]@[email protected]}{0}%
setcounter{[email protected]@[email protected]}{0}%
pgfkeysalso{/tikz/insert path={(0,0) node[/tikz/omino/nodes/.try,/tikz/omino/node normal/.try,/tikz/omino/node start/.try] {[email protected]@[email protected]@start}}},
omino/u/.code=%
stepcounter{[email protected]@omino}%
stepcounter{[email protected]@[email protected]}%
pgfkeysalso{/tikz/insert path={
to[/tikz/omino/how] ++(up:#1)
node[/tikz/omino/nodes/.try,/tikz/omino/node normal/.try,/tikz/omino/node up/.try]{[email protected]@[email protected]@up}}},
omino/d/.code=%
stepcounter{[email protected]@omino}%
addtocounter{[email protected]@[email protected]}{-1}%
pgfkeysalso{/tikz/insert path={
to[/tikz/omino/how] ++(down:#1)
node[/tikz/omino/nodes/.try,/tikz/omino/node normal/.try,/tikz/omino/node down/.try]{[email protected]@[email protected]@down}}},
omino/l/.code=%
stepcounter{[email protected]@omino}%
addtocounter{[email protected]@[email protected]}{-1}%
pgfkeysalso{/tikz/insert path={
to[/tikz/omino/how] ++(left:#1)
node[/tikz/omino/nodes/.try,/tikz/omino/node normal/.try,/tikz/omino/node left/.try]{[email protected]@[email protected]@left}}},
omino/r/.code=%
stepcounter{[email protected]@omino}%
stepcounter{[email protected]@[email protected]}%
pgfkeysalso{/tikz/insert path={
to[/tikz/omino/how] ++(right:#1)
node[/tikz/omino/nodes/.try,/tikz/omino/node normal/.try,/tikz/omino/node right/.try] {[email protected]@[email protected]@right}}},
omino/u/.default=pgfkeysvalueof{/tikz/omino/distance},
omino/d/.default=pgfkeysvalueof{/tikz/omino/distance},
omino/l/.default=pgfkeysvalueof{/tikz/omino/distance},
omino/r/.default=pgfkeysvalueof{/tikz/omino/distance},
omino/how/.style=,
omino/reset/.code=
[email protected]@_{#1}%
[email protected]@
[email protected]@[email protected]#1relax
else
edef[email protected]{csname [email protected]@[email protected]@#1endcsname}%
expandafter[email protected]@[email protected][email protected]relax
fi
pgfkeysalso{/tikz/insert path={(omino-n-#1.center) node[/tikz/omino/nodes/.try, /tikz/omino/node reset/.try] {[email protected]@[email protected]@reset}}},
omino/do/.code={@tfor@next:=#1do{pgfkeysalso{/tikz/omino/@next}}},
omino/node reset/.style={draw=none,fill=none},
omino/node normal/.style={
name=omino-n-number[email protected]@[email protected],
alias=omino-n-number[email protected]@[email protected]@right_number[email protected]@[email protected]@up,
omino/@store coords
},
omino/@store coords/.code=
expandafterxdefcsname [email protected]@[email protected]@arabic{[email protected]@omino}endcsname
{number[email protected]@[email protected]@right_number[email protected]@[email protected]@up},
omino/Text/.code 2 args=expandafteredefcsname [email protected]@[email protected]@#1endcsname{#2},
omino/Text={up}{},omino/Text={down}{},omino/Text={left}{},omino/Text={right}{},omino/Text={start}{},omino/Text={reset}{}
}
def[email protected]@[email protected]#1_#2relax{setcounter{[email protected]@[email protected]}{#1}setcounter{[email protected]@[email protected]}{#2}}
tikzset{
omino/x mirror/.style={/tikz/cm={-1,0,0,1,(0,0)}},
omino/y mirror/.style={/tikz/cm={1,0,0,-1,(0,0)}}
}
tikzset{fun/.code={pgfmathtruncatemacro@fun{number[email protected]@[email protected]/4*100}pgfkeysalso{fill=blue!@fun!red}}}
makeatother
tikzset{
tetris/.style={/tikz/tetris/.cd,#1},
tetris/1/.style={/tikz/omino={do=suuu}},
tetris/2/.style={/tikz/omino={do=suur}},
tetris/2'/.style={/tikz/omino/x mirror, 2},
tetris/3/.style={/tikz/omino={do=suru}},
tetris/3'/.style={/tikz/omino/x mirror, 3},
tetris/4/.style={/tikz/omino={do=surd}},
tetris/5/.style={/tikz/omino={s,u,u,reset=1,r}}
}
makeatletter
makeatother
newcommand*{thesamepictureeverywhere}{matrix[column sep=.5cm, row sep=.5cm, ampersand replacement=&] {
path [tetris=1]; &
path [tetris=2']; & path [tetris=2]; \
path [tetris=3]; & path [tetris=3']; &
path [tetris=4]; &
path [tetris=5];\};}
begin{document}
begin{tikzpicture}[
every path/.style=draw,
omino/how/.style={bend left},
omino/nodes/.style={circle, inner sep=+0pt, minimum size=+4pt, fill=black, outer sep=+0pt}]
thesamepictureeverywhere
end{tikzpicture}
begin{tikzpicture}[omino/nodes/.style={rectangle, inner sep=+0pt, minimum size=+1cm, draw}]
thesamepictureeverywhere
end{tikzpicture}
begin{tikzpicture}[omino={
nodes/.style={circle, inner sep=+0pt, minimum size=+1cm, draw},
Text={left}l,Text={right}r,Text={up}u,Text={down}d,Text={start}s
}]
thesamepictureeverywhere
end{tikzpicture}
begin{tikzpicture}[omino/nodes/.style={shape=circle, inner sep=+0pt, minimum size=+1cm, fun}]
thesamepictureeverywhere
end{tikzpicture}
tikzset{
tetris/1/.prefix style={/tikz/omino/nodes/.append style={fill=black,text=white}},
tetris/2/.prefix style={/tikz/omino/nodes/.append style={fill=blue}},
tetris/3/.prefix style={/tikz/omino/nodes/.append style={fill=green!70!blue}},
tetris/4/.prefix style={/tikz/omino/nodes/.append style={fill=yellow!80!black}},
tetris/5/.prefix style={/tikz/omino/nodes/.append style={fill=red!70!black}},
omino/Text={start}{.}
}
begin{tikzpicture}[omino/nodes/.style={shape=rectangle, rounded corners, inner sep=+0pt, minimum size=1cm-2pgflinewidth}]
path [tetris=1];
path [omino/at=0:1] [tetris=2];
path [omino/at=0:2] [tetris=3];
path [omino={at=0:3, rotate=-90, x mirror}][tetris=5];
path [omino={at={5,1}, rotate=-90}][tetris=3];
path [omino={at={5,2}, rotate=-90}][tetris=2];
path [omino={at={4,2}, x mirror}][tetris=5];
path [omino={at={1,3}}][tetris=4];
end{tikzpicture}
end{document}
Uscita 1
Codice 2
documentclass[tikz,border=2pt,convert=false]{standalone}
usetikzlibrary{matrix}
makeatletter
tikzset{
omino/.style={/tikz/omino.cd,#1},
omino/row sep/.initial=1cm,
omino/column sep/.initial=1cm}
newcounter{[email protected]@[email protected]}
newcounter{[email protected]@[email protected]}
def[email protected]@[email protected]{stepcounter{[email protected]@[email protected]}}
def[email protected]@[email protected]{%
stepcounter{[email protected]@[email protected]}
node[
every omino node/.try,
every omino row number[email protected]@[email protected]@y/.try,
every omino column number[email protected]@[email protected]@x/.try,
every omino cell number[email protected]@[email protected]@x-number[email protected]@[email protected]@y/.try,
at={([email protected]@[email protected]@x*pgfkeysvalueof{/tikz/omino/column sep},[email protected]@[email protected]@y*pgfkeysvalueof{/tikz/omino/row sep})}
]{};}
def[email protected]@[email protected]{setcounter{[email protected]@[email protected]}{0}stepcounter{[email protected]@[email protected]}}
def[email protected]@[email protected]{endgroup@gobble}
def[email protected]{%
afterassignment[email protected]@ominolet[email protected]@token=}
def[email protected]@omino{%
let[email protected]relax
ifx[email protected]@token.%
let[email protected][email protected]@[email protected]
else
ifx[email protected]@token*%
let[email protected][email protected]@[email protected]
else
ifx[email protected]@token:
let[email protected][email protected]@[email protected]
else
ifx[email protected]@token;
let[email protected][email protected]@[email protected]
fi
fi
fi
fi
[email protected][email protected]
}
newcommand*{omino}[1][]{begingrouptikzset{#1}setcounter{[email protected]@[email protected]}{0}setcounter{[email protected]@[email protected]}{0}[email protected]}
makeatother
tikzset{every omino node/.style={circle, inner sep=+0pt, minimum size=+1cm}}
begin{document}
begin{tikzpicture}[every omino node/.append style={rectangle, fill,draw}]
matrix[column sep=.5cm]{
omino *:*:*:*; & omino **:*:*; & omino *:**:*; & omino .*:**:*; \};
end{tikzpicture}
begin{tikzpicture}[
every omino row 0/.style={fill=blue},
every omino row 1/.style={fill=blue!33!red},
every omino row 2/.style={fill=blue!67!red},
every omino row 3/.style={fill=red}]
matrix[column sep=.5cm]{
omino *:*:*:*; & omino **:*:*; & omino *:**:*; & omino .*:**:*; \};
end{tikzpicture}
end{document}
Uscita 2
documentclass{article}
makeatletter
defomino#1{{%
unitlength10[email protected]
@tempcnta[email protected]
@tempcntb@ne
[email protected][email protected]
xomino#1relax
fbox{begin{picture}(@tempcnta,@tempcntb)(0,-@tempcntb)%
@tempcnta[email protected]
@tempcntb@ne
[email protected][email protected]
xxomino#1relax
end{picture}}%
}%
}
defxomino#1{%
ifxrelax#1%
else
ifx\#1%
ifnum[email protected]>@tempcnta @tempcnta[email protected]fi
advance@tempcntb@ne
[email protected][email protected]
else
advance[email protected]@ne
fi
expandafterxomino
fi}
defxxomino#1{%
ifxrelax#1%
else
ifx\#1%
advance@tempcntb@ne
[email protected][email protected]
else
advance[email protected]@ne
ifx*#1%
put([email protected],-@tempcntb){kern-10ptrule{10pt}{10pt}}%
fi
fi
expandafterxxomino
fi}
makeatother
begin{document}
omino{
*\
*\
*\
*\
*}
omino{
**\
.*\
.*\
.*}
omino{
**\
*\
*\
**}
end{document}
La soluzione di David converte l'arte ascii in grafica. Ecco una versione derivata che realizza un trucco simile.
documentclass{article}
usepackage{color}
newdimenomsq omsq=20pt
newdimenomrule omrule=2pt
newdimenomint
newififvth newififhth newififomblank
defOMINO#1{%
vthtrue hthtrue
vbox{ offinterlineskipparindent=0pt OM#1relaxvskip1pt}}
defOM#1{%
omint=omsq advanceomint-omrule
ifxrelax#1%
else
ifx\#1 newlinenull hthtrue ifvthvthfalseelsevskip-omrulevthtruefi
else%
ifx .#1hskipifhth omruleelse omintfi
else%
ifx +#1defcolour{black}fi%
ifx -#1defcolour{black}fi%
ifx |#1defcolour{black}fi%
ifx @#1defcolour{black}fi%
ifx r#1defcolour{red}fi%
ifx g#1defcolour{green}fi%
ifx b#1defcolour{blue}fi%
ifx y#1defcolour{yellow}fi%
ifx m#1defcolour{magenta}fi%
ifx c#1defcolour{cyan}fi%
textcolor{colour}{rule{ifhthomruleelseomsqfi}{ifvthomruleelseomsqfi}}%
ifhthelsehskip -omrulefi%
fi%
ifhthhthfalseelsehthtruefi%
fi%
expandafterOM%
fi}
makeatother
begin{document}
OMINO{
+-+-----+\
|g|@|r.r|\
|.+-+.+-+\
|g.g|r|.|\
+-+.|.|.|\
|c|g|r|.|\
|.+-+-+.|\
|c.c.c|.|\
+-----+-+
}
OMINO{
+-+.......+-----+\
|.|.......|r.r.r|\
|.+-+-----+---+.|\
|...|y.y.y.y.y|r|\
+-+.+-+-----+-+.|\
..|...|.....|r.r|\
..+---+.....+---+
}
end{document}