Popular recipes tagged "meta:requires=pygame"http://code.activestate.com/recipes/tags/meta:requires=pygame/2015-01-03T02:04:02-08:00ActiveState Code RecipesSnake the game (Python) 2015-01-03T02:04:02-08:00Burak Tandoganhttp://code.activestate.com/recipes/users/4191373/http://code.activestate.com/recipes/578996-snake-the-game/ <p style="color: grey"> Python recipe 578996 by <a href="/recipes/users/4191373/">Burak Tandogan</a> (<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/snake/">snake</a>, <a href="/recipes/tags/the/">the</a>). Revision 3. </p> <p>Popular Snake game with Python-Pygame module. <strong>Important:</strong> If you try to run this script without special <strong>png-wav</strong> files it will fail, you have to put following files to a directory with this script. "apple.png","snakehead.png","intro.wav","dead.wav". They are basically apple picture, head of snake, intro sound and dead sound.Without them script will not run. Just make inactive the statements intro.wav and dead.wav, and find a little apple picture and snake head :).Or you can play the game just install it. <strong>Here is the installer:</strong> <a href="http://dosya.co/7c6f15c0f4d04514/Flafel-1.26-win32.rar" rel="nofollow">http://dosya.co/7c6f15c0f4d04514/Flafel-1.26-win32.rar</a> It will install the game in program files, you can find it in search "Flafel" and click to Flafel.exe. </p> Python Game of Life (Python) 2014-01-14T14:34:17-08:00Christian Careagahttp://code.activestate.com/recipes/users/4186639/http://code.activestate.com/recipes/578808-python-game-of-life/ <p style="color: grey"> Python recipe 578808 by <a href="/recipes/users/4186639/">Christian Careaga</a> (<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Conway's Game of Life written in Python with Pygame!</p> <p>Here is a screenshot: <a href="http://adf.ly/c4cnA" rel="nofollow">http://adf.ly/c4cnA</a></p> <p>Here is the exe version!: <a href="http://adf.ly/c4bMO" rel="nofollow">http://adf.ly/c4bMO</a></p> <p>Hope you like it!</p> A Complete Morse Code Generator in Python with Sound (Python) 2013-01-08T18:13:33-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578411-a-complete-morse-code-generator-in-python-with-sou/ <p style="color: grey"> Python recipe 578411 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/morse_code/">morse_code</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This is a complete Morse Code Generator with sound. You can <a href="http://temp3.net/thelivingpearl_downloads/morse_sound_files.zip">download the sound files (ogg) for Morse Code</a>. For more information checkout the article <a href="http://thelivingpearl.com/2013/01/08/morse-code-and-dictionaries-in-python-with-sound/">Morse Code and Dictionaries in Python</a></p> Recursive Mandelbrot Generation (Python) 2013-08-11T03:46:46-07:00Bill Picketthttp://code.activestate.com/recipes/users/4174028/http://code.activestate.com/recipes/578635-recursive-mandelbrot-generation/ <p style="color: grey"> Python recipe 578635 by <a href="/recipes/users/4174028/">Bill Pickett</a> (<a href="/recipes/tags/mandelbrot/">mandelbrot</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/recursion/">recursion</a>). Revision 12. </p> <p>This program recursively generates a Mandelbrot set using Python and PyGame. The size of the window must be a power of two or you will get rendering errors in the final image. It was written as an exercise in recursion, primarily to further my own understanding of that.</p> Play a Sound File in Python using PyGame (Python) 2013-01-08T18:08:55-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578410-play-a-sound-file-in-python-using-pygame/ <p style="color: grey"> Python recipe 578410 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sound/">sound</a>). </p> <p>This is how you can play an ogg sound file in python using the pygame library. This is part of an article about <a href="http://thelivingpearl.com/2013/01/08/morse-code-and-dictionaries-in-python-with-sound/">Morse Code and Dictionaries in Python</a></p> OpenKinect Mouse Control Using Python (Python) 2012-04-15T18:49:00-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578104-openkinect-mouse-control-using-python/ <p style="color: grey"> Python recipe 578104 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/computer/">computer</a>, <a href="/recipes/tags/computer_vision/">computer_vision</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/hand_tracking/">hand_tracking</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/opencv/">opencv</a>, <a href="/recipes/tags/openkinect/">openkinect</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tracking/">tracking</a>, <a href="/recipes/tags/vision/">vision</a>). Revision 2. </p> <p>This is a simple code that lets a user control the mouse and left-click using the Microsoft Kinect, Python, and OpenKinect. </p> <pre class="prettyprint"><code>Computer Prerequisites: -OpenKinect -Python Wrapper for OpenKinect -A Linux machine using Ubuntu -OpenCV 2.1 -OpenCV 2.3 -Python 2.7.2 -A Microsoft Kinect -A Microsoft Kinect USB Adapter -PyGame -Xlib for Python </code></pre> <p>To run this code you either need to start it in the terminal or you need to write a short bash script that runs the code. This is necessary because it requires super-user privileges.</p> <p>The Bash script is (Assuming the code is saved by the name 'Hand Tracking.py' in /home/$USER directory:</p> <pre class="prettyprint"><code>#!bin/bash cd 'home/$USER' gksudo python 'Hand Tracking.py' </code></pre> <p>The code is heavily commented and most of what you will need to know is there. </p> Libreenect (OpenKinect) Minimum Value Joystick With Display - Kinect Demo Using OpenKinect SDK (Python) 2012-03-18T18:52:42-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578080-libreenect-openkinect-minimum-value-joystick-with-/ <p style="color: grey"> Python recipe 578080 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/computer_vision/">computer_vision</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/joystick/">joystick</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/libfreenect/">libfreenect</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/opencv/">opencv</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/virtual_joystick/">virtual_joystick</a>). Revision 3. </p> <p>This demo requires you to be using a Linux machine and to have libfreenect installed with the python wrapper. This demo also requires you to have opencv, numpy, and pygame. They can all be installed using sudo apt-get install {PROGRAM NAME HERE}. Here are instructions on installing libfreenect: <a href="http://openkinect.org/wiki/Getting_Started" rel="nofollow">http://openkinect.org/wiki/Getting_Started</a>. Okay, so what this demo does is finds the minimum point on the depth image and uses the index of this minimum point to create a four button joystick that codes for 'A', 'B', 'X', 'Y'. It also uses the minimum point and the RGB image to put a circle on the minimum point on the screen. So basically a dot will follow your hand on the RGB image. If the minimum value is larger than 600 (arbitrary units), the color of the dot will change from red to purple and the dot will remain stationary. Also, if the Kinect is not properly opened the first time, unplug it and plug it back in and run in the terminal sudo freenect-glview. After try running the program again. One more thing, this code requires super user privileges so run it through the terminal. Here is how to do this for linux n00bs.</p> <ol> <li>Change your directory the the directory the code is in (use cd {PATH})</li> <li>Run the code using sudo python {FILENAME}</li> <li>Don't forget to add the the .py at the end</li> </ol> Sound in the STL (Python) 2011-08-15T09:28:12-07:00Russell Fosterhttp://code.activestate.com/recipes/users/4178972/http://code.activestate.com/recipes/577843-sound-in-the-stl/ <p style="color: grey"> Python recipe 577843 by <a href="/recipes/users/4178972/">Russell Foster</a> (<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/stl/">stl</a>). </p> <p>I get to use a number of languages and have found Python lacks good sound implementation in it's STL. Sure you can download a module, but many organisations make it difficult to install add ons, and when you hand apps to people you don't want to have to say, first install python, then install x, y, z from these websites. The STL needs to have a module added in that handles sound cross platform. I have noticed people are happy with PyGame. Perhaps adding that to the STL would be good for everybody?</p> using pyHook to block Windows Keys (Python) 2011-09-18T21:29:17-07:00Brian Davishttp://code.activestate.com/recipes/users/4119187/http://code.activestate.com/recipes/553270-using-pyhook-to-block-windows-keys/ <p style="color: grey"> Python recipe 553270 by <a href="/recipes/users/4119187/">Brian Davis</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Normally you do NOT want to block operating system key combinations but there are a few legitimate cases where you do. In my case I am making a pygame script for my 1 year old to bang on the keyboard and see/hear shapes/color/sounds in response. Brian Fischer on the pygame mailing list pointed me to pyHook. This example was taken from here: <a href="http://www.mindtrove.info/articles/pyhook.html" rel="nofollow">http://www.mindtrove.info/articles/pyhook.html</a> and modified to use the pygame event system.</p> Play sound files with pygame in a cross-platform manner (Python) 2007-06-21T14:16:58-07:00Chris Arndthttp://code.activestate.com/recipes/users/1499228/http://code.activestate.com/recipes/521884-play-sound-files-with-pygame-in-a-cross-platform-m/ <p style="color: grey"> Python recipe 521884 by <a href="/recipes/users/1499228/">Chris Arndt</a> (<a href="/recipes/tags/multimedia/">multimedia</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 4. </p> <p>This simple script shows how to play back a sound file using the mixer module from the pygame library. If you have pygame installed, this will work on all major platforms. The mixer module supports WAV and OGG files with many different sample rates, bits per sample and channels. The script will play back all supported files given on the command line sequentially.</p> Access Cairo surface from numpy and pygame (Python) 2006-11-21T08:22:51-08:00Simon Burtonhttp://code.activestate.com/recipes/users/1214028/http://code.activestate.com/recipes/498278-access-cairo-surface-from-numpy-and-pygame/ <p style="color: grey"> Python recipe 498278 by <a href="/recipes/users/1214028/">Simon Burton</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>We alias the memory from a cairo surface so that we can manipulate the bits as a numpy array, or display/manipulate the image in pygame.</p> A Sinus Plasma, using Pygame (Python) 2004-11-07T23:38:22-08:00S Whttp://code.activestate.com/recipes/users/1759688/http://code.activestate.com/recipes/334696-a-sinus-plasma-using-pygame/ <p style="color: grey"> Python recipe 334696 by <a href="/recipes/users/1759688/">S W</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>An old-school demo effect, using sine wave interference patterns. Entertaining for at least a few minutes :)</p> <p>Modify the freq variable for different patterns.</p> OpenGL TTF (TrueType Font) FPS (Frames Per Second) example (Python) 2002-02-20T12:23:39-08:00Nelson Rushhttp://code.activestate.com/recipes/users/144881/http://code.activestate.com/recipes/115418-opengl-ttf-truetype-font-fps-frames-per-second-exa/ <p style="color: grey"> Python recipe 115418 by <a href="/recipes/users/144881/">Nelson Rush</a> . </p> <p>An OpenGL example in Python using PyOpenGL and PyGame modules to render a spinning triangle while the FPS (Frames Per Second) is displayed in the upper right hand corner using a TrueType font.</p>