FireWallpaper, a Live wallpaper for Android
Burn stupid smartphone ! Burn !
Status : published on Android market
https://market.android.com/details?id=org.nicolasmy.firewallpaperJust wanted to make a live wallpaper on Android, so I started with one of the most simple effect, the fire effect.
Btw, I can't believe people are trying to sell flame live wallpaper on Android market (with very little success).
1. Set up a wallpaper project on Android.
A live wallpaper main application class should extend WallpaperService
public class FireWallpaper extends WallpaperService {
...
}
Inside this class, you should alse have a class that extends android.service.wallpaper.WallpaperService.Engine
class FireEngine extends Engine {
@Override
public void onVisibilityChanged(boolean visible) {
mVisible = visible;
if (visible) {
drawFrame();
} else {
mHandler.removeCallbacks(mDrawCube);
}
}
}
This class is the main drawing class that will actually write in the canvas.
It should only be active when visible, that's why we are catching the onVisibilityChanged event.
Here is the application manifest, specific for live wallpapers:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.nicolasmy.firewallpaper">
<uses-sdk android:minSdkVersion="7" />
<uses-feature android:name="android.software.live_wallpaper" />
<application
android:label="@string/wallpapers"
android:icon="@drawable/ic_launcher">
<service
android:label="@string/wallpaper_firewall"
android:name="FireWallpaper"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper" android:resource="@xml/main" />
</service>
</application>
</manifest>
2. Fire effect
fire effect is one of the oldest graphical effect that was invented. I rember back in the good ol' days of DOS, and its famous 13h mode (320x200x256 colors paletized 5 bits per channel).
Making a digital fire:
- color palette where higher index means hotter pixel ( white => max, black => min)
- an algorithm than average surround pixel for each pixel on the screen.
- on each frame drawn, ignite the fire in some part of the screen by putting random pixels with the highest ignition value (white pixels).
- by successive averaging, surrounding pixel will slowly shade in tone of white-yellow-red-black, so that it mimics a real life fire.
- tune the fire : intensity (by settings the number of random hot pixels spawn on the screen), set the neighboring pixels that should be taking into account. For the bottom to top motion of a typical fire, it's best to take 2 bottoms pixels for the current pixel into calculation.
I've finished this in few hours, mostly spend on try to find the right tune for the fire. I must say it looks reasonably good.
I've added the ability to set wallpaper refreshrate, fire intesity (in fact quantity of high temperature pixels spawn on each frame), and fire height (top, medium or low proportionnaly to screen resolution).
Last minute idea, but a nice one : incorporate touch as a mean to ignite small fireball where fingers touch screen.