Plasmatic - My Second Android App

A few days ago I blogged about my first Android app, and in that post I promised another one coming along soon. Well, it is now done.

For my second foray into Android application development, I decided to port some C# code I had previously written to draw a plasma fractal to Java.

Plasma fractal

The original code is based on a Java applet written by Justin Seyster, which I ported to C#, and modified slightly, a few years ago for another project.

I have previously blogged about the algorithm used to generate the plasma fractal itself in my series on Fractals in c#, so I won’t go into detail about how the fractal is generated here.

The application consists of three activies.

  • The main activity displays the generated plasma fractal, with menu options to refresh the fractal, which regenerates the fractal, and saving the image to the sdcard. The menu also has options to launch the settings activity and the about activity.
  • The settings activity enables you to change the fractal type - the options being, Plasma, Cloud and Grayscale – as well as the roughness, which changes the amount of variation in the image.
  • The about activity merely showssome information about the application.

While, by no means, a complicated application, this app implements a fair amount of Androids basic features.

The source for the project is available at https://github.com/sjmeunier/plasmatic

Originally posted on my old blog, Smoky Cogs, on 3 Mar 2011


Read More »

My First Android App - A Dutch Public Holiday App

Having my own Android-based phone now, I have been unable to resist the temptation to try my hand at writing an app for it. Deciding on what app I should write, however, required a bit of thinking.

Firstly, if you have ever browsed the Android Market (and if you own an Android phone, no doubt you have), you will have noticed that it has literally hundreds of thousands of applications available for download (either free or for purchase), so finding an application idea that hasn’t been done a hundred times before becomes a bit of a challenge.

The second thing, is that my Java is a little bit on the rusty side. The last time I have written anything at all in Java was around 11 years ago, and even then my jaunt with Java was rather brief.

This means that to ease myself into the Java development environment of Android, I wanted to go with a relatively simple app, leaving more ambitious projects for later.

So, out of this, I came up with the Dutch Public Holidays app, which all it basically does is give you a dropdown of years (currently only 2011 and 2012), and then displaying the public holidays in the Netherlands for that particular year. Very, very simple!

The actual code of the app is largely based on the spinner tutorial on the Android Developer site, but instead of updating a toast, the application updates the TextView with the info we want, and I rearranged how some of the code worked.

The source for the project is available at https://github.com/sjmeunier/dutchpublicholidays

I intend to write more apps to learn more about Android, and at some stage get my apps onto the Android Market, but that is something for another day…

Originally posted on my old blog, Smoky Cogs, on 24 Feb 2011


Read More »

3D Text with CSS3

Text shadows are one of the new features quickly becoming popular in CSS3. Mark Dotto has used this technique to create 3D text, which is an incredibly ingenius use for this. His post shows how he did it.

The code which Mark wrote to do this shown here, with a few modifications that I made myself, which I will explain in a moment.

h1 {
  text-shadow: 1px 1px 0 #aaa, 
               2px 2px 0 #a9a9a9,
               3px 3px 0 #aaa,
               4px 4px 0 #999999,
               5px 5px 0 #9a9a9a,
               6px 6px 1px rgba(0,0,0,.1),
               6px 0 5px rgba(0,0,0,.1),
               6px 1px 3px rgba(0,0,0,.3),
               6px 3px 5px rgba(0,0,0,.2),
               6px 5px 10px rgba(0,0,0,.25),
               6px 10px 10px rgba(0,0,0,.2),
               6px 20px 20px rgba(0,0,0,.15);
}

So if you are running Chrome, Firefox, Safari or Opera, the following text should be looking a little less flat than usual.

Hello World

How he accomplishes the 3D effect is to create multiple shadows, which build up to the 3D effect. The order of the parameters in the above code for each line of the text-shadow css tag are [x pos] [y pos] [blur radius] [color]. The first 5 lines create the solid shadow in the 3D effect, by successively creating a shadow. In this example, each successive shadow is moved right and down one pixel from the previous shadow.

The original, by Mark, kept the x value as 0px, which creates a vertical effect as seen on his demo, while the code above shows a slanted effect.

The height of the raised look is determined by how many shadows you draw, so in this example, we have a height of 5, but depending on the effect you want to go for, you can have more or fewer shadows to create relatively higher or lower raised effects. The next several lines draw in a more diffuse shadow around the text. This is not strictly necessary for a 3D effect, but it gives a nice shadowy look to the text. Here, the blurring radius is used, in addition to a semi-transparent color, to create the diffuse shadow.

Like with the main shadow, the effect here can be varied depending on how many of the diffuse shadows, their transparency and blur radii you use. The possibilities are endless.

Originally posted on my old blog, Smoky Cogs on 7 Jan 2011


Read More »

Iterating Over Char Values in C#

In C#, the char data type represents a text character. Internally though, this value is pretty much a numeric value.

Think here of Ascii or Unicode values. These codings essentially map a character to a particular numeric value, which is what the char data type stores.

One rather interesting side effect of this is that you can iterate through character values in exactly the same way as you would for an int or long.

In the sample code below, the code loops through all the capital letters of the alphabet, adding each letter to a string.

string alphabet = "";
for (char c = 'A'; c <= 'Z'; c++)
{
    alphabet += c.ToString();
}

Originally posted on my old blog, Smoky Cogs, on 17 Oct 2010


Read More »

A Canine Curiosity

Noisette, our dog, has now been in the Netherlands for 2 and a half months, and has settled in quite nicely. She is enjoying discovering the new smells, new parks, and the new dogs.

There is a strange thing that happens every night though.

In the evenings, Noisette’s favourite thing to do is to snuggle up under her blanket on “her” chair and doze off, experiencing the occasional doggie dream along way.

Each night though, between 9 and 10pm, she wakes up from her sleep, dashes to the window and starts barking, and going crazy. The object of her excitement – a small grey dog (I think a Bishon).

The curious thing about this all, is that this particular dog is the only dog she ever does this for, despite there being quite a few dogs that go walking down our street. In addition to this she has never actually met this dog face to face.

Most nights, she is also at the window barking, while the dog is still a block away from our house, and not once have I ever actually heard any noise from the dog or its owner. The only way I know they are walking past is because Noisette goes so mad.

So then, why on earth does Noisette dislike this particular dog so much? And how does she know when this dog is coming past? Does she hear or smell something that I don’t?

I can’t answer any of these questions, but I do get time every night to ponder them.


Read More »

Writing a Family Tree Application in C#: Importing a Gedcom File - Part 2

Now that we know how gedcom files work (covered in part 1), we need to actually parse the file.

The way in which the gedcom is structured is that each new record entry starts on a line with a 0. All lines with a 1 under that belong to that record. Similarly, lines with a 2 prefix, belond to the the entry prefixed by a 1 directly above it.

This makes processing rather straightforward. All we need to do, is read the file line by line, then split up the line into its components, and process accordingly.

All lines have a number (0, 1 or 2) as the first field in the line, and each field is seperated by a space, for example 1 SOUR FamilyTraces

The second field in the line is usually the keyword which tells us what the data represents. Some keywords will not need an extra data field in the third field, but usually, these types of lines which are grouped together with that line. As an example, the VERS and FORM lines are linked to the GEDC keyword as the 2 in the first field shows they belong to the preceding line.

1 GEDC
2 VERS 5.5
2 FORM LINEAGE-LINKED

Read More »

Writing a Family Tree Application in C#: Importing a Gedcom File - Part 1

In my previous post in this series, I introduced the Family Traces family tree application. Now, I am going to go through the importing of a gedcom file.

Firstly, what is a gedcom file? The gedcom file format is a text file format for the transmission and storage of genealogical data, created by the Church of the Latter Day Saints for their genealogical projects.

A standard gedcom file has a header section, individual records, family records and notes. The various records are linked to each other by ids, in the format of @I1@ for an individual record for example. For a full spec of the gedcom format, have a look here.

Here is a sample gedcom file

0 HEAD
1 SOUR FamilyTraces
2 NAME Family Traces
2 CORP Serge Meunier
1 DEST Standard GEDCOM
1 DATE 2010/02/16
1 CHAR ANSEL
1 GEDC
2 VERS 5.5
2 FORM LINEAGE-LINKED
0 @I1@ INDI
1 John/Smith/
2 GIVN John
2 SURN Smith
1 SEX M
1 BIRT
2 DATE 15 dec 1950
2 PLAC
1 FAMC @F2@
1 FAMS @F1@
0 @I2@ INDI
1 Jane/Doe/
2 GIVN Jane
2 SURN Doe
1 SEX F
1 FAMC @F-1@
0 @F1@ FAM
1 HUSB @I1@
1 WIFE @I2@
1 CHIL @F3@
0 TRLR

Before we start processing the file, we need to have some data structures to hold the data from the file.
Read More »

Writing a Family Tree Application in C#: The Underlying Structure

I love being able to trace my family tree, and have used several good genealogy applications which I have found very useful, including Family Tree Legends and Family Tree Builder. The problem I have though, is that they do not always contain everything which I am looking for, so I decided to write a family tree application to plug in the holes.

Family Traces, which you can download the full source for here, is a fully functional, albeit bare-boned family tree application, which can import and export Gedcom files, calculate ancestors and descendants, and allow you to edit the family tree. Everything is there for a starting point, from where you can develop further reports and functionality.

All of that will come in later posts in this series though. For now, I am going to focus on the core of the application – the data layout. This layout is created within an Access database included with the application.

The two main components of any family tree are individuals and families.

Starting with the individual, each person in the family tree will have a record in the database. The most important data we need for an individual are:

  • Individual Id
  • Name
  • Birth date
  • Birth place
  • Death date
  • Death place

These fields are vital in determining if the person we are looking at is the same person listed in genealogical records, such as birth certificates, genealogical lists etc.

Now data collection for an individual is not restricted to these fields, and you are free to create as many fields as your want for things like physical attributes, cause of death, photos and general notes.

Moving onto families now, a family is what connects different individuals together into a tree.

The main family record will have

  • Family Id
  • Husband Id
  • Wife Id
  • Marriage date
  • Marriage place

This links the husband and wife individual records into the family, and allows you to track the marriage date and place, which is also important in genealogical research, as it may provide crucial hints to the individuals, particularly if the birth and death dates of the individuals are unsure.

The last thing we need is to be able to link individuals as children within a family, and this is done using a separate table, which keeps track of the family id, as well as the individual id of the child, and each family can have multiple individuals attached to it as children.

In the database setup for the application, I also included a field in the individual record for the parent family record, which makes it easier to link the individual to a family as a child when processing the tree. This means that we are able to find the family that the individual is a child of without having to check the family records directly.

Now that is all there is to the core of a genealogy application, so feel free to play around with the application, and I will explain more about how the gedcom file format works in the next tutorial…

Originally posted on my old blog, Smoky Cogs on 22 Feb 2010


Read More »

Image Processing in C#: Part 13 - Colour Filters

Implementing a colour filter is a rather simple affair. All a colour filter will do is specify the percentage of red, green and blue to leave in the image. So, for example, if you would like to see only the green component, then you keep the green component of each pixel unchanged, and set the blue and red components to 0.

You can create interesting filters by playing with the ratios too. So for example to get a brownish filter, you can set the red percentage multiplier to 1, green to 0.6 and blue to 0. Then multiply each component by the respective values. In this example, the red value will be unchanged, and blue will be removed entirely. The green component, however, will be set to 60% of the original value.
Read More »

Image Processing in C#: Part 12 - Decreasing the Colour Depth

Decreasing the colour depth involves converting colour values to standard values.

Specifying an offset, preferably a value evenly divisible into 256, such as 16, 24 or 32, we then need to make sure that the red, green and blue components’ values get rounded off to multiples of this offset.

For example, using an offset of 16, value colour values would be 0, 15, 31, 47,……, 255. and all values would need to be rounded off to these values for each of the colour components.

To be able to do this, we take the component value, and then add half of the offset to the value. We then subtract the modulo of this value and the offset. This then gives values along the lines of 0, 16, 32, …., 256, so we will need to subtract 1 from this, but will need to put in a correction for 0, since that value needs to remain as it is.
Read More »

Tag Cloud

Algorithms (3) Android (10) Astronomy (25) Audio (1) Audiobooks (1) Barcodes (9) C# (69) Css (1) Deep sky (6) Esoteric languages (3) Family (3) Fractals (10) Gaming (1) Genealogy (14) General (2) Geodesy (3) Google (1) Graphics (3) Hubble (2) Humour (1) Image processing (23) Java (8) Javascript (5) jQuery (3) Jupiter (3) Maths (22) Moon (5) Music (4) Pets (5) Programming (88) Saturn (1) Science (1) Spitzer (4) Sun (4) Tutorials (68) Unity (3) Web (9) Whisky (13) Windows (1) Xamarin (2)