aboutsummaryrefslogtreecommitdiff
path: root/README.org
blob: 347a0609d4ccec912bdef03abc727c0e6c6da925 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#+title: Grammar with semantics
#+subtitle: Random-art generation
#+date: 2025H1

* Overview
:PROPERTIES:
:CUSTOM_ID: overview
:END:
- Augmented a standard context-free BNF grammar with production rule
  weights (probabilities) to control expression generation density and
  visual aesthetics.
- Optimized and left-factorized the extended grammar to ensure
  compatibility with deterministic parsing methods.
- Implemented a custom C-based lexer and recursive descent parser to
  process rules, terminals, nonterminals, and probabilities.
- Engineered a stochastic expansion algorithm with depth thresholding
  to synthesize complex GLSL fragment shaders driven by screen
  coordinates, mouse input, and time.
- Configured distinct semantic weight profiles to generate varying
  aesthetic styles (smooth vs. noise-heavy procedural patterns).
- Developed a custom GNU Emacs major mode (=bnf-mode.el=) for editing
  BNF grammars.

* Documentation
:PROPERTIES:
:CUSTOM_ID: documentation
:END:
The exported report can be found at [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-05/report.pdf][this link]].

* Showcase
:PROPERTIES:
:CUSTOM_ID: showcase
:END:
** Example 1
:PROPERTIES:
:CUSTOM_ID: example-1
:UNNUMBERED: toc
:END:
*Input:*
#+begin_src bnf
 <expr> ::= <value> | 0 "-" <expr> | 10 <binop> | <trig> | 0 "abs(" <expr> ")" | "sqrt(abs(" <expr> "))"
<value> ::= <coord> | 2 <mouse> | <time> | <const>
<coord> ::= 4 "c.x" | 3 "c.y"
<mouse> ::= 4 "m.x" | 3 "m.y"
 <time> ::= "sin(t)" | 0 "cos(t)"
<const> ::= "." <digit> <digit> <digit> <digit> <digit> <digit>
<digit> ::= 2 "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<binop> ::= 10 "(" <expr> " + " <expr> ")" | 5 "(" <expr> " - " <expr> ")" | 3 <expr> "*" <expr> | 0 "(" <expr> "/" <expr> ")"
 <trig> ::= "sin(" <expr> ")" | "cos(" <expr> ")" | "tan(" <expr> ")"
#+end_src

*Output:*
#+begin_src glsl
(((((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)
#+end_src

*Example frame:*
#+attr_html: :width 100%
[[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]]

** Example 2
:PROPERTIES:
:CUSTOM_ID: example-2
:UNNUMBERED: toc
:END:
*Input:*
#+begin_src bnf
 <expr> ::= <value> | 0 "-" <expr> | 10 <binop> | 3 <trig> | 1 "abs(" <expr> ")" | 5 "sqrt(abs(" <expr> "))"
<value> ::= 3 <coord> | <mouse> | <time> | <const>
<coord> ::= 4 "c.x" | 3 "c.y"
<mouse> ::= 4 "m.x" | 3 "m.y"
 <time> ::= "sin(t)" | "cos(t)"
<const> ::= "." <digit> <digit> <digit> <digit> <digit> <digit>
<digit> ::= 10 "0" | 9 "1" | 8 "2" | 7 "3" | 6 "4" | 5 "5" | 4 "6" | 3 "7" | 2 "8" | 1 "9"
<binop> ::= 1 "(" <expr> " + " <expr> ")" | 30 "(" <expr> " - " <expr> ")" | 5 <expr> "*" <expr> | 7 "(" <expr> "/" <expr> ")"
 <trig> ::= "sin(" <expr> ")" | "cos(" <expr> ")" | 0 "tan(" <expr> ")"
#+end_src

*Output:*
#+begin_src glsl
((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)))
#+end_src

*Example frame:*
#+attr_html: :width 100%
[[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]]

** Gallery
:PROPERTIES:
:CUSTOM_ID: gallery
:UNNUMBERED: toc
:END:
#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

#+attr_html: :width 100%
[[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]]

* Unlicense
:PROPERTIES:
:CUSTOM_ID: unlicense
:END:
#+include: UNLICENSE verse