Posts

Berlin to Copenhagen by bike.

Image
There's a bike path running from the north of Europe all the way to the south. Well, it's not completely finished yet, but it goes most of the way. It's part of the EuroVelo project, which aims to have a high quality cycling network made of 15 routes all around Europe completed by 2020. All my clothes and possessions for a seven day trip from Berlin to Copenhagen. I was just going to tie a sack under my seat... but was convinced that perhaps these special bags are a good idea after all. One part that's done well is the Berlin to Copenhagen leg(I guess not so surprising since they are two cities that are really into supporting bikes). Scroll down on these photos someone took, if you want a look. http :// www . slowtravelberlin .co m/ in - photos - berlin - copenhagen - cycle - route / Except, I'm going to do it at the end of April, not in winter like them. Which is usually the most dry time of year, and with a temperature that's not so hot or...

pygame.Surface.blits

Drawing many things at once is faster than drawing things one thing at a time. So, today I made a function to do this with pygame. It seems to take between 82%-85% of the time it takes to draw things one at a time. Which considering blit is often the bottleneck in many pygame apps is a pretty nice improvement. It will be landing in the pygame 1.9.4 release. More info in the blits Pull Request .

Moss box

Image
I've been looking to get more greenery into my studio, and I kind of like moss. It reminds me of when the times in my childhood running around rain forests barefoot. Luckily, a good friend has a whole bunch of it growing out the back of her apartment. And it's likely to be destroyed soon by workers. Which made me not feel so bad about digging some up. I scavenged some egg cartons First I found some egg cartons to use as a base. Underneath the moss is a good few centimeters of dirt. Unlike most of the wall moss I've seen around the place, this moss is alive. I was sort of horrified to learn that people buy dead preserved moss, and glue gun it into place. But this stuff is alive. Sometimes looking stuff up on Youtube kills the magic. Now I don't think wall moss is anywhere near as cool as I once thought it was. Thanks internet. Here it is sitting on my standing desk. Next I found an old wooden box. I lined the bottom of this with some plastic I had abo...

Investigating pypy frame drop

Image
pypy has spikes in time it takes occasionally when using cpyext, otherwise known as pauses. This is because it's deallocating lots of CPython objects all in one frame, rather than incrementally. This is likely to be addressed in a future release of pypy. Mainly it's a problem when creating and deleting lots of CPython objects (like pygame.Rect). Not pure python objects. To work around it for now, the src/rect.c has been changed to have a free list of python objects, so it doesn't alloc and dealloc them. Instead it maintains it's own list of rect PyObject pointers, and reuses them. This is done in PR #431 Use PYPY_GC_NURSERY=1m incminimark environment variables when running pypy. Below are timings of the default pygame, and default pypy (at time of writing). Then a benchmark showing the improvement with the rect freelist implemented in rect.c inside pygame. Then we also improve things by setting PYPY_GC_NURSERY=1m environment variable to change the ...

Windows pypy pygame build for testing.

Image
How to install pypy (fast python written in python) on windows and use the pygame dev build. pypy running pygame.examples.aliens on Windows 1) Get pypy. It's just a zip folder with all the stuff inside. https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.10.0-win32.zip Unzip, and put into C:\pypy, so C:\pypy\pypy.exe exists. OR get the pypy3.exe from https://bitbucket.org/pypy/pypy/downloads/pypy3-v5.10.1-win32.zip Unzip, and put into C:\pypy3, so C:\pypy3\pypy3.exe exists. 2) Set the PATH environment variable, so that pypy.exe is found in your command prompt. https://www.opentechguides.com/how-to/article/windows-10/113/windows-10-set-path.html Or you can just do this each time you run a new cmd prompt. set PATH=%PATH%;C:\pypy\;C:\pypy3\ Or just cd C:\pypy to test it out. 3) Ensure pip is installed (pip is a weirdly named tool for installing things). pypy.exe -m ensurepip 4 ) Install a dev build of pygame. pypy.exe -m pip install pygame --pre 5...

pygame on pypy usable

Image
Hi, TLDR; I'm at the pypy sprint, and working through the remaining pygame-on-pypy-cpyext issues. https://youtu.be/WN1slc5O8os Surprisingly to me... it's already usable. That is pygame (same one that runs on cpython), works on pypy through its C extension API. pypy has good support for the CPython API (through a recompile) now. PyPy is the python language with a fast JIT, so your code can approach C speeds. And in some cases it can be faster than C. There was an issue with events stopping keyboard/mouse/etc from working. Lots of details in this issue describing the changes needed, so I hope other extensions encountering this will find it useful. https://github.com/pygame/ pygame/issues/419 But now that's fixed, every pygame app I tried on it has worked. Cat sitting in the fog and snow of Switzerland Why is this exciting? This is exciting to me because: pure python code being fast on pypy(after warmup), also mixed with the fast bit...

Drawing sound (as a waveform in pygame).

Image
I recently gave an example of pygame sound generation examples , and a few people asked for more. So... here we go! There's an infinite number of ways to visualize sound. A classic way is to draw it as a waveform . Sound samples drawn as a Waveform. Scaled into a 320x200 sized Surface. A sound could be made up of 44100 samples per second. Where each sample is often a 16 bit number (or 8bit or a 32bit floating point). Python comes with a built in array for efficiently storing numbers. We can store samples in there, with integers between -32768 and 32768. This is a signed 16bit(2 byte) number. Two to the power of 16 is 65536, and if we divide that by two we see the minimum and maximum value that can hold. pow(2, 16) / 2 == 32768. Below is the annotated code, also with an example of an array of samples representing a square wave. We loop over the samples and draw a line from the previous sample to the current one. 0 to 1, 1 to 2, 2 to 3, ... N-1 to N. You can also fin...