1if not modules then modules = { } end modules ['present-random'] = {
2 version = 1.001,
3 comment = "companion to s-present-random.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11
12moduledata.steps = moduledata.steps or { }
13local steps = moduledata.steps
14
15local locations = {
16 'lefttop',
17 'middletop',
18 'righttop',
19 'middleleft',
20 'middle',
21 'middleright',
22 'leftbottom',
23 'middlebottom',
24 'rightbottom',
25}
26
27local done, current, previous, n
28
29function steps.reset_locations()
30 done, current, previous, n = table.tohash(locations,false), 0, 0, 0
31end
32
33function steps.next_location(loc)
34 previous = current
35 n = n + 1
36 loc = loc and loc ~= "" and tonumber(loc)
37 while true do
38 current = loc or math.random(1,#locations)
39 if not done[current] then
40 done[current] = true
41 break
42 end
43 end
44end
45
46function steps.current_location()
47 context(locations[current] or "")
48end
49
50function steps.previous_location()
51 context(locations[previous] or "")
52end
53
54function steps.current_n()
55 context(current)
56end
57
58function steps.previous_n()
59 context(previous)
60end
61
62function steps.step()
63 context(n)
64end
65
66steps.reset_locations()
67 |