Browse Source

Regex, Inline, Enum, Operator, Mario

pull/140/head
Jure Šorn 2 years ago
parent
commit
770d1fa487
3 changed files with 46 additions and 50 deletions
  1. 27
      README.md
  2. 49
      index.html
  3. 20
      parse.js

27
README.md

@ -363,7 +363,7 @@ import re
* **Search() and match() return None if they can't find a match.** * **Search() and match() return None if they can't find a match.**
* **Argument `'flags=re.IGNORECASE'` can be used with all functions.** * **Argument `'flags=re.IGNORECASE'` can be used with all functions.**
* **Argument `'flags=re.MULTILINE'` makes `'^'` and `'$'` match the start/end of each line.** * **Argument `'flags=re.MULTILINE'` makes `'^'` and `'$'` match the start/end of each line.**
* **Argument `'flags=re.DOTALL'` makes dot also accept the `'\n'`.**
* **Argument `'flags=re.DOTALL'` makes `'.'` also accept the `'\n'`.**
* **Use `r'\1'` or `'\\1'` for backreference (`'\1'` returns a character with octal code 1).** * **Use `r'\1'` or `'\\1'` for backreference (`'\1'` returns a character with octal code 1).**
* **Add `'?'` after `'*'` and `'+'` to make them non-greedy.** * **Add `'?'` after `'*'` and `'+'` to make them non-greedy.**
@ -787,7 +787,7 @@ Inline
``` ```
```python ```python
>>> [a if a else 'zero' for a in (0, 1, 2, 3)]
>>> [a if a else 'zero' for a in (0, 1, 2, 3)] # `any([0, '', [], None]) == False`
['zero', 1, 2, 3] ['zero', 1, 2, 3]
``` ```
@ -800,8 +800,8 @@ point = Point(0, 0) # Returns its instance.
```python ```python
from enum import Enum from enum import Enum
Direction = Enum('Direction', 'n e s w') # Creates an enum.
direction = Direction.n # Returns its member.
Direction = Enum('Direction', 'N E S W') # Creates an enum.
direction = Direction.N # Returns its member.
``` ```
```python ```python
@ -1354,9 +1354,9 @@ def get_next_member(member):
### Inline ### Inline
```python ```python
Cutlery = Enum('Cutlery', 'fork knife spoon')
Cutlery = Enum('Cutlery', ['fork', 'knife', 'spoon'])
Cutlery = Enum('Cutlery', {'fork': 1, 'knife': 2, 'spoon': 3})
Cutlery = Enum('Cutlery', 'FORK KNIFE SPOON')
Cutlery = Enum('Cutlery', ['FORK', 'KNIFE', 'SPOON'])
Cutlery = Enum('Cutlery', {'FORK': 1, 'KNIFE': 2, 'SPOON': 3})
``` ```
#### User-defined functions cannot be values, so they must be wrapped: #### User-defined functions cannot be values, so they must be wrapped:
@ -1365,7 +1365,6 @@ from functools import partial
LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r), LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r),
'OR': partial(lambda l, r: l or r)}) 'OR': partial(lambda l, r: l or r)})
``` ```
* **Member names are in all caps because trying to access a member that is named after a reserved keyword raises SyntaxError.**
Exceptions Exceptions
@ -2156,10 +2155,10 @@ Operator
**Module of functions that provide the functionality of operators.** **Module of functions that provide the functionality of operators.**
```python ```python
import operator as op import operator as op
<el> = op.add/sub/mul/truediv/floordiv/mod(<el>, <el>) # +, -, *, /, //, %
<int/set> = op.and_/or_/xor(<int/set>, <int/set>) # &, |, ^
<bool> = op.eq/ne/lt/le/gt/ge(<sortable>, <sortable>) # ==, !=, <, <=, >, >=
<func> = op.itemgetter/attrgetter/methodcaller(<obj>) # [index/key], .name, .name()
<obj> = op.add/sub/mul/truediv/floordiv/mod(<obj>, <obj>) # +, -, *, /, //, %
<int/set> = op.and_/or_/xor(<int/set>, <int/set>) # &, |, ^
<bool> = op.eq/ne/lt/le/gt/ge(<sortable>, <sortable>) # ==, !=, <, <=, >, >=
<func> = op.itemgetter/attrgetter/methodcaller(<obj> [, ...]) # [index/key], .name, .name()
``` ```
```python ```python
@ -3071,7 +3070,7 @@ def run(screen, images, mario, tiles):
def update_speed(mario, tiles, pressed): def update_speed(mario, tiles, pressed):
x, y = mario.spd x, y = mario.spd
x += 2 * ((D.e in pressed) - (D.w in pressed)) x += 2 * ((D.e in pressed) - (D.w in pressed))
x -= (x > 0) - (x < 0)
x += (x < 0) - (x > 0)
y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10 y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10
mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y))) mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y)))
@ -3080,7 +3079,7 @@ def update_position(mario, tiles):
n_steps = max(abs(s) for s in mario.spd) n_steps = max(abs(s) for s in mario.spd)
for _ in range(n_steps): for _ in range(n_steps):
mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles)) mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))
x, y = x + mario.spd.x / n_steps, y + mario.spd.y / n_steps
x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)
mario.rect.topleft = x, y mario.rect.topleft = x, y
def get_boundaries(rect, tiles): def get_boundaries(rect, tiles):

49
index.html

@ -54,7 +54,7 @@
<body> <body>
<header> <header>
<aside>October 2, 2022</aside>
<aside>December 16, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a> <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header> </header>
@ -343,7 +343,7 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
<li><strong>Search() and match() return None if they can't find a match.</strong></li> <li><strong>Search() and match() return None if they can't find a match.</strong></li>
<li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.IGNORECASE'</span></code> can be used with all functions.</strong></li> <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.IGNORECASE'</span></code> can be used with all functions.</strong></li>
<li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.MULTILINE'</span></code> makes <code class="python hljs"><span class="hljs-string">'^'</span></code> and <code class="python hljs"><span class="hljs-string">'$'</span></code> match the start/end of each line.</strong></li> <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.MULTILINE'</span></code> makes <code class="python hljs"><span class="hljs-string">'^'</span></code> and <code class="python hljs"><span class="hljs-string">'$'</span></code> match the start/end of each line.</strong></li>
<li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.DOTALL'</span></code> makes dot also accept the <code class="python hljs"><span class="hljs-string">'\n'</span></code>.</strong></li>
<li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.DOTALL'</span></code> makes <code class="python hljs"><span class="hljs-string">'.'</span></code> also accept the <code class="python hljs"><span class="hljs-string">'\n'</span></code>.</strong></li>
<li><strong>Use <code class="python hljs"><span class="hljs-string">r'\1'</span></code> or <code class="python hljs"><span class="hljs-string">'\\1'</span></code> for backreference (<code class="python hljs"><span class="hljs-string">'\1'</span></code> returns a character with octal code 1).</strong></li> <li><strong>Use <code class="python hljs"><span class="hljs-string">r'\1'</span></code> or <code class="python hljs"><span class="hljs-string">'\\1'</span></code> for backreference (<code class="python hljs"><span class="hljs-string">'\1'</span></code> returns a character with octal code 1).</strong></li>
<li><strong>Add <code class="python hljs"><span class="hljs-string">'?'</span></code> after <code class="python hljs"><span class="hljs-string">'*'</span></code> and <code class="python hljs"><span class="hljs-string">'+'</span></code> to make them non-greedy.</strong></li> <li><strong>Add <code class="python hljs"><span class="hljs-string">'?'</span></code> after <code class="python hljs"><span class="hljs-string">'*'</span></code> and <code class="python hljs"><span class="hljs-string">'+'</span></code> to make them non-greedy.</strong></li>
</ul> </ul>
@ -674,7 +674,7 @@ func(*args, **kwargs)
<div><h3 id="conditionalexpression">Conditional Expression</h3><pre><code class="python language-python hljs">&lt;obj&gt; = &lt;exp&gt; <span class="hljs-keyword">if</span> &lt;condition&gt; <span class="hljs-keyword">else</span> &lt;exp&gt; <span class="hljs-comment"># Only one expression gets evaluated.</span> <div><h3 id="conditionalexpression">Conditional Expression</h3><pre><code class="python language-python hljs">&lt;obj&gt; = &lt;exp&gt; <span class="hljs-keyword">if</span> &lt;condition&gt; <span class="hljs-keyword">else</span> &lt;exp&gt; <span class="hljs-comment"># Only one expression gets evaluated.</span>
</code></pre></div> </code></pre></div>
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>[a <span class="hljs-keyword">if</span> a <span class="hljs-keyword">else</span> <span class="hljs-string">'zero'</span> <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> (<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)]
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>[a <span class="hljs-keyword">if</span> a <span class="hljs-keyword">else</span> <span class="hljs-string">'zero'</span> <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> (<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)] <span class="hljs-comment"># `any([0, '', [], None]) == False`</span>
[<span class="hljs-string">'zero'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>] [<span class="hljs-string">'zero'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
</code></pre> </code></pre>
<div><h3 id="namedtupleenumdataclass">Named Tuple, Enum, Dataclass</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> namedtuple <div><h3 id="namedtupleenumdataclass">Named Tuple, Enum, Dataclass</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> namedtuple
@ -683,8 +683,8 @@ point = Point(<span class="hljs-number">0</span>, <span class="hljs-number">0</s
</code></pre></div> </code></pre></div>
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum <pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum
Direction = Enum(<span class="hljs-string">'Direction'</span>, <span class="hljs-string">'n e s w'</span>) <span class="hljs-comment"># Creates an enum.</span>
direction = Direction.n <span class="hljs-comment"># Returns its member.</span>
Direction = Enum(<span class="hljs-string">'Direction'</span>, <span class="hljs-string">'N E S W'</span>) <span class="hljs-comment"># Creates an enum.</span>
direction = Direction.N <span class="hljs-comment"># Returns its member.</span>
</code></pre> </code></pre>
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> make_dataclass <pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> make_dataclass
Player = make_dataclass(<span class="hljs-string">'Player'</span>, [<span class="hljs-string">'loc'</span>, <span class="hljs-string">'dir'</span>]) <span class="hljs-comment"># Creates a class.</span> Player = make_dataclass(<span class="hljs-string">'Player'</span>, [<span class="hljs-string">'loc'</span>, <span class="hljs-string">'dir'</span>]) <span class="hljs-comment"># Creates a class.</span>
@ -1162,9 +1162,9 @@ random_member = random.choice(list(&lt;enum&gt;))
index = (members.index(member) + <span class="hljs-number">1</span>) % len(members) index = (members.index(member) + <span class="hljs-number">1</span>) % len(members)
<span class="hljs-keyword">return</span> members[index] <span class="hljs-keyword">return</span> members[index]
</code></pre> </code></pre>
<div><h3 id="inline-2">Inline</h3><pre><code class="python language-python hljs">Cutlery = Enum(<span class="hljs-string">'Cutlery'</span>, <span class="hljs-string">'fork knife spoon'</span>)
Cutlery = Enum(<span class="hljs-string">'Cutlery'</span>, [<span class="hljs-string">'fork'</span>, <span class="hljs-string">'knife'</span>, <span class="hljs-string">'spoon'</span>])
Cutlery = Enum(<span class="hljs-string">'Cutlery'</span>, {<span class="hljs-string">'fork'</span>: <span class="hljs-number">1</span>, <span class="hljs-string">'knife'</span>: <span class="hljs-number">2</span>, <span class="hljs-string">'spoon'</span>: <span class="hljs-number">3</span>})
<div><h3 id="inline-2">Inline</h3><pre><code class="python language-python hljs">Cutlery = Enum(<span class="hljs-string">'Cutlery'</span>, <span class="hljs-string">'FORK KNIFE SPOON'</span>)
Cutlery = Enum(<span class="hljs-string">'Cutlery'</span>, [<span class="hljs-string">'FORK'</span>, <span class="hljs-string">'KNIFE'</span>, <span class="hljs-string">'SPOON'</span>])
Cutlery = Enum(<span class="hljs-string">'Cutlery'</span>, {<span class="hljs-string">'FORK'</span>: <span class="hljs-number">1</span>, <span class="hljs-string">'KNIFE'</span>: <span class="hljs-number">2</span>, <span class="hljs-string">'SPOON'</span>: <span class="hljs-number">3</span>})
</code></pre></div> </code></pre></div>
<div><h4 id="userdefinedfunctionscannotbevaluessotheymustbewrapped">User-defined functions cannot be values, so they must be wrapped:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial <div><h4 id="userdefinedfunctionscannotbevaluessotheymustbewrapped">User-defined functions cannot be values, so they must be wrapped:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial
@ -1172,9 +1172,6 @@ LogicOp = Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-st
<span class="hljs-string">'OR'</span>: partial(<span class="hljs-keyword">lambda</span> l, r: l <span class="hljs-keyword">or</span> r)}) <span class="hljs-string">'OR'</span>: partial(<span class="hljs-keyword">lambda</span> l, r: l <span class="hljs-keyword">or</span> r)})
</code></pre></div> </code></pre></div>
<ul>
<li><strong>Member names are in all caps because trying to access a member that is named after a reserved keyword raises SyntaxError.</strong></li>
</ul>
<div><h2 id="exceptions"><a href="#exceptions" name="exceptions">#</a>Exceptions</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">try</span>: <div><h2 id="exceptions"><a href="#exceptions" name="exceptions">#</a>Exceptions</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">try</span>:
&lt;code&gt; &lt;code&gt;
<span class="hljs-keyword">except</span> &lt;exception&gt;: <span class="hljs-keyword">except</span> &lt;exception&gt;:
@ -1780,10 +1777,10 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-
&lt;el&gt; = &lt;Queue&gt;.get_nowait() <span class="hljs-comment"># Raises queue.Empty exception if empty.</span> &lt;el&gt; = &lt;Queue&gt;.get_nowait() <span class="hljs-comment"># Raises queue.Empty exception if empty.</span>
</code></pre> </code></pre>
<div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> operator <span class="hljs-keyword">as</span> op <div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> operator <span class="hljs-keyword">as</span> op
&lt;el&gt; = op.add/sub/mul/truediv/floordiv/mod(&lt;el&gt;, &lt;el&gt;) <span class="hljs-comment"># +, -, *, /, //, %</span>
&lt;int/set&gt; = op.and_/or_/xor(&lt;int/set&gt;, &lt;int/set&gt;) <span class="hljs-comment"># &amp;, |, ^</span>
&lt;bool&gt; = op.eq/ne/lt/le/gt/ge(&lt;sortable&gt;, &lt;sortable&gt;) <span class="hljs-comment"># ==, !=, &lt;, &lt;=, &gt;, &gt;=</span>
&lt;func&gt; = op.itemgetter/attrgetter/methodcaller(&lt;obj&gt;) <span class="hljs-comment"># [index/key], .name, .name()</span>
&lt;obj&gt; = op.add/sub/mul/truediv/floordiv/mod(&lt;obj&gt;, &lt;obj&gt;) <span class="hljs-comment"># +, -, *, /, //, %</span>
&lt;int/set&gt; = op.and_/or_/xor(&lt;int/set&gt;, &lt;int/set&gt;) <span class="hljs-comment"># &amp;, |, ^</span>
&lt;bool&gt; = op.eq/ne/lt/le/gt/ge(&lt;sortable&gt;, &lt;sortable&gt;) <span class="hljs-comment"># ==, !=, &lt;, &lt;=, &gt;, &gt;=</span>
&lt;func&gt; = op.itemgetter/attrgetter/methodcaller(&lt;obj&gt; [, ...]) <span class="hljs-comment"># [index/key], .name, .name()</span>
</code></pre></div> </code></pre></div>
@ -1861,11 +1858,11 @@ type(MyMetaClass) == type <span class="hljs-comment"># MyMetaClass is
<pre><code class="text language-text">┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━┓ <pre><code class="text language-text">┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━┓
┃ Classes │ Metaclasses ┃ ┃ Classes │ Metaclasses ┃
┠─────────────┼─────────────┨ ┠─────────────┼─────────────┨
┃ MyClass ──→ MyMetaClass ┃
┃ │
┃ object ─────→ type ←╮ ┃
┃ │ ╰──╯ ┃
┃ str ─────────╯ ┃
┃ MyClass ←──╴MyMetaClass ┃
┃ │
┃ object ←─────╴type ←╮ ┃
┃ │ ╰──╯ ┃
┃ str ─────────╯ ┃
┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛
</code></pre> </code></pre>
<div><h3 id="inheritancediagram">Inheritance Diagram</h3><pre><code class="python language-python hljs">MyClass.__base__ == object <span class="hljs-comment"># MyClass is a subclass of object.</span> <div><h3 id="inheritancediagram">Inheritance Diagram</h3><pre><code class="python language-python hljs">MyClass.__base__ == object <span class="hljs-comment"># MyClass is a subclass of object.</span>
@ -1876,9 +1873,9 @@ MyMetaClass.__base__ == type <span class="hljs-comment"># MyMetaClass is
┃ Classes │ Metaclasses ┃ ┃ Classes │ Metaclasses ┃
┠─────────────┼─────────────┨ ┠─────────────┼─────────────┨
┃ MyClass │ MyMetaClass ┃ ┃ MyClass │ MyMetaClass ┃
↓ │ ↓
┃ object ←───── type ┃
│ ┃
↑ │ ↑
┃ object╶─────→ type ┃
│ ┃
┃ str │ ┃ ┃ str │ ┃
┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛
</code></pre> </code></pre>
@ -2506,7 +2503,7 @@ W, H, MAX_S = <span class="hljs-number">50</span>, <span class="hljs-number">50<
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update_speed</span><span class="hljs-params">(mario, tiles, pressed)</span>:</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update_speed</span><span class="hljs-params">(mario, tiles, pressed)</span>:</span>
x, y = mario.spd x, y = mario.spd
x += <span class="hljs-number">2</span> * ((D.e <span class="hljs-keyword">in</span> pressed) - (D.w <span class="hljs-keyword">in</span> pressed)) x += <span class="hljs-number">2</span> * ((D.e <span class="hljs-keyword">in</span> pressed) - (D.w <span class="hljs-keyword">in</span> pressed))
x -= (x &gt; <span class="hljs-number">0</span>) - (x &lt; <span class="hljs-number">0</span>)
x += (x &lt; <span class="hljs-number">0</span>) - (x &gt; <span class="hljs-number">0</span>)
y += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> D.s <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> get_boundaries(mario.rect, tiles) <span class="hljs-keyword">else</span> (D.n <span class="hljs-keyword">in</span> pressed) * <span class="hljs-number">-10</span> y += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> D.s <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> get_boundaries(mario.rect, tiles) <span class="hljs-keyword">else</span> (D.n <span class="hljs-keyword">in</span> pressed) * <span class="hljs-number">-10</span>
mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y))) mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y)))
@ -2515,7 +2512,7 @@ W, H, MAX_S = <span class="hljs-number">50</span>, <span class="hljs-number">50<
n_steps = max(abs(s) <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> mario.spd) n_steps = max(abs(s) <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> mario.spd)
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(n_steps): <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(n_steps):
mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles)) mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))
x, y = x + mario.spd.x / n_steps, y + mario.spd.y / n_steps
x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)
mario.rect.topleft = x, y mario.rect.topleft = x, y
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_boundaries</span><span class="hljs-params">(rect, tiles)</span>:</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_boundaries</span><span class="hljs-params">(rect, tiles)</span>:</span>
@ -2910,7 +2907,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer> <footer>
<aside>October 2, 2022</aside>
<aside>December 16, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a> <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer> </footer>

20
parse.js

@ -208,7 +208,7 @@ const MARIO =
'<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update_speed</span><span class="hljs-params">(mario, tiles, pressed)</span>:</span>\n' + '<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update_speed</span><span class="hljs-params">(mario, tiles, pressed)</span>:</span>\n' +
' x, y = mario.spd\n' + ' x, y = mario.spd\n' +
' x += <span class="hljs-number">2</span> * ((D.e <span class="hljs-keyword">in</span> pressed) - (D.w <span class="hljs-keyword">in</span> pressed))\n' + ' x += <span class="hljs-number">2</span> * ((D.e <span class="hljs-keyword">in</span> pressed) - (D.w <span class="hljs-keyword">in</span> pressed))\n' +
' x -= (x &gt; <span class="hljs-number">0</span>) - (x &lt; <span class="hljs-number">0</span>)\n' +
' x += (x &lt; <span class="hljs-number">0</span>) - (x &gt; <span class="hljs-number">0</span>)\n' +
' y += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> D.s <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> get_boundaries(mario.rect, tiles) <span class="hljs-keyword">else</span> (D.n <span class="hljs-keyword">in</span> pressed) * <span class="hljs-number">-10</span>\n' + ' y += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> D.s <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> get_boundaries(mario.rect, tiles) <span class="hljs-keyword">else</span> (D.n <span class="hljs-keyword">in</span> pressed) * <span class="hljs-number">-10</span>\n' +
' mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y)))\n' + ' mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y)))\n' +
'\n' + '\n' +
@ -217,7 +217,7 @@ const MARIO =
' n_steps = max(abs(s) <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> mario.spd)\n' + ' n_steps = max(abs(s) <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> mario.spd)\n' +
' <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(n_steps):\n' + ' <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> range(n_steps):\n' +
' mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))\n' + ' mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles))\n' +
' x, y = x + mario.spd.x / n_steps, y + mario.spd.y / n_steps\n' +
' x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps)\n' +
' mario.rect.topleft = x, y\n' + ' mario.rect.topleft = x, y\n' +
'\n' + '\n' +
'<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_boundaries</span><span class="hljs-params">(rect, tiles)</span>:</span>\n' + '<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_boundaries</span><span class="hljs-params">(rect, tiles)</span>:</span>\n' +
@ -439,11 +439,11 @@ const DIAGRAM_10_B =
'┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━┓\n' + '┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
'┃ Classes │ Metaclasses ┃\n' + '┃ Classes │ Metaclasses ┃\n' +
'┠─────────────┼─────────────┨\n' + '┠─────────────┼─────────────┨\n' +
'┃ MyClass ──→ MyMetaClass ┃\n' +
'┃ │ ┃\n' +
'┃ object ─────→ type ←╮ ┃\n' +
'┃ │ ╰──╯ ┃\n' +
'┃ str ─────────╯ ┃\n' +
'┃ MyClass ←──╴MyMetaClass ┃\n' +
'┃ │ ┃\n' +
'┃ object ←─────╴type ←╮ ┃\n' +
'┃ │ ╰──╯ ┃\n' +
'┃ str ─────────╯ ┃\n' +
'┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛\n'; '┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
const DIAGRAM_11_A = const DIAGRAM_11_A =
@ -457,9 +457,9 @@ const DIAGRAM_11_B =
'┃ Classes │ Metaclasses ┃\n' + '┃ Classes │ Metaclasses ┃\n' +
'┠─────────────┼─────────────┨\n' + '┠─────────────┼─────────────┨\n' +
'┃ MyClass │ MyMetaClass ┃\n' + '┃ MyClass │ MyMetaClass ┃\n' +
'┃ ↓ │ ↓ ┃\n' +
'┃ object ←───── type ┃\n' +
'┃ │ ┃\n' +
'┃ ↑ │ ↑ ┃\n' +
'┃ object╶─────→ type ┃\n' +
'┃ │ ┃\n' +
'┃ str │ ┃\n' + '┃ str │ ┃\n' +
'┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛\n'; '┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛\n';

Loading…
Cancel
Save