Skip to content

Commit e88b89f

Browse files
committed
Image, Pygame, Pandas
1 parent 218be71 commit e88b89f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,7 @@ img.show()
28182818
```python
28192819
from PIL import ImageDraw
28202820
<Draw> = ImageDraw.Draw(<Image>) # Object for adding 2D graphics to the image.
2821-
<Draw>.point((x, y)) # Draws a point. Truncates floats into ints.
2821+
<Draw>.point((x, y)) # Draws a point. Also `fill=<int/tuple/str>`.
28222822
<Draw>.line((x1, y1, x2, y2 [, ...])) # For anti-aliasing use <Image>.resize((w, h)).
28232823
<Draw>.arc((x1, y1, x2, y2), deg1, deg2) # Draws in clockwise dir. Also pieslice().
28242824
<Draw>.rectangle((x1, y1, x2, y2)) # Also rounded_rectangle(), regular_polygon().
@@ -2829,7 +2829,7 @@ from PIL import ImageDraw
28292829
* **Use `'fill=<color>'` to set the primary color.**
28302830
* **Use `'width=<int>'` to set the width of lines or contours.**
28312831
* **Use `'outline=<color>'` to set the color of the contours.**
2832-
* **Color can be an int, tuple, `'#rrggbb[aa]'` string or a color name.**
2832+
* **Color can be an int, tuple, `'#rrggbb[aa]'` or a color name.**
28332833

28342834

28352835
Animation
@@ -2989,10 +2989,10 @@ pg.init()
29892989
screen = pg.display.set_mode((500, 500))
29902990
rect = pg.Rect(240, 240, 20, 20)
29912991
while not pg.event.get(pg.QUIT):
2992-
deltas = {pg.K_UP: (0, -20), pg.K_RIGHT: (20, 0), pg.K_DOWN: (0, 20), pg.K_LEFT: (-20, 0)}
2992+
deltas = {pg.K_UP: (0, -1), pg.K_RIGHT: (1, 0), pg.K_DOWN: (0, 1), pg.K_LEFT: (-1, 0)}
29932993
for event in pg.event.get(pg.KEYDOWN):
2994-
dx, dy = deltas.get(event.key, (0, 0))
2995-
rect = rect.move((dx, dy))
2994+
x, y = deltas.get(event.key, (0, 0))
2995+
rect = rect.move((x*20, y*20))
29962996
screen.fill(pg.Color('black'))
29972997
pg.draw.rect(screen, pg.Color('white'), rect)
29982998
pg.display.flip()
@@ -3003,8 +3003,8 @@ pg.quit()
30033003
**Object for storing rectangular coordinates.**
30043004
```python
30053005
<Rect> = pg.Rect(x, y, width, height) # Creates Rect object. Truncates passed floats.
3006-
<int> = <Rect>.x/y/centerx/centery/# Top, right, bottom, left. Allows assignments.
3007-
<tup.> = <Rect>.topleft/center/# Topright, bottomright, bottomleft. Same.
3006+
<int> = <Rect>.x/y/centerx/centery/# `top/right/bottom/left`. Allows assignments.
3007+
<tup.> = <Rect>.topleft/center/# `topright/bottomright/bottomleft`. Same.
30083008
<Rect> = <Rect>.move((delta_x, delta_y)) # Use move_ip() to move in-place.
30093009
```
30103010

@@ -3026,7 +3026,7 @@ pg.quit()
30263026
```
30273027

30283028
```python
3029-
<Surf>.fill(color) # Tuple, Color('#rrggbb[aa]') or Color(<name>).
3029+
<Surf>.fill(color) # Pass tuple or pg.Color('<name/hex_code>').
30303030
<Surf>.set_at((x, y), color) # Updates pixel. Also <Surf>.get_at((x, y)).
30313031
<Surf>.blit(<Surf>, (x, y)) # Draws passed surface at specified location.
30323032
```
@@ -3185,7 +3185,7 @@ Name: a, dtype: int64
31853185
```python
31863186
<S>.plot.line/area/bar/pie/hist() # Generates a plot. `plt.show()` displays it.
31873187
```
3188-
* **Also `'<S>.quantile(<float/coll>)'` and `'pd.cut(<S>, bins=<int/coll>)'`.**
3188+
* **Use `'print(<S>.to_string())'` to print a Series that has more than 60 items.**
31893189
* **Indexing objects can't be tuples because `'obj[x, y]'` is converted to `'obj[(x, y)]'`.**
31903190
* **Pandas uses NumPy types like `'np.int64'`. Series is converted to `'float64'` if we assign np.nan to any item. Use `'<S>.astype(<str/type>)'` to get converted Series.**
31913191
* **Series will silently overflow if we run `'pd.Series([100], dtype="int8") + 100'`!**

index.html

+11-11
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<body>
5858
<header>
59-
<aside>April 22, 2025</aside>
59+
<aside>April 27, 2025</aside>
6060
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6161
</header>
6262

@@ -2312,7 +2312,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
23122312

23132313
<div><h3 id="imagedraw">Image Draw</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> ImageDraw
23142314
&lt;Draw&gt; = ImageDraw.Draw(&lt;Image&gt;) <span class="hljs-comment"># Object for adding 2D graphics to the image.</span>
2315-
&lt;Draw&gt;.point((x, y)) <span class="hljs-comment"># Draws a point. Truncates floats into ints.</span>
2315+
&lt;Draw&gt;.point((x, y)) <span class="hljs-comment"># Draws a point. Also `fill=&lt;int/tuple/str&gt;`.</span>
23162316
&lt;Draw&gt;.line((x1, y1, x2, y2 [, ...])) <span class="hljs-comment"># For anti-aliasing use &lt;Image&gt;.resize((w, h)).</span>
23172317
&lt;Draw&gt;.arc((x1, y1, x2, y2), deg1, deg2) <span class="hljs-comment"># Draws in clockwise dir. Also pieslice().</span>
23182318
&lt;Draw&gt;.rectangle((x1, y1, x2, y2)) <span class="hljs-comment"># Also rounded_rectangle(), regular_polygon().</span>
@@ -2325,7 +2325,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
23252325
<li><strong>Use <code class="python hljs"><span class="hljs-string">'fill=&lt;color&gt;'</span></code> to set the primary color.</strong></li>
23262326
<li><strong>Use <code class="python hljs"><span class="hljs-string">'width=&lt;int&gt;'</span></code> to set the width of lines or contours.</strong></li>
23272327
<li><strong>Use <code class="python hljs"><span class="hljs-string">'outline=&lt;color&gt;'</span></code> to set the color of the contours.</strong></li>
2328-
<li><strong>Color can be an int, tuple, <code class="python hljs"><span class="hljs-string">'#rrggbb[aa]'</span></code> string or a color name.</strong></li>
2328+
<li><strong>Color can be an int, tuple, <code class="python hljs"><span class="hljs-string">'#rrggbb[aa]'</span></code> or a color name.</strong></li>
23292329
</ul>
23302330
<div><h2 id="animation"><a href="#animation" name="animation">#</a>Animation</h2><div><h4 id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install imageio</span>
23312331
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw
@@ -2452,10 +2452,10 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
24522452
screen = pg.display.set_mode((<span class="hljs-number">500</span>, <span class="hljs-number">500</span>))
24532453
rect = pg.Rect(<span class="hljs-number">240</span>, <span class="hljs-number">240</span>, <span class="hljs-number">20</span>, <span class="hljs-number">20</span>)
24542454
<span class="hljs-keyword">while</span> <span class="hljs-keyword">not</span> pg.event.get(pg.QUIT):
2455-
deltas = {pg.K_UP: (<span class="hljs-number">0</span>, <span class="hljs-number">-20</span>), pg.K_RIGHT: (<span class="hljs-number">20</span>, <span class="hljs-number">0</span>), pg.K_DOWN: (<span class="hljs-number">0</span>, <span class="hljs-number">20</span>), pg.K_LEFT: (<span class="hljs-number">-20</span>, <span class="hljs-number">0</span>)}
2455+
deltas = {pg.K_UP: (<span class="hljs-number">0</span>, <span class="hljs-number">-1</span>), pg.K_RIGHT: (<span class="hljs-number">1</span>, <span class="hljs-number">0</span>), pg.K_DOWN: (<span class="hljs-number">0</span>, <span class="hljs-number">1</span>), pg.K_LEFT: (<span class="hljs-number">-1</span>, <span class="hljs-number">0</span>)}
24562456
<span class="hljs-keyword">for</span> event <span class="hljs-keyword">in</span> pg.event.get(pg.KEYDOWN):
2457-
dx, dy = deltas.get(event.key, (<span class="hljs-number">0</span>, <span class="hljs-number">0</span>))
2458-
rect = rect.move((dx, dy))
2457+
x, y = deltas.get(event.key, (<span class="hljs-number">0</span>, <span class="hljs-number">0</span>))
2458+
rect = rect.move((x*<span class="hljs-number">20</span>, y*<span class="hljs-number">20</span>))
24592459
screen.fill(pg.Color(<span class="hljs-string">'black'</span>))
24602460
pg.draw.rect(screen, pg.Color(<span class="hljs-string">'white'</span>), rect)
24612461
pg.display.flip()
@@ -2464,8 +2464,8 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
24642464

24652465

24662466
<div><h3 id="rect">Rect</h3><p><strong>Object for storing rectangular coordinates.</strong></p><pre><code class="python language-python hljs">&lt;Rect&gt; = pg.Rect(x, y, width, height) <span class="hljs-comment"># Creates Rect object. Truncates passed floats.</span>
2467-
&lt;int&gt; = &lt;Rect&gt;.x/y/centerx/centery/… <span class="hljs-comment"># Top, right, bottom, left. Allows assignments.</span>
2468-
&lt;tup.&gt; = &lt;Rect&gt;.topleft/center/… <span class="hljs-comment"># Topright, bottomright, bottomleft. Same.</span>
2467+
&lt;int&gt; = &lt;Rect&gt;.x/y/centerx/centery/… <span class="hljs-comment"># `top/right/bottom/left`. Allows assignments.</span>
2468+
&lt;tup.&gt; = &lt;Rect&gt;.topleft/center/… <span class="hljs-comment"># `topright/bottomright/bottomleft`. Same.</span>
24692469
&lt;Rect&gt; = &lt;Rect&gt;.move((delta_x, delta_y)) <span class="hljs-comment"># Use move_ip() to move in-place.</span>
24702470
</code></pre></div>
24712471

@@ -2483,7 +2483,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
24832483
</code></pre></div>
24842484

24852485

2486-
<pre><code class="python language-python hljs">&lt;Surf&gt;.fill(color) <span class="hljs-comment"># Tuple, Color('#rrggbb[aa]') or Color(&lt;name&gt;).</span>
2486+
<pre><code class="python language-python hljs">&lt;Surf&gt;.fill(color) <span class="hljs-comment"># Pass tuple or pg.Color('&lt;name/hex_code&gt;').</span>
24872487
&lt;Surf&gt;.set_at((x, y), color) <span class="hljs-comment"># Updates pixel. Also &lt;Surf&gt;.get_at((x, y)).</span>
24882488
&lt;Surf&gt;.blit(&lt;Surf&gt;, (x, y)) <span class="hljs-comment"># Draws passed surface at specified location.</span>
24892489
</code></pre>
@@ -2613,7 +2613,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
26132613
<pre><code class="python language-python hljs">&lt;S&gt;.plot.line/area/bar/pie/hist() <span class="hljs-comment"># Generates a plot. `plt.show()` displays it.</span>
26142614
</code></pre>
26152615
<ul>
2616-
<li><strong>Also <code class="python hljs"><span class="hljs-string">'&lt;S&gt;.quantile(&lt;float/coll&gt;)'</span></code> and <code class="python hljs"><span class="hljs-string">'pd.cut(&lt;S&gt;, bins=&lt;int/coll&gt;)'</span></code>.</strong></li>
2616+
<li><strong>Use <code class="python hljs"><span class="hljs-string">'print(&lt;S&gt;.to_string())'</span></code> to print a Series that has more than 60 items.</strong></li>
26172617
<li><strong>Indexing objects can't be tuples because <code class="python hljs"><span class="hljs-string">'obj[x, y]'</span></code> is converted to <code class="python hljs"><span class="hljs-string">'obj[(x, y)]'</span></code>.</strong></li>
26182618
<li><strong>Pandas uses NumPy types like <code class="python hljs"><span class="hljs-string">'np.int64'</span></code>. Series is converted to <code class="python hljs"><span class="hljs-string">'float64'</span></code> if we assign np.nan to any item. Use <code class="python hljs"><span class="hljs-string">'&lt;S&gt;.astype(&lt;str/type&gt;)'</span></code> to get converted Series.</strong></li>
26192619
<li><strong>Series will silently overflow if we run <code class="python hljs"><span class="hljs-string">'pd.Series([100], dtype="int8") + 100'</span></code>!</strong></li>
@@ -2944,7 +2944,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29442944

29452945

29462946
<footer>
2947-
<aside>April 22, 2025</aside>
2947+
<aside>April 27, 2025</aside>
29482948
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29492949
</footer>
29502950

0 commit comments

Comments
 (0)