stick's corner

All composite phenomena are impermanent. All contaminated things and events are unsatisfactory.

LÖVE (Love2D) on Android

| Comments

Almost two years ago I blogged about my Global Game Jam entry called Hexoboros. This year’s approacing GGJ reminded me that I wanted to port this game to Android. Back then it turned out to be quite hard and results were not very satisfying.

I knew that SDL 2.0 was released in August 2013 bringing Android support out of the box. What I didn’t know was that LÖVE 0.9.0 was released in December as well, building on top of SDL2. I was pretty excited, because I felt that LÖVE on Android will became a real thing soon.

And I was right. Martin Felis is working on love-android-sdl2 repo, which combines all these efforts into one easy to build Android package.

After fixing some minor issues in Martin’s and mine code I ended up with this result:

Great! Now I’m convinced that I’ll be using LÖVE again during Global Game Jam this year.

Some notes:

  • love-android-sdl2 loads LÖVE resources from /sdcard/lovegame/ directory (this is useful for debugging)
  • if you zip your LÖVE resources to a file named game.love and add this file to assets directory of Android project, you end up with APK that bundles LÖVE with your game (this is great for deploying final game)
  • never force fixed resolution in your LÖVE code; rather update your code so it works with any given resolution and aspect ratio (i.e. don’t hardcode sizes and positions of rendered objects)
  • you can test you got that right by putting t.window.resizable = true in your conf.lua and using something like this in your main.lua code:
1
2
3
4
5
6
7
8
function love.resize(w, h)
  width, height = w, h
  scale = height / 1024
end

function love.load()
  love.resize(love.window.getWidth(), love.window.getHeight())
  ...

Idea Factory: Mycelium Animated Photos

| Comments

This post is a part of Idea Factory series.

One evening I found really nice work by Ryan Alexander where images are created by simulating a life of mycelium. I was wondering how it was done and I came up with my own Processing sketch that creates something similar (although not as quite nice as the original work).

The principle is simple: you take an image and convert it to grayscale. The brighter (or darker) is the pixel, the more food you put on that particular position. Then you run several autonomous agents that feed from this food, move randomly, die if they are starving and multiply if they are well enough. The original photos and the mycelium growing process can be seen here:

The idea is to create a mobile phone application that is able to take a photo from a camera (and/or open a gallery photo) and runs the described process on it. The final result or animated GIF of the process could be then uploaded to the Internet and shared among your friends.

Idea Factory: Facebook Random Comics

| Comments

This post is a part of Idea Factory series.

Recently my friend sent me a link to this great random comic generator at Pandyland. My idea is to create a similar application but instead of the drawn figures it would use your friends photos from Facebook. One could check which of his/hers friends should appear in the comic (or leave it to a random chance), select the layout of the comic strip (e.g. 3x1 frames, 2x2 frames, etc.) and click the generate button. The application then calls the Facebook API which returns reasonable photos together with their metadata (such as who is in the picture and at what pixel position, the API already includes that kind of info in the results). Next step is to add speech bubbles filled in with either random sentences or leaving the bubbles empty so one can add his/hers own replicas. Lastly, a nice frames and a title are added, so the result could be shared back to Facebook or any other webiste as one image.

Idea Factory: Pack My Stuff

| Comments

This post is a part of Idea Factory series.

Last two years I travelled a lot to various Open Source related conferences. After few of them I already got quite a good idea what to pack and what not, depending on the length and the destination of the trip. But from time to time I forgot something and that later turned out to be a huge mistake.

The idea is to create a mobile application where you can define several lists of things you need to pack, for example: “3 days in Europe (summer)”, “a week in the USA (winter)”, “Christmas with Family” and so on. You open the application while packing packing your stuff at home and it will show you the list of things you need to pack. Everytime you put an item into your suitcase, you check the corresponding checkbox in the list. When the list is fully checked you know you didn’t miss anything. Simple, isn’t it?! :) You do the same process on the last day of your trip, so you can make sure you don’t forgot anything at the hotel.

Idea Factory: Semantic Patches on Github

| Comments

This post is a part of Idea Factory series.

Two years ago someone sent me quite weird pull request on Github. It took me some time to realize that the only change was the removal of whitespace at the end of the lines of all files. Commit message contained a link to some software development company so the whole effort could be considered as some kind of spam or publicity stunt.

But it sparked an idea!

When I was at FOSDEM I saw a great talk about Coccinelle which is a tool for semantic patches. These are similar to normal patches, but they contain something like expressions which are being matched during applying of the patch. That way they apply the change to usually more places of the codebase not just one (which is the case when using “normal” patches). Basically, you want to come up with most generic “rule” that fixes one particular issue, but it’s not triggered at any other time. Some examples how Coccinelle was used in Linux kernel development are here.

Another quite common example (which I’ve seen at many, many places while working as a package maintainer at SUSE) is the wrong usage of strncpy function. The last argument has quite different meaning than the one used in strncat function. It is the maximum length of the appended string, not the size of the whole output buffer. The patch fixing this issue is similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
--- source.c
+++ source.c
@@ -34,7 +34,7 @@
   return 0;
 }
 
-strncpy(buf, player, sizeof(buf));
+strncpy(buf, player, sizeof(buf) - sizeof(player) - 1);
 
 if (verbose)
 {
 

This patch obviously fixes the problem only at one particular place. Semantic patch that fixes all wrong usages of the function might look like this (but please don’t take my words for granted, I have not tested it):

1
2
3
4
5
6
7
@@
identifier dest, src;
@@
 
-strncpy(dest, src, sizeof(dest));
+strncpy(dest, src, sizeof(dest) - sizeof(src) - 1);
 

So back to the idea:

  1. Collect the most common programming mistakes people make.
  2. Create semantic patches for fixing them.
  3. Write a bot that scans Github for these issues and creates a pull request when necessary.
  4. PROFIT!

While writing this post I found this article which says that bots are generally not welcome on Github. But I think if the pull requests are reviewed by a person and the fixing rules are beneficial to everyone, then it might really be worth a try!

Idea Factory: Coin Counter

| Comments

This post is a part of Idea Factory series.

The idea is simple: create a mobile phone application that is able to count coins (and their values) from the photo. You pour coins from your wallet on the table, make sure they don’t overlap by spreading them, take a photo and voila the phone will tell you exactly how much money in coins you have. User can select what currency is she using (dollars/cents, euros/cents, etc., to make the recognition easier). Using OpenCV or some other computer vision library should make this task pretty easy.

Special points awarded if the application is using realtime augmented reality, but for this particular case it is not necessary.

Idea Factory

| Comments

From time to time I come up with the “ultimate idea”, but because I don’t have usually time to implement it right away I put it in my backlog. Unfortunately, the backlog is growing bigger and bigger and I started to realize there are some ideas on the list to which I’ll never return, but still they would be nice to have. There are lots of bright minds out there, so I decided to start publishing the ideas from the backlog list. Maybe someone will find them interesting enough and implement them. Heck, maybe someone will be able to build a successful startup around some of them. For that case I put the donate section in the sidebar, so you can do me a favor once you are a millionaire. :–)

But, enough talking, here are the ideas! I’ll keep adding links to this list in the future:

  1. Coin Counter
  2. Github Semantic Patches
  3. Pack My Stuff
  4. Mycelium Animated Photos
  5. Facebook Random Comics

What I Am Up To

| Comments

I realized that I haven’t put any new posts for quite a long time. Here, I try to summarize what I am up to now and what are the projects I’m currently working on.

One area of my activities is related to Bitcoin. It is an exciting way how to transfer value over the Internet and you can read more about it on Wikipedia or on Bitcoin Wiki. With Marek “slush” Palatinus we are building a hardware wallet for Bitcoins called Trezor. We found out that one of the biggest problems of mass addoption of Bitcoin is that it’s very hard to keep your private keys secure. With our solution the keys never leave the keychain wallet, so it is impossible for attacker to steal them. We have couple of other ideas which deal with Bitcoins, but right now we focus on Trezor and we will announce these other Bitcoin related projects once Trezor is out.

Another field is software, hardware and small fabrication consulting effort called fabhack. We founded it together with Tomislav “sargon” Arnaudov, whom I met at Prague hackerspace brmlab. At first we wanted to start something inspired by a western fablab model, but we realised that our knowledge is the most valuable asset and easy access to makers’ technology can be provided by some other groups. At fabhack we try to do projects that are both bleeding edge and fun to make!

During countless nights spent at brmlab we met a famous artist Prokop Bartonicek whom we helped to realize a couple of art projects. Later we decided to create a studio that deals with interactive art installations and hi-tech exclusive objects called pebe/lab. This is a very exciting cooperation for all of us and we are really looking forward to our contracts.

As you can see I’m quite busy with these three enterprises. I decided to give away some of my older ideas for projects, because I’m afraid I will not have a chance to get back to them. See my next blogpost called Idea Factory for more information.

Ars Electronica Festival 2012

| Comments

Last week I attended Ars Electronica Festival with an additional title “The Big Picture”. This was quite a new experience for me, because I usually visit technical conferences, while this one was more about art (but tech was of course present as well!).

The first evening in Linz I decided to spend with folks from hackerspace Linz called DevLoL. Technically, it’s not a hackerspace yet, because they are still waiting for their premises, but once they get them, it’s gonna be great! They are promised around 1000 square meters of space in a former tobacco factory, now a culture centrum called Tabakfabrik. Hopefully they’ll be able to do some amazing projects there soon. We had a great discussion about stuff we do at brmlab and I got some valuable input as well. It’s always nice to see more and more hackerspaces to appear in new places.

The other days were mostly about Ars Electronica. I attended quite a lot of expositions, talks and events. If you’ve never been to Ars Electronica Center, go there, their main exposition is amazing and the tickets are quite cheap (8 EUR full price).

During the festival these two projects caught my eye: CogniToo and BioBookCover. The first one is basically a tattoo of your fMRI scan. The times when people were tattoing the names of their loved ones are past, the future is having a fMRI scan of your brain while thinking about your love. :–) The second one is an attempt to create biodegradable (starch based) plastic, which can be made in amateur environment (like a kitchen) and will dissolve in few days (in contrast to few centuries) in nature if thrown away.

From the talks I mostly enjoyed the talk from Golan Levin. He started with the following image:

I think it’s really a good way how to describe current efforts in technology. He didn’t said that explicitly, but my opinion is that artists are leaning towards interesting-beautiful side and hackers towards useful-interesting side of things. There are also other groups like for example designers, which are positioned somewhere else in the triangle. Golan showed us some examples of interesting-beautiful projects like: Most Wanted and Least Wanted Paintings by Komar Melamid, Every Playboy Centerfold by Jason Salavon or The Secret Lives of Numbers by himself.

Other nice talks I attended were about about Free Universal Construction Kit and Apertus, an open source camera. It’s nice to see that an idea of open-source hardware is advancing in these more-or-less artistic fields as well.

But undoubtedly, the main attraction of the festival were so called Klangwolke (Sound clouds). This is a tradition that happens on the bank of Danube river every year and this time there were around 90000 participating people. Around one thousand of them used an opportunity to make a big blinking letter during the festival and these were connected via network during the performance. The letters were not the only things blinking, we also had a chance to see buildings with projections and 50 quadcopters flying changing colour and flying in nice formations. See the video for yourself:

I’d like to thank all people I hanged out with (especially Prokop who made the trip possible and Szara who kindly sheltered me) and I hope I’ll be able to visit the event next year as well!

Convert PyQt4 Applications to PySide

| Comments

I just noticed (little bit late, but better later than never :–)) that PySide has become an official part of the Qt Project.

Thus I decided to rewrite all my PyQt4 applications to PySide. There are couple of options how to make your code to work with both PyQt4 and PySide, but in my opinion this adds a lot of cruft to the source code and there’s no reason to stay with PyQt4 so most of the systems will migrate to PySide in the near future. If you want to learn about these options anyway, consult the Supporting Both APIs section of the Differences Between PySide and PyQt at Qt wiki.

This document has also been a very helpful source of information for my simple script that converts your code from PyQt4 API to PySide. Please note that it’s not a 100% fully automated conversion, just a bunch of simple replacements and a scanner for problematic API usage like using QString, QVariant or the return value of QFileDialog methods. I am releasing it because I still do think it’s quite helpful and covers most of the cases.

Grab the source on github and of course you are welcome to send your patches/pull requests. :–)