Hello,
I am making progress and I almost get what I want to achieve but I still have two problems :
how to color cells not containing numbers with the same color as the others ?
how to color in salmon, for example, cells 1 2 ?
3
Thank you
Fabrice
\usecolors[X11]
\startuseMPgraphic{DiagonalRule}
rulethickness := \frameddimension{rulethickness};
drawoptions(
withpen pencircle scaled rulethickness
withcolor \MPcolor{\framedparameter{framecolor}});
pair leftcorner, rightcorner;
leftcorner := (rulethickness, \overlayheight-rulethickness);
rightcorner := (\overlaywidth-rulethickness, rulethickness);
draw leftcorner -- rightcorner;
\stopuseMPgraphic
\defineoverlay
[DiagonalRule]
[\useMPgraphic{DiagonalRule}]
\define[2]\DiagonalLabel{%
\setuptabulate [after={\blank[\frameddimension{offset}]}]
\starttabulate [|p|r|]
\NC \NC #2 \NC\NR
\NC #1 \NC \NC\NR
\stoptabulate
}
\starttext
\startluacode
function Binom(n,k)
if k > n then
return ""
elseif (n == 0 or k == 0) then
return 1
else
return math.round((n*Binom(n-1,k-1))/k)
end
end
context.startxtable({"align={middle,lohi}, width=1cm,offset=0.8ex,bodyfont=9pt,framecolor=cyan"})
context.startxrow()
context.startxcell({"background=DiagonalRule,background=color,backgroundcolor=thistle2"})
context("\\DiagonalLabel{\\m{n}}{\\m{k}}")
context.stopxcell()
for j = 0, 7 do
context.startxcell({"background=color,backgroundcolor=thistle2"})
context(j)
context.stopxcell()
end
context.startxcell({"background=color,backgroundcolor=thistle2"})
context("\\dots")
context.stopxcell()
context.stopxrow()
for i = 0, 7 do
context.startxrow()
context.startxcell({"background=color,backgroundcolor=thistle2"})
context(i)
context.stopxcell()
for j = 0, 8 do
context.startxcell()
context(Binom(i,j))
context.stopxcell()
end
context.stopxrow()
end
context.startxrow()
context.startxcell({"background=color,backgroundcolor=thistle2"})
context("\\dots")
context.stopxcell()
for i = 0, 8 do
context.startxcell({"background=color,backgroundcolor=thistle2"})
context("")
context.stopxcell()
end
context.stopxrow()
context.stopxtable()
\stopluacode
\stoptext