Back to Business

I’m back from Canada. Actually I’ve been back for a week now, but I’ve been too lazy to post. About the article I said I was working on, well…I’m still working on it. It turned out to be a more complicated than I thought, so I’m going to need more time to get it done. Meanwhile I’ll try to start posting on my blog more often. To start off I’ll post about what I’ve been up to since I got back from Canada.

Last week I finally graduated from high school. the actual graduation was not until Saturday, but we had a graduation party on Thursday. It feels nice to finally be over with high school, I couldn’t stand some of my classes anymore. Fortunately, from now on all of my classes will be related to Mathematics which should be fun. I’m still not sure what mathematicians do for a living, but that’s what I want to study. I’m starting university on August, so I’ve still got more than a month left of vacation, although to be honest I’m not sure what I’m going to do all this time.

Other than graduating and wasting my time, I’ve been watching Friends and playing with my new Nintendo DS Lite. I wanted a Nintendo DS ever since they first came out, but somehow I was never convinced that I should get one, until the DS Lite. Right now, I have six games: New Super Mario Bros, Mario & Luigi: Partners in Time, Brain Age, Metroid Prime Hunters, Tetris DS and Mario Kart DS. The only ones I’ve really played are New Super Mario Bros and Brain Age. New Super Mario Bros is simply amazing, I already finished the game but I’m still playing to get all of the Star Coins and the alternate routes. I’ll write a lot more about it when I’m done playing it. As for Brain Age, somehow it’s actually fun to play the “brain training” programs. In case you’re wondering, I haven’t played in the last couple days, but last time I checked my brain was in its 30s which seems pretty bad since I’m actually 19. I should really get back to training to see if I can make my brain get younger. As for Friends, before I went to Canada I started watching all ten seasons, and I’m almost done. I think I’ve finally decided that Friends is my favorite TV show of all time. I wasn’t sure if I liked it better than Seinfeld, but after watching all of the seasons back to back I think I like Friends more. Right now I’m about halfway through season 9 which means that there’s only about one a half seasons left. I will probably finish watching the tenth season sometime this week; I’ve spent so much time watching Friends lately, that I’m not sure what I’ll do when I’m done watching all the episodes.

Anyway, that’s it for today, hopefully I’ll start posting more often from now on. It would help to have some visitors though. So if you’re reading this, please come back soon, or better yet, subscribe to my RSS feed.

New Articles up

Today I posted two new articles. First, I released Chaotica, a Mac OS X application to draw fractals using the Chaos Game. For more information follow the link. It’s amazing how with a few very simple rules and playing around with a few parameters you can create some very nice fractals. If you haven’t already, you should try it out. I’ve been thinking about some of the changes that would be great for future versions of Chaotica, like the ability to choose the exact positions of the vertices, or to use OpenGL to improve the performance. I’m not sure, if I’ll ever get to do this, but it’s definitely in my mind. The other article I posted comes from my old blog. It explains how to sort a list like the Finder does, I think that Cocoa programmers will find it very useful. There really isn’t much to say about this one, but if you’re interested feel free to use it, here’s the link.

I have another article planned to explain some aspects of the Chaos game, but I’m not sure of when it’ll be available. Hopefully, I’ll be able to finish it before friday, but if not, it’ll have to wait till I get back from visiting my sister in Canada.

Sorting Like the Finder

Something that most Cocoa programmers are likely encounter in their lifetimes is trying to sort a list like the Finder. At first sight, it might seem like there’s nothing special about how the Finder sorts; it looks like a plain old alphabetical sort. But it isn’t, there are many subtleties with the way in which the Finder sorts a list of documents. A simple example of this is when you have three documents called “1”,”2″, and “10”. A normal alphabetical sort would order them: “1”,”10″,”2″. But the Finder is smart enough to order them: “1”,”2″,”10″.

The basic code to sort like the Finder comes from Apple’s Technical Q&A QA1159. Using this code, I created a category for NSString which adds a method called finderCompare: to the NSString class. This way you only need to create an instance of NSSortDescriptor and initialize it using initWithKey:ascending:selector: where selector: should be @selector(finderCompare:). Then you just need to use this instance of NSSortDescriptor whenever you want to sort something like the Finder.

You can find the code for the category below, or you can just click here to download the file. To use this file you only need to add it to your Xcode project.

#import 

@interface NSString (FinderCompare)

- (NSComparisonResult)finderCompare:(NSString *)aString;

@end

@implementation NSString (FinderCompare)

- (NSComparisonResult)finderCompare:(NSString *)aString
{
	SInt32 compareResult;
	
	CFIndex lhsLen = [self length];;
        CFIndex rhsLen = [aString length];
	
	UniChar *lhsBuf = malloc(lhsLen * sizeof(UniChar));
	UniChar *rhsBuf = malloc(rhsLen * sizeof(UniChar));
	
	[self getCharacters:lhsBuf];
	[aString getCharacters:rhsBuf];
	
       (void) UCCompareTextDefault(
          kUCCollateComposeInsensitiveMask
        | kUCCollateWidthInsensitiveMask
        | kUCCollateCaseInsensitiveMask
        | kUCCollateDigitsOverrideMask
        | kUCCollateDigitsAsNumberMask
        | kUCCollatePunctuationSignificantMask,
        lhsBuf,
        lhsLen,
        rhsBuf,
        rhsLen,
        NULL,
        &compareResult
       );
	
	free(lhsBuf);
	free(rhsBuf);
	
	return (CFComparisonResult) compareResult;
}

@end

Chaotica


Click to enlarge.

Chaotica is a Mac OS X application that draws fractals using the Chaos Game method. To use Chaotica you simply need to specify the number of vertices that will be used, how the vertices will be chosen, the fraction that will be used, and the number of iterations performed to generate the fractal. Chaotica will first choose a point inside the drawing area at random and then it’ll choose one of the vertices, also at random. Next, it will draw a new point at the chosen fraction of the distance between the point and the chosen vertex. After that, it will use the newly drawn point and pick a new random vertex and repeat the process to find the next point. Each time a new point is picked is called an iteration. You can change the settings in Chaotica to create many different fractals. Here’s a description of what each option in the New Fractal window and the Preferences does:

New Fractal window:

  • Regular Polygon – If selected, the vertices will be placed to form a regular polygon.
  • Random – If selected, the vertices will be placed randomly inside the drawing area.
  • Vertices – A number between 3-12. It determines how many vertices will be used to create the fractal.
  • Iterations – A number between 1-100,000. It determines how many points will be calculated.
  • Fraction – The fraction that will be used to determine the distance at which a new point will be added.
  • Use fraction for Sierpinki n-gon – Uses the fraction necessary to generate the Sierpinski polygon with the selected number of vertices. An explanation on how this works is coming soon.

Preferences:

  • Background color – Self-explanatory.
  • One color for all vertices – If selected, all points are drawn with the same color.
  • Color depends on the vertex – If selected, the color of the points depends on which vertex was chosen when calculating where the point should be. This option generates nicer looking fractals.


Welcome!

I think it’s finally time to start posting. I’m very proud of this new website, here’s why. I’ll start with the design. First of all, I like the buttons at the left a lot. I’ll admit that right now since there is only one button it looks a bit stupid, but trust me, when there are many buttons you’ll be moving your mouse around them just for fun. Also, if you are using a browser other than Internet Explorer you should see some really nice shadows on the sides of the main part of the layout. I did my best to try to get the shadows to work on Internet Explorer, but since IE has no respect for CSS, it wasn’t possible, so the shadows are not visible if you are using IE.

But the looks are not my favorite part of this new website. Again, if you are using a browser other than Internet Explorer, try making the text bigger. The whole page grows, not just the text. I think people should be able to choose whichever font size they’re comfortable reading and the design should adapt to it. No one should have to choose between ruining their eyesight and ruining the website’s layout. Another thing I like is how the website reacts to being resized. The web developer community often debates about which is better, liquid layouts or fixed layouts. Liquid layouts take advantage of the size of your browser window, but many users (especially those on Windows) cover their whole screen with the browser window which makes liquid layouts end up with really long lines which are hard to read. On the other hand, fixed layouts allow the web designer to have control over the length of the lines, but don’t really care about the size of the window and waste a lot of space because they are usually designed to work on small screens. But, why not combine both? Try resizing your window. When the window is small enough the layout will shrink and grow along the window, but when the window is too large, it will keep a fixed size to avoid having huge unreadable lines.

The last thing I really like about my new website is that it is easily updated. The entire website uses WordPress, but there are two different types of pages. One type is for my blog posts, and the other one is for the rest of the categories. My blog is pretty much what you would expect from a blog, except that it does not use categories. Instead, the categories are used for the sections of my website and tags are used to classify the blog posts. The non-blog categories are displayed in a more article-like way. But regardless of which type of page it should be on, to post anything new, I just need to create a new blog post and place it in the right category. WordPress was very easy to work with, and I even wrote some plugins to make formatting my posts easier. For example, I can use a bunch of fancy tags for different purposes such as posting spoilers, images of other types of content. Check this out: Show Spoiler You have been spoiled. Or this: Show Content

Look! It’s above the rest of the website, and you won’t see it if you are not interested.

I’m still not sure what I will do with the last one, but it looks nice, doesn’t it? Anyway, that’s all there is to my new website. I’ve been doing a lot of testing lately and I think that everything is working. There is only a small problem with the tag pages, but I’ve tried everything I can think of to fix it and nothing worked. I’ll try to add some more categories and some content over the week.