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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>pygame.examples — pygame v2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/pygame.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="shortcut icon" href="../_static/pygame.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="pygame.fastevent" href="fastevent.html" />
<link rel="prev" title="pygame.event" href="event.html" />
</head><body>
<div class="document">
<div class="header">
<table>
<tr>
<td class="logo">
<a href="https://www.pygame.org/">
<img src="../_static/pygame_tiny.png"/>
</a>
<h5>pygame documentation</h5>
</td>
<td class="pagelinks">
<div class="top">
<a href="https://www.pygame.org/">Pygame Home</a> ||
<a href="../index.html">Help Contents</a> ||
<a href="../genindex.html">Reference Index</a>
<form action="../search.html" method="get" style="display:inline;float:right;">
<input name="q" value="" type="text">
<input value="search" type="submit">
</form>
</div>
<hr style="color:black;border-bottom:none;border-style: dotted;border-bottom-style:none;">
<p class="bottom"><b>Most useful stuff</b>:
<a href="color.html">Color</a> |
<a href="display.html">display</a> |
<a href="draw.html">draw</a> |
<a href="event.html">event</a> |
<a href="font.html">font</a> |
<a href="image.html">image</a> |
<a href="key.html">key</a> |
<a href="locals.html">locals</a> |
<a href="mixer.html">mixer</a> |
<a href="mouse.html">mouse</a> |
<a href="rect.html">Rect</a> |
<a href="surface.html">Surface</a> |
<a href="time.html">time</a> |
<a href="music.html">music</a> |
<a href="pygame.html">pygame</a>
</p>
<p class="bottom"><b>Advanced stuff</b>:
<a href="cursors.html">cursors</a> |
<a href="joystick.html">joystick</a> |
<a href="mask.html">mask</a> |
<a href="sprite.html">sprite</a> |
<a href="transform.html">transform</a> |
<a href="bufferproxy.html">BufferProxy</a> |
<a href="freetype.html">freetype</a> |
<a href="gfxdraw.html">gfxdraw</a> |
<a href="midi.html">midi</a> |
<a href="pixelarray.html">PixelArray</a> |
<a href="pixelcopy.html">pixelcopy</a> |
<a href="sndarray.html">sndarray</a> |
<a href="surfarray.html">surfarray</a> |
<a href="math.html">math</a>
</p>
<p class="bottom"><b>Other</b>:
<a href="camera.html">camera</a> |
<a href="sdl2_controller.html#module-pygame._sdl2.controller">controller</a> |
<a href="examples.html">examples</a> |
<a href="fastevent.html">fastevent</a> |
<a href="scrap.html">scrap</a> |
<a href="tests.html">tests</a> |
<a href="touch.html">touch</a> |
<a href="pygame.html#module-pygame.version">version</a>
</p>
</td>
</tr>
</table>
</div>
<div class="documentwrapper">
<div class="body" role="main">
<section id="module-pygame.examples">
<span id="pygame-examples"></span><dl class="definition">
<dt class="title module sig sig-object">
<code class="docutils literal notranslate"><span class="pre">pygame.examples</span></code></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">module of example programs</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 37%" />
<col style="width: 1%" />
<col style="width: 62%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.aliens.main">pygame.examples.aliens.main</a></div>
</td>
<td>—</td>
<td>play the full aliens example</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.stars.main">pygame.examples.stars.main</a></div>
</td>
<td>—</td>
<td>run a simple starfield example</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.chimp.main">pygame.examples.chimp.main</a></div>
</td>
<td>—</td>
<td>hit the moving chimp</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.moveit.main">pygame.examples.moveit.main</a></div>
</td>
<td>—</td>
<td>display animated objects on the screen</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.fonty.main">pygame.examples.fonty.main</a></div>
</td>
<td>—</td>
<td>run a font rendering example</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.freetype_misc.main">pygame.examples.freetype_misc.main</a></div>
</td>
<td>—</td>
<td>run a FreeType rendering example</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.vgrade.main">pygame.examples.vgrade.main</a></div>
</td>
<td>—</td>
<td>display a vertical gradient</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.eventlist.main">pygame.examples.eventlist.main</a></div>
</td>
<td>—</td>
<td>display pygame events</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.arraydemo.main">pygame.examples.arraydemo.main</a></div>
</td>
<td>—</td>
<td>show various surfarray effects</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.sound.main">pygame.examples.sound.main</a></div>
</td>
<td>—</td>
<td>load and play a sound</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.sound_array_demos.main">pygame.examples.sound_array_demos.main</a></div>
</td>
<td>—</td>
<td>play various sndarray effects</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.liquid.main">pygame.examples.liquid.main</a></div>
</td>
<td>—</td>
<td>display an animated liquid effect</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.glcube.main">pygame.examples.glcube.main</a></div>
</td>
<td>—</td>
<td>display an animated 3D cube using OpenGL</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.scrap_clipboard.main">pygame.examples.scrap_clipboard.main</a></div>
</td>
<td>—</td>
<td>access the clipboard</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.mask.main">pygame.examples.mask.main</a></div>
</td>
<td>—</td>
<td>display multiple images bounce off each other using collision detection</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.testsprite.main">pygame.examples.testsprite.main</a></div>
</td>
<td>—</td>
<td>show lots of sprites moving around</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.headless_no_windows_needed.main">pygame.examples.headless_no_windows_needed.main</a></div>
</td>
<td>—</td>
<td>write an image file that is smoothscaled copy of an input file</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.joystick.main">pygame.examples.joystick.main</a></div>
</td>
<td>—</td>
<td>demonstrate joystick functionality</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.blend_fill.main">pygame.examples.blend_fill.main</a></div>
</td>
<td>—</td>
<td>demonstrate the various surface.fill method blend options</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.blit_blends.main">pygame.examples.blit_blends.main</a></div>
</td>
<td>—</td>
<td>uses alternative additive fill to that of surface.fill</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.cursors.main">pygame.examples.cursors.main</a></div>
</td>
<td>—</td>
<td>display two different custom cursors</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.pixelarray.main">pygame.examples.pixelarray.main</a></div>
</td>
<td>—</td>
<td>display various pixelarray generated effects</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.scaletest.main">pygame.examples.scaletest.main</a></div>
</td>
<td>—</td>
<td>interactively scale an image using smoothscale</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.midi.main">pygame.examples.midi.main</a></div>
</td>
<td>—</td>
<td>run a midi example</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.scroll.main">pygame.examples.scroll.main</a></div>
</td>
<td>—</td>
<td>run a Surface.scroll example that shows a magnified image</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.camera.main">pygame.examples.camera.main</a></div>
</td>
<td>—</td>
<td>display video captured live from an attached camera</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="examples.html#pygame.examples.playmus.main">pygame.examples.playmus.main</a></div>
</td>
<td>—</td>
<td>play an audio file</td>
</tr>
</tbody>
</table>
<p>These examples should help get you started with pygame. Here is a brief rundown
of what you get. The source code for these examples is in the public domain.
Feel free to use for your own projects.</p>
<p>There are several ways to run the examples. First they can be run as
stand-alone programs. Second they can be imported and their <code class="docutils literal notranslate"><span class="pre">main()</span></code> methods
called (see below). Finally, the easiest way is to use the python -m option:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">pygame</span><span class="o">.</span><span class="n">examples</span><span class="o">.<</span><span class="n">example</span> <span class="n">name</span><span class="o">></span> <span class="o"><</span><span class="n">example</span> <span class="n">arguments</span><span class="o">></span>
</pre></div>
</div>
<p>eg:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">pygame</span><span class="o">.</span><span class="n">examples</span><span class="o">.</span><span class="n">scaletest</span> <span class="n">someimage</span><span class="o">.</span><span class="n">png</span>
</pre></div>
</div>
<p>Resources such as images and sounds for the examples are found in the
pygame/examples/data subdirectory.</p>
<p>You can find where the example files are installed by using the following
commands inside the python interpreter.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pygame.examples.scaletest</span>
<span class="gp">>>> </span><span class="n">pygame</span><span class="o">.</span><span class="n">examples</span><span class="o">.</span><span class="n">scaletest</span><span class="o">.</span><span class="vm">__file__</span>
<span class="go">'/usr/lib/python2.6/site-packages/pygame/examples/scaletest.py'</span>
</pre></div>
</div>
<p>On each OS and version of Python the location will be slightly different.
For example on Windows it might be in 'C:/Python26/Lib/site-packages/pygame/examples/'
On Mac OS X it might be in '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pygame/examples/'</p>
<p>You can also run the examples in the python interpreter by calling each modules main() function.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pygame.examples.scaletest</span>
<span class="gp">>>> </span><span class="n">pygame</span><span class="o">.</span><span class="n">examples</span><span class="o">.</span><span class="n">scaletest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
</pre></div>
</div>
<p>We're always on the lookout for more examples and/or example requests. Code
like this is probably the best way to start getting involved with python
gaming.</p>
<p>examples as a package is new to pygame 1.9.0. But most of the examples came with
pygame much earlier.</p>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.aliens.main">
<span class="sig-prename descclassname"><span class="pre">aliens.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.aliens.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">play the full aliens example</span></div>
<div class="line"><span class="signature">aliens.main() -> None</span></div>
</div>
<p>This started off as a port of the <code class="docutils literal notranslate"><span class="pre">SDL</span></code> demonstration, Aliens. Now it has
evolved into something sort of resembling fun. This demonstrates a lot of
different uses of sprites and optimized blitting. Also transparency,
colorkeys, fonts, sound, music, joystick, and more. (PS, my high score is
117! goodluck)</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.stars.main">
<span class="sig-prename descclassname"><span class="pre">stars.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.stars.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">run a simple starfield example</span></div>
<div class="line"><span class="signature">stars.main() -> None</span></div>
</div>
<p>A simple starfield example. You can change the center of perspective by
leftclicking the mouse on the screen.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.chimp.main">
<span class="sig-prename descclassname"><span class="pre">chimp.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.chimp.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">hit the moving chimp</span></div>
<div class="line"><span class="signature">chimp.main() -> None</span></div>
</div>
<p>This simple example is derived from the line-by-line tutorial that comes
with pygame. It is based on a 'popular' web banner. Note there are comments
here, but for the full explanation, follow along in the tutorial.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.moveit.main">
<span class="sig-prename descclassname"><span class="pre">moveit.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.moveit.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display animated objects on the screen</span></div>
<div class="line"><span class="signature">moveit.main() -> None</span></div>
</div>
<p>This is the full and final example from the Pygame Tutorial, "How Do I Make
It Move". It creates 10 objects and animates them on the screen.</p>
<p>Note it's a bit scant on error checking, but it's easy to read. :]
Fortunately, this is python, and we needn't wrestle with a pile of error
codes.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.fonty.main">
<span class="sig-prename descclassname"><span class="pre">fonty.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.fonty.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">run a font rendering example</span></div>
<div class="line"><span class="signature">fonty.main() -> None</span></div>
</div>
<p>Super quick, super simple application demonstrating the different ways to
render fonts with the font module</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.freetype_misc.main">
<span class="sig-prename descclassname"><span class="pre">freetype_misc.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.freetype_misc.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">run a FreeType rendering example</span></div>
<div class="line"><span class="signature">freetype_misc.main() -> None</span></div>
</div>
<p>A showcase of rendering features the <a class="tooltip reference internal" href="freetype.html#pygame.freetype.Font" title=""><code class="xref py py-class docutils literal notranslate"><span class="pre">pygame.freetype.Font</span></code><span class="tooltip-content">Create a new Font instance from a supported font file.</span></a>
class provides in addition to those available with <a class="tooltip reference internal" href="font.html#pygame.font.Font" title=""><code class="xref py py-class docutils literal notranslate"><span class="pre">pygame.font.Font</span></code><span class="tooltip-content">create a new Font object from a file</span></a>.
It is a demonstration of direct to surface rendering, with vertical text
and rotated text, opaque text and semi transparent text, horizontally
stretched text and vertically stretched text.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.vgrade.main">
<span class="sig-prename descclassname"><span class="pre">vgrade.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.vgrade.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display a vertical gradient</span></div>
<div class="line"><span class="signature">vgrade.main() -> None</span></div>
</div>
<p>Demonstrates creating a vertical gradient with pixelcopy and NumPy python.
The app will create a new gradient every half second and report the time
needed to create and display the image. If you're not prepared to start
working with the NumPy arrays, don't worry about the source for this one :]</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.eventlist.main">
<span class="sig-prename descclassname"><span class="pre">eventlist.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.eventlist.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display pygame events</span></div>
<div class="line"><span class="signature">eventlist.main() -> None</span></div>
</div>
<p>Eventlist is a sloppy style of pygame, but is a handy tool for learning
about pygame events and input. At the top of the screen are the state of
several device values, and a scrolling list of events are displayed on the
bottom.</p>
<p>This is not quality 'ui' code at all, but you can see how to implement very
non-interactive status displays, or even a crude text output control.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.arraydemo.main">
<span class="sig-prename descclassname"><span class="pre">arraydemo.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.arraydemo.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">show various surfarray effects</span></div>
<div class="line"><span class="signature">arraydemo.main(arraytype=None) -> None</span></div>
</div>
<p>Another example filled with various surfarray effects. It requires the
surfarray and image modules to be installed. This little demo can also make
a good starting point for any of your own tests with surfarray</p>
<p>The <code class="docutils literal notranslate"><span class="pre">arraytype</span></code> parameter is deprecated; passing any value besides 'numpy'
will raise ValueError.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.sound.main">
<span class="sig-prename descclassname"><span class="pre">sound.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.sound.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">load and play a sound</span></div>
<div class="line"><span class="signature">sound.main(file_path=None) -> None</span></div>
</div>
<p>Extremely basic testing of the mixer module. Load a sound and play it. All
from the command shell, no graphics.</p>
<p>If provided, use the audio file 'file_path', otherwise use a default file.</p>
<p><code class="docutils literal notranslate"><span class="pre">sound.py</span></code> optional command line argument: an audio file</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.sound_array_demos.main">
<span class="sig-prename descclassname"><span class="pre">sound_array_demos.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.sound_array_demos.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">play various sndarray effects</span></div>
<div class="line"><span class="signature">sound_array_demos.main(arraytype=None) -> None</span></div>
</div>
<p>Uses sndarray and NumPy to create offset faded copies of the
original sound. Currently it just uses hardcoded values for the number of
echoes and the delay. Easy for you to recreate as needed.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">arraytype</span></code> parameter is deprecated; passing any value besides 'numpy'
will raise ValueError.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.liquid.main">
<span class="sig-prename descclassname"><span class="pre">liquid.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.liquid.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display an animated liquid effect</span></div>
<div class="line"><span class="signature">liquid.main() -> None</span></div>
</div>
<p>This example was created in a quick comparison with the BlitzBasic gaming
language. Nonetheless, it demonstrates a quick 8-bit setup (with colormap).</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.glcube.main">
<span class="sig-prename descclassname"><span class="pre">glcube.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.glcube.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display an animated 3D cube using OpenGL</span></div>
<div class="line"><span class="signature">glcube.main() -> None</span></div>
</div>
<p>Using PyOpenGL and pygame, this creates a spinning 3D multicolored cube.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.scrap_clipboard.main">
<span class="sig-prename descclassname"><span class="pre">scrap_clipboard.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.scrap_clipboard.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">access the clipboard</span></div>
<div class="line"><span class="signature">scrap_clipboard.main() -> None</span></div>
</div>
<p>A simple demonstration example for the clipboard support.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.mask.main">
<span class="sig-prename descclassname"><span class="pre">mask.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.mask.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display multiple images bounce off each other using collision detection</span></div>
<div class="line"><span class="signature">mask.main(*args) -> None</span></div>
</div>
<p>Positional arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">one</span> <span class="ow">or</span> <span class="n">more</span> <span class="n">image</span> <span class="n">file</span> <span class="n">names</span><span class="o">.</span>
</pre></div>
</div>
<p>This <code class="docutils literal notranslate"><span class="pre">pygame.masks</span></code> demo will display multiple moving sprites bouncing off
each other. More than one sprite image can be provided.</p>
<p>If run as a program then <code class="docutils literal notranslate"><span class="pre">mask.py</span></code> takes one or more image files as
command line arguments.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.testsprite.main">
<span class="sig-prename descclassname"><span class="pre">testsprite.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.testsprite.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">show lots of sprites moving around</span></div>
<div class="line"><span class="signature">testsprite.main(update_rects = True, use_static = False, use_FastRenderGroup = False, screen_dims = [640, 480], use_alpha = False, flags = 0) -> None</span></div>
</div>
<p>Optional keyword arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">update_rects</span> <span class="o">-</span> <span class="n">use</span> <span class="n">the</span> <span class="n">RenderUpdate</span> <span class="n">sprite</span> <span class="n">group</span> <span class="k">class</span>
<span class="nc">use_static</span> <span class="o">-</span> <span class="n">include</span> <span class="n">non</span><span class="o">-</span><span class="n">moving</span> <span class="n">images</span>
<span class="n">use_FastRenderGroup</span> <span class="o">-</span> <span class="n">Use</span> <span class="n">the</span> <span class="n">FastRenderGroup</span> <span class="n">sprite</span> <span class="n">group</span>
<span class="n">screen_dims</span> <span class="o">-</span> <span class="n">pygame</span> <span class="n">window</span> <span class="n">dimensions</span>
<span class="n">use_alpha</span> <span class="o">-</span> <span class="n">use</span> <span class="n">alpha</span> <span class="n">blending</span>
<span class="n">flags</span> <span class="o">-</span> <span class="n">additional</span> <span class="n">display</span> <span class="n">mode</span> <span class="n">flags</span>
</pre></div>
</div>
<p>Like the <code class="docutils literal notranslate"><span class="pre">testsprite.c</span></code> that comes with SDL, this pygame version shows
lots of sprites moving around.</p>
<p>If run as a stand-alone program then no command line arguments are taken.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.headless_no_windows_needed.main">
<span class="sig-prename descclassname"><span class="pre">headless_no_windows_needed.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.headless_no_windows_needed.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">write an image file that is smoothscaled copy of an input file</span></div>
<div class="line"><span class="signature">headless_no_windows_needed.main(fin, fout, w, h) -> None</span></div>
</div>
<p>arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fin</span> <span class="o">-</span> <span class="n">name</span> <span class="n">of</span> <span class="n">an</span> <span class="nb">input</span> <span class="n">image</span> <span class="n">file</span>
<span class="n">fout</span> <span class="o">-</span> <span class="n">name</span> <span class="n">of</span> <span class="n">the</span> <span class="n">output</span> <span class="n">file</span> <span class="n">to</span> <span class="n">create</span><span class="o">/</span><span class="n">overwrite</span>
<span class="n">w</span><span class="p">,</span> <span class="n">h</span> <span class="o">-</span> <span class="n">size</span> <span class="n">of</span> <span class="n">the</span> <span class="n">rescaled</span> <span class="n">image</span><span class="p">,</span> <span class="k">as</span> <span class="n">integer</span> <span class="n">width</span> <span class="ow">and</span> <span class="n">height</span>
</pre></div>
</div>
<p>How to use pygame with no windowing system, like on headless servers.</p>
<p>Thumbnail generation with scaling is an example of what you can do with
pygame.</p>
<p><code class="docutils literal notranslate"><span class="pre">NOTE</span></code>: the pygame scale function uses MMX/SSE if available, and can be
run in multiple threads.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">headless_no_windows_needed.py</span></code> is run as a program it takes the
following command line arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">-</span><span class="n">scale</span> <span class="n">inputimage</span> <span class="n">outputimage</span> <span class="n">new_width</span> <span class="n">new_height</span>
<span class="n">eg</span><span class="o">.</span> <span class="o">-</span><span class="n">scale</span> <span class="ow">in</span><span class="o">.</span><span class="n">png</span> <span class="n">outpng</span> <span class="mi">50</span> <span class="mi">50</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.joystick.main">
<span class="sig-prename descclassname"><span class="pre">joystick.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.joystick.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">demonstrate joystick functionality</span></div>
<div class="line"><span class="signature">joystick.main() -> None</span></div>
</div>
<p>A demo showing full joystick support.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.2.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.blend_fill.main">
<span class="sig-prename descclassname"><span class="pre">blend_fill.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.blend_fill.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">demonstrate the various surface.fill method blend options</span></div>
<div class="line"><span class="signature">blend_fill.main() -> None</span></div>
</div>
<p>A interactive demo that lets one choose which BLEND_xxx option to apply to a
surface.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.blit_blends.main">
<span class="sig-prename descclassname"><span class="pre">blit_blends.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.blit_blends.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">uses alternative additive fill to that of surface.fill</span></div>
<div class="line"><span class="signature">blit_blends.main() -> None</span></div>
</div>
<p>Fake additive blending. Using NumPy. it doesn't clamp. Press r,g,b Somewhat
like blend_fill.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.cursors.main">
<span class="sig-prename descclassname"><span class="pre">cursors.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.cursors.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display two different custom cursors</span></div>
<div class="line"><span class="signature">cursors.main() -> None</span></div>
</div>
<p>Display an arrow or circle with crossbar cursor.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.pixelarray.main">
<span class="sig-prename descclassname"><span class="pre">pixelarray.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.pixelarray.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display various pixelarray generated effects</span></div>
<div class="line"><span class="signature">pixelarray.main() -> None</span></div>
</div>
<p>Display various pixelarray generated effects.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.scaletest.main">
<span class="sig-prename descclassname"><span class="pre">scaletest.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.scaletest.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">interactively scale an image using smoothscale</span></div>
<div class="line"><span class="signature">scaletest.main(imagefile, convert_alpha=False, run_speed_test=True) -> None</span></div>
</div>
<p>arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">imagefile</span> <span class="o">-</span> <span class="n">file</span> <span class="n">name</span> <span class="n">of</span> <span class="n">source</span> <span class="n">image</span> <span class="p">(</span><span class="n">required</span><span class="p">)</span>
<span class="n">convert_alpha</span> <span class="o">-</span> <span class="n">use</span> <span class="n">convert_alpha</span><span class="p">()</span> <span class="n">on</span> <span class="n">the</span> <span class="n">surf</span> <span class="p">(</span><span class="n">default</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">run_speed_test</span> <span class="o">-</span> <span class="p">(</span><span class="n">default</span> <span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p>A smoothscale example that resized an image on the screen. Vertical and
horizontal arrow keys are used to change the width and height of the
displayed image. If the convert_alpha option is True then the source image
is forced to have source alpha, whether or not the original images does. If
run_speed_test is True then a background timing test is performed instead of
the interactive scaler.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">scaletest.py</span></code> is run as a program then the command line options are:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ImageFile</span> <span class="p">[</span><span class="o">-</span><span class="n">t</span><span class="p">]</span> <span class="p">[</span><span class="o">-</span><span class="n">convert_alpha</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="n">Run</span> <span class="n">Speed</span> <span class="n">Test</span>
<span class="p">[</span><span class="o">-</span><span class="n">convert_alpha</span><span class="p">]</span> <span class="o">=</span> <span class="n">Use</span> <span class="n">convert_alpha</span><span class="p">()</span> <span class="n">on</span> <span class="n">the</span> <span class="n">surf</span><span class="o">.</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.midi.main">
<span class="sig-prename descclassname"><span class="pre">midi.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.midi.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">run a midi example</span></div>
<div class="line"><span class="signature">midi.main(mode='output', device_id=None) -> None</span></div>
</div>
<p>Arguments:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mode</span> <span class="o">-</span> <span class="k">if</span> <span class="s1">'output'</span> <span class="n">run</span> <span class="n">a</span> <span class="n">midi</span> <span class="n">keyboard</span> <span class="n">output</span> <span class="n">example</span>
<span class="s1">'input'</span> <span class="n">run</span> <span class="n">a</span> <span class="n">midi</span> <span class="n">event</span> <span class="n">logger</span> <span class="nb">input</span> <span class="n">example</span>
<span class="s1">'list'</span> <span class="nb">list</span> <span class="n">available</span> <span class="n">midi</span> <span class="n">devices</span>
<span class="p">(</span><span class="n">default</span> <span class="s1">'output'</span><span class="p">)</span>
<span class="n">device_id</span> <span class="o">-</span> <span class="n">midi</span> <span class="n">device</span> <span class="n">number</span><span class="p">;</span> <span class="k">if</span> <span class="kc">None</span> <span class="n">then</span> <span class="n">use</span> <span class="n">the</span> <span class="n">default</span> <span class="n">midi</span> <span class="nb">input</span> <span class="ow">or</span>
<span class="n">output</span> <span class="n">device</span> <span class="k">for</span> <span class="n">the</span> <span class="n">system</span>
</pre></div>
</div>
<p>The output example shows how to translate mouse clicks or computer keyboard
events into midi notes. It implements a rudimentary button widget and state
machine.</p>
<p>The input example shows how to translate midi input to pygame events.</p>
<p>With the use of a virtual midi patch cord the output and input examples can
be run as separate processes and connected so the keyboard output is
displayed on a console.</p>
<p>new to pygame 1.9.0</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.scroll.main">
<span class="sig-prename descclassname"><span class="pre">scroll.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.scroll.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">run a Surface.scroll example that shows a magnified image</span></div>
<div class="line"><span class="signature">scroll.main(image_file=None) -> None</span></div>
</div>
<p>This example shows a scrollable image that has a zoom factor of eight. It
uses the <a class="reference internal" href="surface.html#pygame.Surface.scroll" title="pygame.Surface.scroll"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Surface.scroll()</span></code></a>
function to shift the image on the display surface.
A clip rectangle protects a margin area. If called as a function,
the example accepts an optional image file path. If run as a program it
takes an optional file path command line argument. If no file is provided a
default image file is used.</p>
<p>When running click on a black triangle to move one pixel in the direction
the triangle points. Or use the arrow keys. Close the window or press
<code class="docutils literal notranslate"><span class="pre">ESC</span></code> to quit.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.camera.main">
<span class="sig-prename descclassname"><span class="pre">camera.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.camera.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">display video captured live from an attached camera</span></div>
<div class="line"><span class="signature">camera.main() -> None</span></div>
</div>
<p>A simple live video player, it uses the first available camera it finds on
the system.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.examples.playmus.main">
<span class="sig-prename descclassname"><span class="pre">playmus.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.examples.playmus.main" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">play an audio file</span></div>
<div class="line"><span class="signature">playmus.main(file_path) -> None</span></div>
</div>
<p>A simple music player with window and keyboard playback control. Playback can
be paused and rewound to the beginning.</p>
</dd></dl>
</dd></dl>
</section>
<br /><br />
<hr />
<a href="https://github.com/pygame/pygame/edit/main/docs/reST/ref/examples.rst" rel="nofollow">Edit on GitHub</a>
<div class="clearer"></div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="fastevent.html" title="pygame.fastevent"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="event.html" title="pygame.event"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pygame v2.1.2 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.examples</span></code></a></li>
<script type="text/javascript" src="https://www.pygame.org/comment/jquery.plugin.docscomments.js"></script>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2000-2021, pygame developers.
</div>
</body>
</html>
|