* OT: Pexeso
@ 2018-06-11 9:09 Procházka Lukáš Ing.
0 siblings, 0 replies; only message in thread
From: Procházka Lukáš Ing. @ 2018-06-11 9:09 UTC (permalink / raw)
To: ConTeXt; +Cc: oka, ddv
[-- Attachment #1: Type: text/plain, Size: 1995 bytes --]
Hello,
there is a card game called "Pexeso".
It is played by two or more players with pairs of cards of identical pictures.
Initially, cards are spread regularly and are turned upside down.
The first player turns two cards; if they are identical, he picks them and continues turning two more cards.
Once both cards do not show the same picture, the next payer follows.
The game stops when there are no more cards to turn.
Who collects more pairs of cards is winner.
Usually, you can buy Pexeso of Barbies, princesses, road signs, castles, ...
My little son (of nearly 4 years) ignores all above as he is interested (or even fascinated) by construction machinery and woodworking tools.
So I decided to create a Pexeso of woodworking tools for him with the following points:
- Pictures to be processed are placed in the subdirectory called "1" (may be changed).
- Pictures whose name do not start by "-" have the first letter uppercased shown on the card ("education" for letters).
- You may simply change the text or MP code to draw the card back.
- Backs of cards are intentionally a bit randomized (I am curious how quickly children are able to recognize some cards by their backs).
- When the number of cards is not multiple of two (also my case), two more backs of cards will be drawn.
This is intended and it comes due to some simplicity of the code; and it doesn't matter to anything.
- Source uses UTF-8 coding.
- There are no dependencies to external files (excluding pictures).
- The source file is attached.
Due to the size (~2.3 MB), all data including the result and source pictures are available for download here:
http://leteckaposta.cz/611754576
(The link will be valid for ~27 days from now.)
Enjoy!
Best regards,
Lukas
--
Ing. Lukáš Procházka | mailto:LPr@pontex.cz
Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS:nrpt3sn
Bezová 1658
147 14 Praha 4
Mob.: +420 702 033 396
[-- Attachment #2: Pexeso2.mkiv --]
[-- Type: application/octet-stream, Size: 3350 bytes --]
\setuplayout[tight]
\definecombination[Pexeso]
\setupcombination[Pexeso][alternative=label]
\setupexternalfigures[width=45mm,inbetween=,location=global,directory=1]
\setupbodyfont
[%pagella,
sans,
]
\definefontsize[e]
\definebodyfontenvironment[default][e=1.85]
\showlayout
% MP
\defineoverlay[Bkg][\useMPgraphic{Bkg}]
\startuseMPgraphic{Bkg}
newpath pa;
pa = (-22mm, -10mm) -- (-15mm, -15mm) -- (15mm, -15mm) -- (22mm, -10mm)
-- (22mm, 10mm) -- (15mm, 15mm) -- (-15mm, 15mm) -- (-22mm, 10mm)
-- cycle;
pa := pa scaled 0.9 randomized 1.mm;
color col; col := .333blue;
if true :
fill pa
withcolor
(.995 yellow)
;
draw pa withpen pencircle scaled (1.25mm) withcolor blue;
fi
\stopuseMPgraphic
%
\definecolor[LtrCol][r=.5,g=0.,b=0.,t_=.667,a=.5]
\defineoverlay[Ltr][\useMPgraphic{Ltr}]
\startuseMPgraphic{Ltr}
draw thelabel(btex\bfe \MPtext{1} etex, (0mm, 0mm))
withcolor
"LtrCol"
;
newpath pa; pa = (0mm, 0mm) -- (42mm, -42mm) -- cycle;
setbounds currentpicture to pa;
\stopuseMPgraphic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ěščřžýáíé
\starttext
\startluacode
local pics = {}
local pa = lfs.currentdir() .. "/1"
for fn in lfs.dir(pa) do
fn = pa .. "/" .. fn
local atts = lfs.attributes(fn)
print(fn)
--inspect(atts); io.read()
if atts and atts.mode == "file" then
table.insert(pics, (fn:gsub("\\", "/")))
end
end
--inspect(pics); io.read()
local C = context
local pics1 = {}
for i, pic in ipairs(pics) do
table.insert(pics1, pic)
if math.mod(i, 10) == 0 or i == #pics then
for j, fun in ipairs{ function(i, pic)
if not pic then return end
local c = pic:match(".*/(.)")
C.setMPtext(1, c == "-" and "" or c:upper())
C.framed( {width = "50mm", height = "50mm", frame = "none", background = "foreground,Ltr"},
context.nested.externalfigure{pic})
end,
function(i, pic)
C.framed({width = "50mm", height = "50mm", frame = "none", background = "Bkg"}, context.nested.bfe("NÁŘADÍ"))
end,
} do
C.startalignment{"middle"}
C.bTABLE{ align = "{lohi,middle}",
["frame" .. (j == 2 and "" or "~")] = "off",
}
for k = 1, math.ceil(#pics1 / 2) * 2 do
local pic = pics1[k]
if math.mod(k, 2) == 1 then
C.bTR()
end
for _ = 1, 2 do
C.bTD()
fun(i, pic)
C.eTD()
end
if math.mod(k, 2) == 0 then
C.eTR()
end
end
C.eTABLE()
C.stopalignment()
C.page()
end
pics1 = {}
end
end
\stopluacode
\stoptext
[-- Attachment #3: Type: text/plain, Size: 492 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-06-11 9:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11 9:09 OT: Pexeso Procházka Lukáš Ing.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).