Debian Codegraph @

texmf-dist/tex/luatex/chickenize/chickenize.lua

raw
1 --
2 -- This is file `chickenize.lua',
3 -- generated with the docstrip utility.
4 --
5 -- The original source files were:
6 --
7 -- chickenize.dtx (with options: `lua')
8 --
9 -- EXPERIMENTAL CODE
10 --
11 -- This package is copyright © 2021 Arno L. Trautmann. It may be distributed and/or
12 -- modified under the conditions of the LaTeX Project Public License, either version 1.3c
13 -- of this license or (at your option) any later version. This work has the LPPL mainten-
14 -- ance status ‘maintained’.
15
16 local nodeid = node.id
17 local nodecopy = node.copy
18 local nodenew = node.new
19 local nodetail = node.tail
20 local nodeslide = node.slide
21 local noderemove = node.remove
22 local nodetraverseid = node.traverse_id
23 local nodeinsertafter = node.insert_after
24 local nodeinsertbefore = node.insert_before
25
26 Hhead = nodeid("hhead")
27 RULE = nodeid("rule")
28 GLUE = nodeid("glue")
29 WHAT = nodeid("whatsit")
30 COL = node.subtype("pdf_colorstack")
31 DISC = nodeid("disc")
32 GLYPH = nodeid("glyph")
33 GLUE = nodeid("glue")
34 HLIST = nodeid("hlist")
35 KERN = nodeid("kern")
36 PUNCT = nodeid("punct")
37 PENALTY = nodeid("penalty")
38 PDF_LITERAL = node.subtype("pdf_literal")
39 color_push = nodenew(WHAT,COL)
40 color_pop = nodenew(WHAT,COL)
41 color_push.stack = 0
42 color_pop.stack = 0
43 color_push.command = 1
44 color_pop.command = 2
45 chicken_pagenumbers = true
46
47 chickenstring = {}
48 chickenstring[1] = "chicken" -- chickenstring is a table, please remeber this!
49
50 chickenizefraction = 0.5 -- set this to a small value to fool somebody,
51 -- or to see if your text has been read carefully. This is also a great way to lay easter eggs for your own class / package …
52 chicken_substitutions = 0 -- value to count the substituted chickens. Makes sense for testing your proofreaders.
53
54 local match = unicode.utf8.match
55 chickenize_ignore_word = false
56 chickenize_real_stuff = function(i,head)
57 while ((i.next.id == GLYPH) or (i.next.id == KERN) or (i.next.id == DISC) or (i.next.id == HLIST)) do --find end of a word
58 i.next = i.next.next
59 end
60
61 chicken = {} -- constructing the node list.
62
63 -- Should this be done only once? No, otherwise we lose the freedom to change the string in-document.
64 -- But it could be done only once each paragraph as in-paragraph changes are not possible!
65
66 chickenstring_tmp = chickenstring[math.random(1,#chickenstring)]
67 chicken[0] = nodenew(GLYPH,1) -- only a dummy for the loop
68 for i = 1,string.len(chickenstring_tmp) do
69 chicken[i] = nodenew(GLYPH,1)
70 chicken[i].font = font.current()
71 chicken[i-1].next = chicken[i]
72 end
73
74 j = 1
75 for s in string.utfvalues(chickenstring_tmp) do
76 local char = unicode.utf8.char(s)
77 chicken[j].char = s
78 if match(char,"%s") then
79 chicken[j] = nodenew(GLUE)
80 chicken[j].width = space
81 chicken[j].shrink = shrink
82 chicken[j].stretch = stretch
83 end
84 j = j+1
85 end
86
87 nodeslide(chicken[1])
88 lang.hyphenate(chicken[1])
89 chicken[1] = node.kerning(chicken[1]) -- FIXME: does not work
90 chicken[1] = node.ligaturing(chicken[1]) -- dito
91
92 nodeinsertbefore(head,i,chicken[1])
93 chicken[1].next = chicken[2] -- seems to be necessary … to be fixed
94 chicken[string.len(chickenstring_tmp)].next = i.next
95
96 -- shift lowercase latin letter to uppercase if the original input was an uppercase
97 if (chickenize_capital and (chicken[1].char > 96 and chicken[1].char < 123)) then
98 chicken[1].char = chicken[1].char - 32
99 end
100
101 return head
102 end
103
104 chickenize = function(head)
105 for i in nodetraverseid(GLYPH,head) do --find start of a word
106 -- Random determination of the chickenization of the next word:
107 if math.random() > chickenizefraction then
108 chickenize_ignore_word = true
109 elseif chickencount then
110 chicken_substitutions = chicken_substitutions + 1
111 end
112
113 if (chickenize_ignore_word == false) then -- normal case: at the beginning of a word, we jump into chickenization
114 if (i.char > 64 and i.char < 91) then chickenize_capital = true else chickenize_capital = false end
115 head = chickenize_real_stuff(i,head)
116 end
117
118 -- At the end of the word, the ignoring is reset. New chance for everyone.
119 if not((i.next.id == GLYPH) or (i.next.id == DISC) or (i.next.id == PUNCT) or (i.next.id == KERN)) then
120 chickenize_ignore_word = false
121 end
122 end
123 return head
124 end
125
126 local separator = string.rep("=", 28)
127 local texiowrite_nl = texio.write_nl
128 nicetext = function()
129 texiowrite_nl("Output written on "..tex.jobname..".pdf ("..status.total_pages.." chicken,".." eggs).")
130 texiowrite_nl(" ")
131 texiowrite_nl(separator)
132 texiowrite_nl("Hello my dear user,")
133 texiowrite_nl("good job, now go outside and enjoy the world!")
134 texiowrite_nl(" ")
135 texiowrite_nl("And don't forget to feed your chicken!")
136 texiowrite_nl(separator .. "\n")
137 if chickencount then
138 texiowrite_nl("There were "..chicken_substitutions.." substitutions made.")
139 texiowrite_nl(separator)
140 end
141 end
142 boustrophedon = function(head)
143 rot = node.new(WHAT,PDF_LITERAL)
144 rot2 = node.new(WHAT,PDF_LITERAL)
145 odd = true
146 for line in node.traverse_id(0,head) do
147 if odd == false then
148 w = line.width/65536*0.99625 -- empirical correction factor (?)
149 rot.data = "-1 0 0 1 "..w.." 0 cm"
150 rot2.data = "-1 0 0 1 "..-w.." 0 cm"
151 line.head = node.insert_before(line.head,line.head,nodecopy(rot))
152 nodeinsertafter(line.head,nodetail(line.head),nodecopy(rot2))
153 odd = true
154 else
155 odd = false
156 end
157 end
158 return head
159 end
160 boustrophedon_glyphs = function(head)
161 odd = false
162 rot = nodenew(WHAT,PDF_LITERAL)
163 rot2 = nodenew(WHAT,PDF_LITERAL)
164 for line in nodetraverseid(0,head) do
165 if odd==true then
166 line.dir = "TRT"
167 for g in nodetraverseid(GLYPH,line.head) do
168 w = -g.width/65536*0.99625
169 rot.data = "-1 0 0 1 " .. w .." 0 cm"
170 rot2.data = "-1 0 0 1 " .. -w .." 0 cm"
171 line.head = node.insert_before(line.head,g,nodecopy(rot))
172 nodeinsertafter(line.head,g,nodecopy(rot2))
173 end
174 odd = false
175 else
176 line.dir = "TLT"
177 odd = true
178 end
179 end
180 return head
181 end
182 boustrophedon_inverse = function(head)
183 rot = node.new(WHAT,PDF_LITERAL)
184 rot2 = node.new(WHAT,PDF_LITERAL)
185 odd = true
186 for line in node.traverse_id(0,head) do
187 if odd == false then
188 texio.write_nl(line.height)
189 w = line.width/65536*0.99625 -- empirical correction factor (?)
190 h = line.height/65536*0.99625
191 rot.data = "-1 0 0 -1 "..w.." "..h.." cm"
192 rot2.data = "-1 0 0 -1 "..-w.." "..0.5*h.." cm"
193 line.head = node.insert_before(line.head,line.head,node.copy(rot))
194 node.insert_after(line.head,node.tail(line.head),node.copy(rot2))
195 odd = true
196 else
197 odd = false
198 end
199 end
200 return head
201 end
202 function bubblesort(head)
203 for line in nodetraverseid(0,head) do
204 for glyph in nodetraverseid(GLYPH,line.head) do
205
206 end
207 end
208 return head
209 end
210 -- Take care: This will slow down the compilation extremely, by about a factor of 2! Only use for playing around or counting a final version of your document!
211 countglyphs = function(head)
212 for line in nodetraverseid(0,head) do
213 for glyph in nodetraverseid(GLYPH,line.head) do
214 glyphnumber = glyphnumber + 1
215 if (glyph.next.next) then
216 if (glyph.next.id == 10) and (glyph.next.next.id == GLYPH) then
217 spacenumber = spacenumber + 1
218 end
219 counted_glyphs_by_code[glyph.char] = counted_glyphs_by_code[glyph.char] + 1
220 end
221 end
222 end
223 return head
224 end
225 printglyphnumber = function()
226 texiowrite_nl("\nNumber of glyphs by character code (only up to 127):")
227 for i = 1,127 do --%% FIXME: should allow for more characters, but cannot be printed to console output – print into document?
228 texiowrite_nl(string.char(i)..": "..counted_glyphs_by_code[i])
229 end
230
231 texiowrite_nl("\nTotal number of glyphs in this document: "..glyphnumber)
232 texiowrite_nl("Number of spaces in this document: "..spacenumber)
233 texiowrite_nl("Glyphs plus spaces: "..glyphnumber+spacenumber.."\n")
234 end
235 countwords = function(head)
236 for glyph in nodetraverseid(GLYPH,head) do
237 if (glyph.next.id == GLUE) then
238 wordnumber = wordnumber + 1
239 end
240 end
241 wordnumber = wordnumber + 1 -- add 1 for the last word in a paragraph which is not found otherwise
242 return head
243 end
244 printwordnumber = function()
245 texiowrite_nl("\nNumber of words in this document: "..wordnumber)
246 end
247
248 detectdoublewords = function(head)
249 prevlastword = {} -- array of numbers representing the glyphs
250 prevfirstword = {}
251 newlastword = {}
252 newfirstword = {}
253 for line in nodetraverseid(0,head) do
254 for g in nodetraverseid(GLYPH,line.head) do
255 texio.write_nl("next glyph",#newfirstword+1)
256 newfirstword[#newfirstword+1] = g.char
257 if (g.next.id == 10) then break end
258 end
259 texio.write_nl("nfw:"..#newfirstword)
260 end
261 end
262
263 printdoublewords = function()
264 texio.write_nl("finished")
265 end
266 francize = function(head)
267 for n in nodetraverseid(GLYPH,head) do
268 if ((n.char > 47) and (n.char < 58)) then
269 n.char = math.random(48,57)
270 end
271 end
272 return head
273 end
274 function gameofchicken()
275 GOC_lifetab = {}
276 GOC_spawntab = {}
277 GOC_antilifetab = {}
278 GOC_antispawntab = {}
279 -- translate the rules into an easily-manageable table
280 for i=1,#GOCrule_live do; GOC_lifetab[GOCrule_live[i]] = true end
281 for i=1,#GOCrule_spawn do; GOC_spawntab[GOCrule_spawn[i]] = true end
282 for i=1,#GOCrule_antilive do; GOC_antilifetab[GOCrule_antilive[i]] = true end
283 for i=1,#GOCrule_antispawn do; GOC_antispawntab[GOCrule_antispawn[i]] = true end
284 -- initialize the arrays
285 local life = {}
286 local antilife = {}
287 local newlife = {}
288 local newantilife = {}
289 for i = 0, GOCx do life[i] = {}; newlife[i] = {} for j = 0, GOCy do life[i][j] = 0 end end
290 for i = 0, GOCx do antilife[i] = {}; newantilife[i] = {} for j = 0, GOCy do antilife[i][j] = 0 end end
291 function applyruleslife(neighbors, lifeij, antineighbors, antilifeij)
292 if GOC_spawntab[neighbors] then myret = 1 else -- new cell
293 if GOC_lifetab[neighbors] and (lifeij == 1) then myret = 1 else myret = 0 end end
294 if antineighbors > 1 then myret = 0 end
295 return myret
296 end
297 function applyrulesantilife(neighbors, lifeij, antineighbors, antilifeij)
298 if (antineighbors == 3) then myret = 1 else -- new cell or keep cell
299 if (((antineighbors > 1) and (antineighbors < 4)) and (lifeij == 1)) then myret = 1 else myret = 0 end end
300 if neighbors > 1 then myret = 0 end
301 return myret
302 end
303 -- prepare some special patterns as starter
304 life[53][26] = 1 life[53][25] = 1 life[54][25] = 1 life[55][25] = 1 life[54][24] = 1
305 print("start");
306 for i = 1,GOCx do
307 for j = 1,GOCy do
308 if (life[i][j]==1) then texio.write("X") else if (antilife[i][j]==1) then texio.write("O") else texio.write("_") end end
309 end
310 texio.write_nl(" ");
311 end
312 os.sleep(GOCsleep)
313
314 for i = 0, GOCx do
315 for j = 0, GOCy do
316 newlife[i][j] = 0 -- Fill the values from the start settings here
317 newantilife[i][j] = 0 -- Fill the values from the start settings here
318 end
319 end
320
321 for k = 1,GOCiter do -- iterate over the cycles
322 texio.write_nl(k);
323 for i = 1, GOCx-1 do -- iterate over lines
324 for j = 1, GOCy-1 do -- iterate over columns -- prevent edge effects
325 local neighbors = (life[i-1][j-1] + life[i-1][j] + life[i-1][j+1] + life[i][j-1] + life[i][j+1] + life[i+1][j-1] + life[i+1][j] + life[i+1][j+1])
326 local antineighbors = (antilife[i-1][j-1] + antilife[i-1][j] + antilife[i-1][j+1] + antilife[i][j-1] + antilife[i][j+1] + antilife[i+1][j-1] + antilife[i+1][j] + antilife[i+1][j+1])
327
328 newlife[i][j] = applyruleslife(neighbors, life[i][j],antineighbors, antilife[i][j])
329 newantilife[i][j] = applyrulesantilife(neighbors,life[i][j], antineighbors,antilife[i][j])
330 end
331 end
332
333 for i = 1, GOCx do
334 for j = 1, GOCy do
335 life[i][j] = newlife[i][j] -- copy the values
336 antilife[i][j] = newantilife[i][j] -- copy the values
337 end
338 end
339
340 for i = 1,GOCx do
341 for j = 1,GOCy do
342 if GOC_console then
343 if (life[i][j]==1) then texio.write("X") else if (antilife[i][j]==1) then texio.write("O") else texio.write("_") end end
344 end
345 if GOC_pdf then
346 if (life[i][j]==1) then tex.print("\\placeat("..(i/10)..","..(j/10).."){"..GOCcellcode.."}") end
347 if (antilife[i][j]==1) then tex.print("\\placeat("..(i/10)..","..(j/10).."){"..GOCanticellcode.."}") end
348 end
349 end
350 end
351 tex.print(".\\newpage")
352 os.sleep(GOCsleep)
353 end
354 end --end function gameofchicken
355 function make_a_gif()
356 os.execute("convert -verbose -dispose previous -background white -alpha remove -alpha off -density "..GOCdensity.." "..tex.jobname ..".pdf " ..tex.jobname..".gif")
357 os.execute("gwenview "..tex.jobname..".gif")
358 end
359 local quotestrings = {
360 [171] = true, [172] = true,
361 [8216] = true, [8217] = true, [8218] = true,
362 [8219] = true, [8220] = true, [8221] = true,
363 [8222] = true, [8223] = true,
364 [8248] = true, [8249] = true, [8250] = true,
365 }
366 guttenbergenize_rq = function(head)
367 for n in nodetraverseid(GLYPH,head) do
368 local i = n.char
369 if quotestrings[i] then
370 noderemove(head,n)
371 end
372 end
373 return head
374 end
375 hammertimedelay = 1.2
376 local htime_separator = string.rep("=", 30) .. "\n" -- slightly inconsistent with the “nicetext”
377 hammertime = function(head)
378 if hammerfirst then
379 texiowrite_nl(htime_separator)
380 texiowrite_nl("============STOP!=============\n")
381 texiowrite_nl(htime_separator .. "\n\n\n")
382 os.sleep (hammertimedelay*1.5)
383 texiowrite_nl(htime_separator .. "\n")
384 texiowrite_nl("==========HAMMERTIME==========\n")
385 texiowrite_nl(htime_separator .. "\n\n")
386 os.sleep (hammertimedelay)
387 hammerfirst = false
388 else
389 os.sleep (hammertimedelay)
390 texiowrite_nl(htime_separator)
391 texiowrite_nl("======U can't touch this!=====\n")
392 texiowrite_nl(htime_separator .. "\n\n")
393 os.sleep (hammertimedelay*0.5)
394 end
395 return head
396 end
397 italianizefraction = 0.5 --%% gives the amount of italianization
398 mynode = nodenew(GLYPH) -- prepare a dummy glyph
399
400 italianize = function(head)
401 -- skip "h/H" randomly
402 for n in node.traverse_id(GLYPH,head) do -- go through all glyphs
403 if n.prev.id ~= GLYPH then -- check if it's a word start
404 if ((n.char == 72) or (n.char == 104)) and (tex.normal_rand() < italianizefraction) then -- if it's h/H, remove randomly
405 n.prev.next = n.next
406 end
407 end
408 end
409
410 -- add h or H in front of vowels
411 for n in nodetraverseid(GLYPH,head) do
412 if math.random() < italianizefraction then
413 x = n.char
414 if x == 97 or x == 101 or x == 105 or x == 111 or x == 117 or
415 x == 65 or x == 69 or x == 73 or x == 79 or x == 85 then
416 if (n.prev.id == GLUE) then
417 mynode.font = n.font
418 if x > 90 then -- lower case
419 mynode.char = 104
420 else
421 mynode.char = 72 -- upper case – convert into lower case
422 n.char = x + 32
423 end
424 node.insert_before(head,n,node.copy(mynode))
425 end
426 end
427 end
428 end
429
430 -- add e after words, but only after consonants
431 for n in node.traverse_id(GLUE,head) do
432 if n.prev.id == GLYPH then
433 x = n.prev.char
434 -- skip vowels and randomize
435 if not(x == 97 or x == 101 or x == 105 or x == 111 or x == 117 or x == 44 or x == 46) and math.random() > 0.2 then
436 mynode.char = 101 -- it's always a lower case e, no?
437 mynode.font = n.prev.font -- adapt the current font
438 node.insert_before(head,n,node.copy(mynode)) -- insert the e in the node list
439 end
440 end
441 end
442
443 return head
444 end
445 italianizerandwords = function(head)
446 words = {}
447 wordnumber = 0
448 -- head.next.next is the very first word. However, let's try to get the first word after the first space correct.
449 for n in nodetraverseid(GLUE,head) do -- let's try to count words by their separators
450 wordnumber = wordnumber + 1
451 if n.next then
452 words[wordnumber] = {}
453 words[wordnumber][1] = node.copy(n.next)
454
455 glyphnumber = 1
456 myglyph = n.next
457 while myglyph.next do
458 node.tail(words[wordnumber][1]).next = node.copy(myglyph.next)
459 myglyph = myglyph.next
460 end
461 end
462 print(#words)
463 if #words > 0 then
464 print("lengs is: ")
465 print(#words[#words])
466 end
467 end
468 --myinsertnode = head.next.next -- first letter
469 --node.tail(words[1][1]).next = myinsertnode.next
470 --myinsertnode.next = words[1][1]
471
472 return head
473 end
474
475 italianize_old = function(head)
476 local wordlist = {} -- here we will store the number of words of the sentence.
477 local words = {} -- here we will store the words of the sentence.
478 local wordnumber = 0
479 -- let's first count all words in one sentence, howboutdat?
480 wordlist[wordnumber] = 1 -- let's save the word *length* in here …
481
482 for n in nodetraverseid(GLYPH,head) do
483 if (n.next.id == GLUE) then -- this is a space
484 wordnumber = wordnumber + 1
485 wordlist[wordnumber] = 1
486 words[wordnumber] = n.next.next
487 end
488 if (n.next.id == GLYPH) then -- it's a glyph
489 if (n.next.char == 46) then -- this is a full stop.
490 wordnumber = wordnumber + 1
491 texio.write_nl("this sentence had "..wordnumber.."words.")
492 for i=0,wordnumber-1 do
493 texio.write_nl("word "..i.." had " .. wordlist[i] .. "glyphs")
494 end
495 texio.write_nl(" ")
496 wordnumber = -1 -- to compensate the fact that the next node will be a space, this would count one word too much.
497 else
498
499 wordlist[wordnumber] = wordlist[wordnumber] + 1 -- the current word got 1 glyph longer
500 end
501 end
502 end
503 return head
504 end
505
506 itsame = function()
507 local mr = function(a,b) rectangle({a*10,b*-10},10,10) end
508 color = "1 .6 0"
509 for i = 6,9 do mr(i,3) end
510 for i = 3,11 do mr(i,4) end
511 for i = 3,12 do mr(i,5) end
512 for i = 4,8 do mr(i,6) end
513 for i = 4,10 do mr(i,7) end
514 for i = 1,12 do mr(i,11) end
515 for i = 1,12 do mr(i,12) end
516 for i = 1,12 do mr(i,13) end
517
518 color = ".3 .5 .2"
519 for i = 3,5 do mr(i,3) end mr(8,3)
520 mr(2,4) mr(4,4) mr(8,4)
521 mr(2,5) mr(4,5) mr(5,5) mr(9,5)
522 mr(2,6) mr(3,6) for i = 8,11 do mr(i,6) end
523 for i = 3,8 do mr(i,8) end
524 for i = 2,11 do mr(i,9) end
525 for i = 1,12 do mr(i,10) end
526 mr(3,11) mr(10,11)
527 for i = 2,4 do mr(i,15) end for i = 9,11 do mr(i,15) end
528 for i = 1,4 do mr(i,16) end for i = 9,12 do mr(i,16) end
529
530 color = "1 0 0"
531 for i = 4,9 do mr(i,1) end
532 for i = 3,12 do mr(i,2) end
533 for i = 8,10 do mr(5,i) end
534 for i = 5,8 do mr(i,10) end
535 mr(8,9) mr(4,11) mr(6,11) mr(7,11) mr(9,11)
536 for i = 4,9 do mr(i,12) end
537 for i = 3,10 do mr(i,13) end
538 for i = 3,5 do mr(i,14) end
539 for i = 7,10 do mr(i,14) end
540 end
541 chickenkernamount = 0
542 chickeninvertkerning = false
543
544 function kernmanipulate (head)
545 if chickeninvertkerning then -- invert the kerning
546 for n in nodetraverseid(11,head) do
547 n.kern = -n.kern
548 end
549 else -- if not, set it to the given value
550 for n in nodetraverseid(11,head) do
551 n.kern = chickenkernamount
552 end
553 end
554 return head
555 end
556
557 leetspeak_onlytext = false
558 leettable = {
559 [101] = 51, -- E
560 [105] = 49, -- I
561 [108] = 49, -- L
562 [111] = 48, -- O
563 [115] = 53, -- S
564 [116] = 55, -- T
565
566 [101-32] = 51, -- e
567 [105-32] = 49, -- i
568 [108-32] = 49, -- l
569 [111-32] = 48, -- o
570 [115-32] = 53, -- s
571 [116-32] = 55, -- t
572 }
573 leet = function(head)
574 for line in nodetraverseid(Hhead,head) do
575 for i in nodetraverseid(GLYPH,line.head) do
576 if not leetspeak_onlytext or
577 node.has_attribute(i,luatexbase.attributes.leetattr)
578 then
579 if leettable[i.char] then
580 i.char = leettable[i.char]
581 end
582 end
583 end
584 end
585 return head
586 end
587 leftsideright = function(head)
588 local factor = 65536/0.99626
589 for n in nodetraverseid(GLYPH,head) do
590 if (leftsiderightarray[n.char]) then
591 shift = nodenew(WHAT,PDF_LITERAL)
592 shift2 = nodenew(WHAT,PDF_LITERAL)
593 shift.data = "q -1 0 0 1 " .. n.width/factor .." 0 cm"
594 shift2.data = "Q 1 0 0 1 " .. n.width/factor .." 0 cm"
595 nodeinsertbefore(head,n,shift)
596 nodeinsertafter(head,n,shift2)
597 end
598 end
599 return head
600 end
601 local letterspace_glue = nodenew(GLUE)
602 local letterspace_pen = nodenew(PENALTY)
603
604 letterspace_glue.width = tex.sp"0pt"
605 letterspace_glue.stretch = tex.sp"0.5pt"
606 letterspace_pen.penalty = 10000
607 letterspaceadjust = function(head)
608 for glyph in nodetraverseid(GLYPH, head) do
609 if glyph.prev and (glyph.prev.id == GLYPH or glyph.prev.id == DISC or glyph.prev.id == KERN) then
610 local g = nodecopy(letterspace_glue)
611 nodeinsertbefore(head, glyph, g)
612 nodeinsertbefore(head, g, nodecopy(letterspace_pen))
613 end
614 end
615 return head
616 end
617 textletterspaceadjust = function(head)
618 for glyph in nodetraverseid(GLYPH, head) do
619 if node.has_attribute(glyph,luatexbase.attributes.letterspaceadjustattr) then
620 if glyph.prev and (glyph.prev.id == node.id"glyph" or glyph.prev.id == node.id"disc" or glyph.prev.id == KERN) then
621 local g = node.copy(letterspace_glue)
622 nodeinsertbefore(head, glyph, g)
623 nodeinsertbefore(head, g, nodecopy(letterspace_pen))
624 end
625 end
626 end
627 luatexbase.remove_from_callback("pre_linebreak_filter","textletterspaceadjust")
628 return head
629 end
630 matrixize = function(head)
631 x = {}
632 s = nodenew(DISC)
633 for n in nodetraverseid(GLYPH,head) do
634 j = n.char
635 for m = 0,7 do -- stay ASCII for now
636 x[7-m] = nodecopy(n) -- to get the same font etc.
637
638 if (j / (2^(7-m)) < 1) then
639 x[7-m].char = 48
640 else
641 x[7-m].char = 49
642 j = j-(2^(7-m))
643 end
644 nodeinsertbefore(head,n,x[7-m])
645 nodeinsertafter(head,x[7-m],nodecopy(s))
646 end
647 noderemove(head,n)
648 end
649 return head
650 end
651 medievalumlaut = function(head)
652 local factor = 65536/0.99626
653 local org_e_node = nodenew(GLYPH)
654 org_e_node.char = 101
655 for line in nodetraverseid(0,head) do
656 for n in nodetraverseid(GLYPH,line.head) do
657 if (n.char == 228 or n.char == 246 or n.char == 252) then
658 e_node = nodecopy(org_e_node)
659 e_node.font = n.font
660 shift = nodenew(WHAT,PDF_LITERAL)
661 shift2 = nodenew(WHAT,PDF_LITERAL)
662 shift2.data = "Q 1 0 0 1 " .. e_node.width/factor .." 0 cm"
663 nodeinsertafter(head,n,e_node)
664
665 nodeinsertbefore(head,e_node,shift)
666 nodeinsertafter(head,e_node,shift2)
667
668 x_node = nodenew(KERN)
669 x_node.kern = -e_node.width
670 nodeinsertafter(head,shift2,x_node)
671 end
672
673 if (n.char == 228) then -- ä
674 shift.data = "q 0.5 0 0 0.5 " ..
675 -n.width/factor*0.85 .." ".. n.height/factor*0.75 .. " cm"
676 n.char = 97
677 end
678 if (n.char == 246) then -- ö
679 shift.data = "q 0.5 0 0 0.5 " ..
680 -n.width/factor*0.75 .." ".. n.height/factor*0.75 .. " cm"
681 n.char = 111
682 end
683 if (n.char == 252) then -- ü
684 shift.data = "q 0.5 0 0 0.5 " ..
685 -n.width/factor*0.75 .." ".. n.height/factor*0.75 .. " cm"
686 n.char = 117
687 end
688 end
689 end
690 return head
691 end
692 local separator = string.rep("=", 28)
693 local texiowrite_nl = texio.write_nl
694 pancaketext = function()
695 texiowrite_nl("Output written on "..tex.jobname..".pdf ("..status.total_pages.." chicken,".." eggs).")
696 texiowrite_nl(" ")
697 texiowrite_nl(separator)
698 texiowrite_nl("Soo ... you decided to use \\pancakenize.")
699 texiowrite_nl("That means you owe me a pancake!")
700 texiowrite_nl(" ")
701 texiowrite_nl("(This goes by document, not compilation.)")
702 texiowrite_nl(separator.."\n\n")
703 texiowrite_nl("Looking forward for my pancake! :)")
704 texiowrite_nl("\n\n")
705 end
706
707 randomfontslower = 1
708 randomfontsupper = 0
709 randomfonts = function(head)
710 local rfub
711 if randomfontsupper > 0 then -- fixme: this should be done only once, no? Or at every paragraph?
712 rfub = randomfontsupper -- user-specified value
713 else
714 rfub = font.max() -- or just take all fonts
715 end
716 for line in nodetraverseid(Hhead,head) do
717 for i in nodetraverseid(GLYPH,line.head) do
718 if not(randomfonts_onlytext) or node.has_attribute(i,luatexbase.attributes.randfontsattr) then
719 i.font = math.random(randomfontslower,rfub)
720 end
721 end
722 end
723 return head
724 end
725 uclcratio = 0.5 -- ratio between uppercase and lower case
726 randomuclc = function(head)
727 for i in nodetraverseid(GLYPH,head) do
728 if not(randomuclc_onlytext) or node.has_attribute(i,luatexbase.attributes.randuclcattr) then
729 if math.random() < uclcratio then
730 i.char = tex.uccode[i.char]
731 else
732 i.char = tex.lccode[i.char]
733 end
734 end
735 end
736 return head
737 end
738 randomchars = function(head)
739 for line in nodetraverseid(Hhead,head) do
740 for i in nodetraverseid(GLYPH,line.head) do
741 i.char = math.floor(math.random()*512)
742 end
743 end
744 return head
745 end
746 randomcolor_grey = false
747 randomcolor_onlytext = false --switch between local and global colorization
748 rainbowcolor = false
749
750 grey_lower = 0
751 grey_upper = 900
752
753 Rgb_lower = 1
754 rGb_lower = 1
755 rgB_lower = 1
756 Rgb_upper = 254
757 rGb_upper = 254
758 rgB_upper = 254
759 rainbow_step = 0.005
760 rainbow_Rgb = 1-rainbow_step -- we start in the red phase
761 rainbow_rGb = rainbow_step -- values x must always be 0 < x < 1
762 rainbow_rgB = rainbow_step
763 rainind = 1 -- 1:red,2:yellow,3:green,4:blue,5:purple
764 randomcolorstring = function()
765 if randomcolor_grey then
766 return (0.001*math.random(grey_lower,grey_upper)).." g"
767 elseif rainbowcolor then
768 if rainind == 1 then -- red
769 rainbow_rGb = rainbow_rGb + rainbow_step
770 if rainbow_rGb >= 1-rainbow_step then rainind = 2 end
771 elseif rainind == 2 then -- yellow
772 rainbow_Rgb = rainbow_Rgb - rainbow_step
773 if rainbow_Rgb <= rainbow_step then rainind = 3 end
774 elseif rainind == 3 then -- green
775 rainbow_rgB = rainbow_rgB + rainbow_step
776 rainbow_rGb = rainbow_rGb - rainbow_step
777 if rainbow_rGb <= rainbow_step then rainind = 4 end
778 elseif rainind == 4 then -- blue
779 rainbow_Rgb = rainbow_Rgb + rainbow_step
780 if rainbow_Rgb >= 1-rainbow_step then rainind = 5 end
781 else -- purple
782 rainbow_rgB = rainbow_rgB - rainbow_step
783 if rainbow_rgB <= rainbow_step then rainind = 1 end
784 end
785 return rainbow_Rgb.." "..rainbow_rGb.." "..rainbow_rgB.." rg"
786 else
787 Rgb = math.random(Rgb_lower,Rgb_upper)/255
788 rGb = math.random(rGb_lower,rGb_upper)/255
789 rgB = math.random(rgB_lower,rgB_upper)/255
790 return Rgb.." "..rGb.." "..rgB.." ".." rg"
791 end
792 end
793 randomcolor = function(head)
794 for line in nodetraverseid(0,head) do
795 for i in nodetraverseid(GLYPH,line.head) do
796 if not(randomcolor_onlytext) or
797 (node.has_attribute(i,luatexbase.attributes.randcolorattr))
798 then
799 color_push.data = randomcolorstring() -- color or grey string
800 line.head = nodeinsertbefore(line.head,i,nodecopy(color_push))
801 nodeinsertafter(line.head,i,nodecopy(color_pop))
802 end
803 end
804 end
805 return head
806 end
807 sailheight = 12
808 mastheight = 4
809 hullheight = 5
810 relnumber = 402
811 function relationship()
812 --%% check if there's a problem with any character in the current font
813 f = font.getfont(font.current())
814 fullfont = 1
815 for i = 8756,8842 do
816 if not(f.characters[i]) then texio.write_nl((i).." not available") fullfont = 0 end
817 end
818 --%% store the result of the check for later, then go on to construct the ship:
819 shipheight = sailheight + mastheight + hullheight
820 tex.print("\\parshape "..(shipheight)) --%% prepare the paragraph shape ...
821 for i =1,sailheight do
822 tex.print(" "..(4.5-i/3.8).."cm "..((i-0.5)/2.5).."cm ")
823 end
824 for i =1,mastheight do
825 tex.print(" "..(3.2).."cm "..(1).."cm ")
826 end
827 for i =1,hullheight do
828 tex.print(" "..((i-1)/2).."cm "..(10-i).."cm ")
829 end
830 tex.print("\\noindent") --%% ... up to here, then insert relations
831 for i=1,relnumber do
832 tex.print("\\ \\char"..math.random(8756,8842))
833 end
834 tex.print("\\break")
835 end
836 function cutparagraph(head)
837 local parsum = 0
838 for n in nodetraverseid(HLIST,head) do
839 parsum = parsum + 1
840 if parsum > shipheight then
841 node.remove(head,n)
842 end
843 end
844 return head
845 end
846 function missingcharstext()
847 if (fullfont == 0) then
848 local separator = string.rep("=", 28)
849 local texiowrite_nl = texio.write_nl
850 texiowrite_nl("Output written on "..tex.jobname..".pdf ("..status.total_pages.." chicken,".." eggs).")
851 texiowrite_nl(" ")
852 texiowrite_nl(separator)
853 texiowrite_nl("CAREFUL!!")
854 texiowrite_nl("\\relationship needs special characters (unicode points 8756 to 8842)")
855 texiowrite_nl("Your font does not support all of them!")
856 texiowrite_nl("consider using another one, e.g. the XITS font supplied with TeXlive.")
857 texiowrite_nl(separator .. "\n")
858 end
859 end
860 substitutewords_strings = {}
861
862 addtosubstitutions = function(input,output)
863 substitutewords_strings[#substitutewords_strings + 1] = {}
864 substitutewords_strings[#substitutewords_strings][1] = input
865 substitutewords_strings[#substitutewords_strings][2] = output
866 end
867
868 substitutewords = function(head)
869 for i = 1,#substitutewords_strings do
870 head = string.gsub(head,substitutewords_strings[i][1],substitutewords_strings[i][2])
871 end
872 return head
873 end
874 suppressonecharbreakpenaltynode = node.new(PENALTY)
875 suppressonecharbreakpenaltynode.penalty = 10000
876 function suppressonecharbreak(head)
877 for i in node.traverse_id(GLUE,head) do
878 if ((i.next) and (i.next.next.id == GLUE)) then
879 pen = node.copy(suppressonecharbreakpenaltynode)
880 node.insert_after(head,i.next,pen)
881 end
882 end
883
884 return head
885 end
886 tabularasa_onlytext = false
887
888 tabularasa = function(head)
889 local s = nodenew(KERN)
890 for line in nodetraverseid(HLIST,head) do
891 for n in nodetraverseid(GLYPH,line.head) do
892 if not(tabularasa_onlytext) or node.has_attribute(n,luatexbase.attributes.tabularasaattr) then
893 s.kern = n.width
894 nodeinsertafter(line.list,n,nodecopy(s))
895 line.head = noderemove(line.list,n)
896 end
897 end
898 end
899 return head
900 end
901 tanjanize = function(head)
902 local s = nodenew(KERN)
903 local m = nodenew(GLYPH,1)
904 local use_letter_i = true
905 scale = nodenew(WHAT,PDF_LITERAL)
906 scale2 = nodenew(WHAT,PDF_LITERAL)
907 scale.data = "0.5 0 0 0.5 0 0 cm"
908 scale2.data = "2 0 0 2 0 0 cm"
909
910 for line in nodetraverseid(HLIST,head) do
911 for n in nodetraverseid(GLYPH,line.head) do
912 mimicount = 0
913 tmpwidth = 0
914 while ((n.next.id == GLYPH) or (n.next.id == 11) or (n.next.id == 7) or (n.next.id == 0)) do --find end of a word
915 n.next = n.next.next
916 mimicount = mimicount + 1
917 tmpwidth = tmpwidth + n.width
918 end
919
920 mimi = {} -- constructing the node list.
921 mimi[0] = nodenew(GLYPH,1) -- only a dummy for the loop
922 for i = 1,string.len(mimicount) do
923 mimi[i] = nodenew(GLYPH,1)
924 mimi[i].font = font.current()
925 if(use_letter_i) then mimi[i].char = 109 else mimi[i].char = 105 end
926 use_letter_i = not(use_letter_i)
927 mimi[i-1].next = mimi[i]
928 end
929 --]]
930
931 line.head = nodeinsertbefore(line.head,n,nodecopy(scale))
932 nodeinsertafter(line.head,n,nodecopy(scale2))
933 s.kern = (tmpwidth*2-n.width)
934 nodeinsertafter(line.head,n,nodecopy(s))
935 end
936 end
937 return head
938 end
939 uppercasecolor_onlytext = false
940
941 uppercasecolor = function (head)
942 for line in nodetraverseid(Hhead,head) do
943 for upper in nodetraverseid(GLYPH,line.head) do
944 if not(uppercasecolor_onlytext) or node.has_attribute(upper,luatexbase.attributes.uppercasecolorattr) then
945 if (((upper.char > 64) and (upper.char < 91)) or
946 ((upper.char > 57424) and (upper.char < 57451))) then -- for small caps! nice ☺
947 color_push.data = randomcolorstring() -- color or grey string
948 line.head = nodeinsertbefore(line.head,upper,nodecopy(color_push))
949 nodeinsertafter(line.head,upper,nodecopy(color_pop))
950 end
951 end
952 end
953 end
954 return head
955 end
956 upsidedown = function(head)
957 local factor = 65536/0.99626
958 for line in nodetraverseid(Hhead,head) do
959 for n in nodetraverseid(GLYPH,line.head) do
960 if (upsidedownarray[n.char]) then
961 shift = nodenew(WHAT,PDF_LITERAL)
962 shift2 = nodenew(WHAT,PDF_LITERAL)
963 shift.data = "q 1 0 0 -1 0 " .. n.height/factor .." cm"
964 shift2.data = "Q 1 0 0 1 " .. n.width/factor .." 0 cm"
965 nodeinsertbefore(head,n,shift)
966 nodeinsertafter(head,n,shift2)
967 end
968 end
969 end
970 return head
971 end
972 keeptext = true
973 colorexpansion = true
974
975 colorstretch_coloroffset = 0.5
976 colorstretch_colorrange = 0.5
977 chickenize_rule_bad_height = 4/5 -- height and depth of the rules
978 chickenize_rule_bad_depth = 1/5
979
980 colorstretchnumbers = true
981 drawstretchthreshold = 0.1
982 drawexpansionthreshold = 0.9
983 colorstretch = function (head)
984 local f = font.getfont(font.current()).characters
985 for line in nodetraverseid(Hhead,head) do
986 local rule_bad = nodenew(RULE)
987
988 if colorexpansion then -- if also the font expansion should be shown
989 --%% here use first_glyph function!!
990 local g = line.head
991 n = node.first_glyph(line.head.next)
992 texio.write_nl(line.head.id)
993 texio.write_nl(line.head.next.id)
994 texio.write_nl(line.head.next.next.id)
995 texio.write_nl(n.id)
996 while not(g.id == GLYPH) and (g.next) do g = g.next end -- find first glyph on line. If line is empty, no glyph:
997 if (g.id == GLYPH) then -- read width only if g is a glyph!
998 exp_factor = g.expansion_factor/10000 --%% neato, luatex now directly gives me this!!
999 exp_color = colorstretch_coloroffset + (exp_factor*0.1) .. " g"
1000 texio.write_nl(exp_factor)
1001 rule_bad.width = 0.5*line.width -- we need two rules on each line!
1002 end
1003 else
1004 rule_bad.width = line.width -- only the space expansion should be shown, only one rule
1005 end
1006 rule_bad.height = tex.baselineskip.width*chickenize_rule_bad_height -- this should give a better output
1007 rule_bad.depth = tex.baselineskip.width*chickenize_rule_bad_depth
1008
1009 local glue_ratio = 0
1010 if line.glue_order == 0 then
1011 if line.glue_sign == 1 then
1012 glue_ratio = colorstretch_colorrange * math.min(line.glue_set,1)
1013 else
1014 glue_ratio = -colorstretch_colorrange * math.min(line.glue_set,1)
1015 end
1016 end
1017 color_push.data = colorstretch_coloroffset + glue_ratio .. " g"
1018
1019 -- set up output
1020 local p = line.head
1021
1022 -- a rule to immitate kerning all the way back
1023 local kern_back = nodenew(RULE)
1024 kern_back.width = -line.width
1025
1026 -- if the text should still be displayed, the color and box nodes are inserted additionally
1027 -- and the head is set to the color node
1028 if keeptext then
1029 line.head = nodeinsertbefore(line.head,line.head,nodecopy(color_push))
1030 else
1031 node.flush_list(p)
1032 line.head = nodecopy(color_push)
1033 end
1034 nodeinsertafter(line.head,line.head,rule_bad) -- then the rule
1035 nodeinsertafter(line.head,line.head.next,nodecopy(color_pop)) -- and then pop!
1036 tmpnode = nodeinsertafter(line.head,line.head.next.next,kern_back)
1037
1038 -- then a rule with the expansion color
1039 if colorexpansion then -- if also the stretch/shrink of letters should be shown
1040 color_push.data = exp_color
1041 nodeinsertafter(line.head,tmpnode,nodecopy(color_push))
1042 nodeinsertafter(line.head,tmpnode.next,nodecopy(rule_bad))
1043 nodeinsertafter(line.head,tmpnode.next.next,nodecopy(color_pop))
1044 end
1045 if colorstretchnumbers then
1046 j = 1
1047 glue_ratio_output = {}
1048 for s in string.utfvalues(math.abs(glue_ratio)) do -- using math.abs here gets us rid of the minus sign
1049 local char = unicode.utf8.char(s)
1050 glue_ratio_output[j] = nodenew(GLYPH,1)
1051 glue_ratio_output[j].font = font.current()
1052 glue_ratio_output[j].char = s
1053 j = j+1
1054 end
1055 if math.abs(glue_ratio) > drawstretchthreshold then
1056 if glue_ratio < 0 then color_push.data = "0.99 0 0 rg"
1057 else color_push.data = "0 0.99 0 rg" end
1058 else color_push.data = "0 0 0 rg"
1059 end
1060
1061 nodeinsertafter(line.head,node.tail(line.head),nodecopy(color_push))
1062 for i = 1,math.min(j-1,7) do
1063 nodeinsertafter(line.head,node.tail(line.head),glue_ratio_output[i])
1064 end
1065 nodeinsertafter(line.head,node.tail(line.head),nodecopy(color_pop))
1066 end -- end of stretch number insertion
1067 end
1068 return head
1069 end
1070
1071 function scorpionize_color(head)
1072 color_push.data = ".35 .55 .75 rg"
1073 nodeinsertafter(head,head,nodecopy(color_push))
1074 nodeinsertafter(head,node.tail(head),nodecopy(color_pop))
1075 return head
1076 end
1077 substlist = {}
1078 substlist[1488] = 64289
1079 substlist[1491] = 64290
1080 substlist[1492] = 64291
1081 substlist[1499] = 64292
1082 substlist[1500] = 64293
1083 substlist[1501] = 64294
1084 substlist[1512] = 64295
1085 substlist[1514] = 64296
1086 function variantjustification(head)
1087 math.randomseed(1)
1088 for line in nodetraverseid(Hhead,head) do
1089 if (line.glue_sign == 1 and line.glue_order == 0) then -- exclude the last line!
1090 substitutions_wide = {} -- we store all “expandable” letters of each line
1091 for n in nodetraverseid(GLYPH,line.head) do
1092 if (substlist[n.char]) then
1093 substitutions_wide[#substitutions_wide+1] = n
1094 end
1095 end
1096 line.glue_set = 0 -- deactivate normal glue expansion
1097 local width = node.dimensions(line.head) -- check the new width of the line
1098 local goal = line.width
1099 while (width < goal and #substitutions_wide > 0) do
1100 x = math.random(#substitutions_wide) -- choose randomly a glyph to be substituted
1101 oldchar = substitutions_wide[x].char
1102 substitutions_wide[x].char = substlist[substitutions_wide[x].char] -- substitute by wide letter
1103 width = node.dimensions(line.head) -- check if the line is too wide
1104 if width > goal then substitutions_wide[x].char = oldchar break end -- substitute back if the line would be too wide and break out of the loop
1105 table.remove(substitutions_wide,x) -- if further substitutions have to be done, remove the just substituted node from the list
1106 end
1107 end
1108 end
1109 return head
1110 end
1111 zebracolorarray = {}
1112 zebracolorarray_bg = {}
1113 zebracolorarray[1] = "0.1 g"
1114 zebracolorarray[2] = "0.9 g"
1115 zebracolorarray_bg[1] = "0.9 g"
1116 zebracolorarray_bg[2] = "0.1 g"
1117 function zebranize(head)
1118 zebracolor = 1
1119 for line in nodetraverseid(Hhead,head) do
1120 if zebracolor == #zebracolorarray then zebracolor = 0 end
1121 zebracolor = zebracolor + 1
1122 color_push.data = zebracolorarray[zebracolor]
1123 line.head = nodeinsertbefore(line.head,line.head,nodecopy(color_push))
1124 for n in nodetraverseid(GLYPH,line.head) do
1125 if n.next then else
1126 nodeinsertafter(line.head,n,nodecopy(color_pull))
1127 end
1128 end
1129
1130 local rule_zebra = nodenew(RULE)
1131 rule_zebra.width = line.width
1132 rule_zebra.height = tex.baselineskip.width*4/5
1133 rule_zebra.depth = tex.baselineskip.width*1/5
1134
1135 local kern_back = nodenew(RULE)
1136 kern_back.width = -line.width
1137
1138 color_push.data = zebracolorarray_bg[zebracolor]
1139 line.head = nodeinsertbefore(line.head,line.head,nodecopy(color_pop))
1140 line.head = nodeinsertbefore(line.head,line.head,nodecopy(color_push))
1141 nodeinsertafter(line.head,line.head,kern_back)
1142 nodeinsertafter(line.head,line.head,rule_zebra)
1143 end
1144 return (head)
1145 end
1146 --
1147 function pdf_print (...)
1148 for _, str in ipairs({...}) do
1149 pdf.print(str .. " ")
1150 end
1151 pdf.print("\n")
1152 end
1153
1154 function move (p1,p2)
1155 if (p2) then
1156 pdf_print(p1,p2,"m")
1157 else
1158 pdf_print(p1[1],p1[2],"m")
1159 end
1160 end
1161
1162 function line(p1,p2)
1163 if (p2) then
1164 pdf_print(p1,p2,"l")
1165 else
1166 pdf_print(p1[1],p1[2],"l")
1167 end
1168 end
1169
1170 function curve(p11,p12,p21,p22,p31,p32)
1171 if (p22) then
1172 p1,p2,p3 = {p11,p12},{p21,p22},{p31,p32}
1173 else
1174 p1,p2,p3 = p11,p12,p21
1175 end
1176 pdf_print(p1[1], p1[2],
1177 p2[1], p2[2],
1178 p3[1], p3[2], "c")
1179 end
1180
1181 function close ()
1182 pdf_print("h")
1183 end
1184
1185 drawwidth = 1
1186
1187 function linewidth (w)
1188 pdf_print(w,"w")
1189 end
1190
1191 function stroke ()
1192 pdf_print("S")
1193 end
1194 --
1195
1196 function strictcircle(center,radius)
1197 local left = {center[1] - radius, center[2]}
1198 local lefttop = {left[1], left[2] + 1.45*radius}
1199 local leftbot = {left[1], left[2] - 1.45*radius}
1200 local right = {center[1] + radius, center[2]}
1201 local righttop = {right[1], right[2] + 1.45*radius}
1202 local rightbot = {right[1], right[2] - 1.45*radius}
1203
1204 move (left)
1205 curve (lefttop, righttop, right)
1206 curve (rightbot, leftbot, left)
1207 stroke()
1208 end
1209
1210 sloppynessh = 5
1211 sloppynessv = 5
1212
1213 function disturb_point(point)
1214 return {point[1] + (math.random() - 1/2)*sloppynessh,
1215 point[2] + (math.random() - 1/2)*sloppynessv}
1216 end
1217
1218 function sloppycircle(center,radius)
1219 local left = disturb_point({center[1] - radius, center[2]})
1220 local lefttop = disturb_point({left[1], left[2] + 1.45*radius})
1221 local leftbot = {lefttop[1], lefttop[2] - 2.9*radius}
1222 local right = disturb_point({center[1] + radius, center[2]})
1223 local righttop = disturb_point({right[1], right[2] + 1.45*radius})
1224 local rightbot = disturb_point({right[1], right[2] - 1.45*radius})
1225
1226 local right_end = disturb_point(right)
1227
1228 move (right)
1229 curve (rightbot, leftbot, left)
1230 curve (lefttop, righttop, right_end)
1231 linewidth(drawwidth*(math.random()+0.5))
1232 stroke()
1233 end
1234
1235 function sloppyellipsis(center,radiusx,radiusy)
1236 local left = disturb_point({center[1] - radiusx, center[2]})
1237 local lefttop = disturb_point({left[1], left[2] + 1.45*radiusy})
1238 local leftbot = {lefttop[1], lefttop[2] - 2.9*radiusy}
1239 local right = disturb_point({center[1] + radiusx, center[2]})
1240 local righttop = disturb_point({right[1], right[2] + 1.45*radiusy})
1241 local rightbot = disturb_point({right[1], right[2] - 1.45*radiusy})
1242
1243 local right_end = disturb_point(right)
1244
1245 move (right)
1246 curve (rightbot, leftbot, left)
1247 curve (lefttop, righttop, right_end)
1248 linewidth(drawwidth*(math.random()+0.5))
1249 stroke()
1250 end
1251
1252 function sloppyline(start,stop)
1253 local start_line = disturb_point(start)
1254 local stop_line = disturb_point(stop)
1255 start = disturb_point(start)
1256 stop = disturb_point(stop)
1257 move(start) curve(start_line,stop_line,stop)
1258 linewidth(drawwidth*(math.random()+0.5))
1259 stroke()
1260 end
1261 --
1262 -- End of File `chickenize.lua'.