|
2204 | 2204 | <li><strong><code class="python hljs"><span class="hljs-string">'RGB'</span></code> - 3x8-bit pixels, true color.</strong></li>
|
2205 | 2205 | <li><strong><code class="python hljs"><span class="hljs-string">'RGBA'</span></code> - 4x8-bit pixels, true color with transparency mask.</strong></li>
|
2206 | 2206 | <li><strong><code class="python hljs"><span class="hljs-string">'HSV'</span></code> - 3x8-bit pixels, Hue, Saturation, Value color space.</strong></li>
|
2207 |
| -</ul></div> |
| 2207 | +</ul><div><h3 id="animation">Animation</h3><div><h4 id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw |
| 2208 | +<span class="hljs-keyword">import</span> imageio |
| 2209 | +height, r = <span class="hljs-number">126</span>, <span class="hljs-number">10</span> |
| 2210 | +frames = [] |
| 2211 | +<span class="hljs-keyword">for</span> velocity <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>, <span class="hljs-number">16</span>): |
| 2212 | + y = sum(range(velocity)) |
| 2213 | + frame = Image.new(<span class="hljs-string">'L'</span>, (height, height)) |
| 2214 | + draw = ImageDraw.Draw(frame) |
| 2215 | + draw.ellipse((height/<span class="hljs-number">2</span>-r, y, height/<span class="hljs-number">2</span>+r, y+<span class="hljs-number">2</span>*r), fill=<span class="hljs-string">'white'</span>) |
| 2216 | + frames.append(frame) |
| 2217 | +frames += reversed(frames[<span class="hljs-number">1</span>:<span class="hljs-number">-1</span>]) |
| 2218 | +imageio.mimsave(<span class="hljs-string">'test.gif'</span>, frames, duration=<span class="hljs-number">0.03</span>) |
| 2219 | +</code></pre></div></div></div> |
| 2220 | + |
| 2221 | + |
| 2222 | + |
2208 | 2223 |
|
2209 | 2224 | <div><h2 id="audio"><a href="#audio" name="audio">#</a>Audio</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> wave
|
2210 | 2225 | <span class="hljs-keyword">from</span> struct <span class="hljs-keyword">import</span> pack, iter_unpack
|
|
0 commit comments