diff options
| author | 2026-11-08 08:19:44 +0000 | |
|---|---|---|
| committer | 2026-11-08 08:23:19 +0000 | |
| commit | 5be0e39d0ce97849d7722bd1ac98563c7014faf3 (patch) | |
| tree | 9dba821664337a6662a6da88dfe86291d269c36b /README.org | |
| download | lab-05-master.tar.gz | |
Diffstat (limited to 'README.org')
| -rw-r--r-- | README.org | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/README.org b/README.org new file mode 100644 index 0000000..347a060 --- /dev/null +++ b/README.org | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | #+title: Grammar with semantics | ||
| 2 | #+subtitle: Random-art generation | ||
| 3 | #+date: 2025H1 | ||
| 4 | |||
| 5 | * Overview | ||
| 6 | :PROPERTIES: | ||
| 7 | :CUSTOM_ID: overview | ||
| 8 | :END: | ||
| 9 | - Augmented a standard context-free BNF grammar with production rule | ||
| 10 | weights (probabilities) to control expression generation density and | ||
| 11 | visual aesthetics. | ||
| 12 | - Optimized and left-factorized the extended grammar to ensure | ||
| 13 | compatibility with deterministic parsing methods. | ||
| 14 | - Implemented a custom C-based lexer and recursive descent parser to | ||
| 15 | process rules, terminals, nonterminals, and probabilities. | ||
| 16 | - Engineered a stochastic expansion algorithm with depth thresholding | ||
| 17 | to synthesize complex GLSL fragment shaders driven by screen | ||
| 18 | coordinates, mouse input, and time. | ||
| 19 | - Configured distinct semantic weight profiles to generate varying | ||
| 20 | aesthetic styles (smooth vs. noise-heavy procedural patterns). | ||
| 21 | - Developed a custom GNU Emacs major mode (=bnf-mode.el=) for editing | ||
| 22 | BNF grammars. | ||
| 23 | |||
| 24 | * Documentation | ||
| 25 | :PROPERTIES: | ||
| 26 | :CUSTOM_ID: documentation | ||
| 27 | :END: | ||
| 28 | The exported report can be found at [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/report.pdf][this link]]. | ||
| 29 | |||
| 30 | * Showcase | ||
| 31 | :PROPERTIES: | ||
| 32 | :CUSTOM_ID: showcase | ||
| 33 | :END: | ||
| 34 | ** Example 1 | ||
| 35 | :PROPERTIES: | ||
| 36 | :CUSTOM_ID: example-1 | ||
| 37 | :UNNUMBERED: toc | ||
| 38 | :END: | ||
| 39 | *Input:* | ||
| 40 | #+begin_src bnf | ||
| 41 | <expr> ::= <value> | 0 "-" <expr> | 10 <binop> | <trig> | 0 "abs(" <expr> ")" | "sqrt(abs(" <expr> "))" | ||
| 42 | <value> ::= <coord> | 2 <mouse> | <time> | <const> | ||
| 43 | <coord> ::= 4 "c.x" | 3 "c.y" | ||
| 44 | <mouse> ::= 4 "m.x" | 3 "m.y" | ||
| 45 | <time> ::= "sin(t)" | 0 "cos(t)" | ||
| 46 | <const> ::= "." <digit> <digit> <digit> <digit> <digit> <digit> | ||
| 47 | <digit> ::= 2 "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | ||
| 48 | <binop> ::= 10 "(" <expr> " + " <expr> ")" | 5 "(" <expr> " - " <expr> ")" | 3 <expr> "*" <expr> | 0 "(" <expr> "/" <expr> ")" | ||
| 49 | <trig> ::= "sin(" <expr> ")" | "cos(" <expr> ")" | "tan(" <expr> ")" | ||
| 50 | #+end_src | ||
| 51 | |||
| 52 | *Output:* | ||
| 53 | #+begin_src glsl | ||
| 54 | (((((cos((tan(((cos(((((((cos(((((c.x + (((((sqrt(abs((((cos(sqrt(abs((sqrt(abs(tan(sin((((((((m.y*(sin((((((((((sqrt(abs(((( cos(((sqrt(abs(cos(c.x))) + ((((sqrt(abs(((m.y - ((((((.923344 - (.949094 + m.y)) + m.x) + sin(t)) - m.y)*m.x - sin(t)) + c.y)) - m.x)*sin(t))) - m.y) + m.y) + m.y)*m.y - sin(t))) - m.x)) + m.x) - sin(t)) + m.x))) - sin(t)) - m.x) + sin(t)) - .112088)*c.x - m.x) + .233916) - c.y) + m.x) + sin(t))) + m.x) + sin(t))*c.y*m.x + c.x) + .190365) - .887840) + sin(t)) + m.x) + m.y))*.291275))) - sin(t))))) + .287723) - m.x) - sin(t)))) - m.y) + sin(t))*c.x + m.y) + m.y) + .830306)*m.y*sin(t)) + c.y) + c.y)*m.y + c.x)) + m.x) - c.x) + m.x) - sin(t)) + c.y) + c.y)) + c.x) + c.y))*c.y*c.y + m.x)*.256283) - .585881) + .177134) + m.x) + c.x), (((((((((sqrt(abs(sin(((((((((cos((sqrt(abs((((((((((((sqrt(abs((((m.y - (sqrt(abs(m.x)) - sin((((((((m.x + ((((m.y - (((((((c.x + (((((((((m.x + .018174) - cos(sqrt(abs(((tan(m.x) - .689349) + m.x))))) - .420239) + m.x) + m.x) + sin(t)) + m.x) - m.x) + m.x)) - m.y)*sin(t) + sin(t)) + c.x) + .142664) - m.y) + m.x)) + c.x) + m.y)*.800054 - c.y)) - .509630) + m.y) - c.y) - sin(t))*m.x + .447933) - .237243)))) + m.x) + m.y)))*.733285 + c.x) - m.x) + m.x)*sin(t) + m.x) + .100814) + m.y) - m.x) - m.x) + sin(t)) + m.x) + .907417))) + m.y))*.388498 + sin(t)) + .016879) + c.y) + sin(t)) + .905070) - c.x) - c.x) + m.x)))) + .531642) - sin(t)) + m.y) + m.y) - .722737) + sin(t)) - c.y) - m.y) + m.x), sqrt(abs((m.x - tan(tan((sqrt(abs((((c.x - (((((((sin(sqrt(abs((sqrt(abs((((((m.y - (sin(((((sqrt(abs(((((sin(t) + (((((((((((((sin(t) - ((((((c.y*(((m.x + .127801) - (sqrt(abs((sin(t) + m.x))) + .900278)) + m.y)*m.y - m.x) + .191150) - m.x) + c.y)*sin(t) + .760660) + m.y)) + m.x) + m.y) - .470661) + .239425) + m.x) + m.y) - .085803) + m.x) - m.y) + m.x) + .304005) - .044509)) + m.x) + m.x) + c.x)*.156629)) - m.y) + m.x) - sin(t)) - m.x))*.501841 - m.x)) + m.y)*m.y + .098450) + m.x) - m.x))) + sin(t))))) - c.y) + m.y) + .005222)*m.y + m.x) + m.x) + .030531) + m.x)) + m.x) + c.x))) + m.x)))*c.x)))*m.x) | ||
| 55 | #+end_src | ||
| 56 | |||
| 57 | *Example frame:* | ||
| 58 | #+attr_html: :width 100% | ||
| 59 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/10.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/10.png]] | ||
| 60 | |||
| 61 | ** Example 2 | ||
| 62 | :PROPERTIES: | ||
| 63 | :CUSTOM_ID: example-2 | ||
| 64 | :UNNUMBERED: toc | ||
| 65 | :END: | ||
| 66 | *Input:* | ||
| 67 | #+begin_src bnf | ||
| 68 | <expr> ::= <value> | 0 "-" <expr> | 10 <binop> | 3 <trig> | 1 "abs(" <expr> ")" | 5 "sqrt(abs(" <expr> "))" | ||
| 69 | <value> ::= 3 <coord> | <mouse> | <time> | <const> | ||
| 70 | <coord> ::= 4 "c.x" | 3 "c.y" | ||
| 71 | <mouse> ::= 4 "m.x" | 3 "m.y" | ||
| 72 | <time> ::= "sin(t)" | "cos(t)" | ||
| 73 | <const> ::= "." <digit> <digit> <digit> <digit> <digit> <digit> | ||
| 74 | <digit> ::= 10 "0" | 9 "1" | 8 "2" | 7 "3" | 6 "4" | 5 "5" | 4 "6" | 3 "7" | 2 "8" | 1 "9" | ||
| 75 | <binop> ::= 1 "(" <expr> " + " <expr> ")" | 30 "(" <expr> " - " <expr> ")" | 5 <expr> "*" <expr> | 7 "(" <expr> "/" <expr> ")" | ||
| 76 | <trig> ::= "sin(" <expr> ")" | "cos(" <expr> ")" | 0 "tan(" <expr> ")" | ||
| 77 | #+end_src | ||
| 78 | |||
| 79 | *Output:* | ||
| 80 | #+begin_src glsl | ||
| 81 | ((sqrt(abs((sqrt(abs(sqrt(abs(((c.x/sqrt(abs(sqrt(abs(((((abs(((((((((abs(sqrt(abs(sin(((( cos(((cos(sqrt(abs(sqrt(abs(((sin((sqrt(abs(((sqrt(abs(sqrt(abs((((sqrt(abs((sqrt( abs((((sqrt(abs(sqrt(abs(((((((sqrt(abs(c.x))*(sqrt(abs((sqrt(abs(sin(abs((((c.x - (abs(abs((((sqrt(abs((sqrt(abs(sqrt(abs(((sqrt(abs((sin(sin(sin(((sin((cos(((cos(abs((( sqrt(abs(cos(c.x)))*cos((c.y - c.x)) - m.y) - c.x))) - c.x)/c.x)) - c.y)) - c.y) - sin(t)))))/.024006))) - c.x) - .183139))))) - m.x))) - c.y)/sin(t)) - sin(t)))) - sin(t))) - c.x) - m.y))))) - m.x))) - c.x) - c.x) - sin(t)) - c.x) - cos(t)) - c.y)/c.x)*m.x)))) - .223574) - c.x) - cos(t)))) - c.y)))/m.x) - c.x) - m.x))))) - c.x) - cos(t)))) - m.x)) - c.x) - c.x)))))) - c.x) - c.y)) - sin(t)) - .406444) - c.y))))) - m.y)/m.x) - c.x) - c.y)/cos(t))/.262350) - sin(t)) - c.y)) - c.x) - c.x)/c.x)/m.x)))))) - cos(t)))))) - c.x))) - c.x), cos(t), sin(((((((((cos(sqrt(abs((sqrt(abs(c.y)) - c.x)))) - (sqrt(abs((sqrt(abs(m.x)) - ((cos(sqrt(abs((m.y - c.y)))) - sqrt(abs(abs((sqrt(abs((((abs((sqrt(abs(sqrt(abs(cos((m.y - ((.254220 - (sqrt(abs(sqrt(abs(((m.y - sin(sqrt(abs((cos(sqrt(abs(sqrt(abs(sin(sqrt(abs(abs(sin(((((sqrt(abs(m.x)) - c.y)*.213340*c.x*cos(t) - .877721)/m.y) - .632123))))))))))) - c.x))))) - c.x))))) - cos(t))) + c.y))))))) - sin(t))) - c.y)/c.x) - c.x))) - c.y)))))*c.x - c.y))))/.123224))/m.x) - c.y)*.273026/c.x)/c.y) - cos(t)) - m.x)/m.y))) | ||
| 82 | #+end_src | ||
| 83 | |||
| 84 | *Example frame:* | ||
| 85 | #+attr_html: :width 100% | ||
| 86 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/13.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/13.png]] | ||
| 87 | |||
| 88 | ** Gallery | ||
| 89 | :PROPERTIES: | ||
| 90 | :CUSTOM_ID: gallery | ||
| 91 | :UNNUMBERED: toc | ||
| 92 | :END: | ||
| 93 | #+attr_html: :width 100% | ||
| 94 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/01.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/01.png]] | ||
| 95 | |||
| 96 | #+attr_html: :width 100% | ||
| 97 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/02.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/02.png]] | ||
| 98 | |||
| 99 | #+attr_html: :width 100% | ||
| 100 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/03.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/03.png]] | ||
| 101 | |||
| 102 | #+attr_html: :width 100% | ||
| 103 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/04.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/04.png]] | ||
| 104 | |||
| 105 | #+attr_html: :width 100% | ||
| 106 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/05.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/05.png]] | ||
| 107 | |||
| 108 | #+attr_html: :width 100% | ||
| 109 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/06.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/06.png]] | ||
| 110 | |||
| 111 | #+attr_html: :width 100% | ||
| 112 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/07.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/07.png]] | ||
| 113 | |||
| 114 | #+attr_html: :width 100% | ||
| 115 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/08.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/08.png]] | ||
| 116 | |||
| 117 | #+attr_html: :width 100% | ||
| 118 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/09.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/09.png]] | ||
| 119 | |||
| 120 | #+attr_html: :width 100% | ||
| 121 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/11.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/11.png]] | ||
| 122 | |||
| 123 | #+attr_html: :width 100% | ||
| 124 | [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/12.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/12.png]] | ||
| 125 | |||
| 126 | * Unlicense | ||
| 127 | :PROPERTIES: | ||
| 128 | :CUSTOM_ID: unlicense | ||
| 129 | :END: | ||
| 130 | #+include: UNLICENSE verse | ||
