Color Gradient Generator

Tuesday, November 12, 2013

A while back, I created a WPF Mandelbrot Set program with zoom abilities. I demonstrated the use of async/await for writing code that works asynchronously (to keep the UI responsive), but is easy to write as synchronous code. Here’s a sample image:The image is grayscale, so I wanted to make it use colors, to indicate the level of “being part of” the Mandelbrot set. The problem here is how to create a nice color gradient that moves smoothly from color to color.One possible option might be to leverage an existing class, such as WPF’s LinearGradientBrush, set up a bunch...

Getting rid of the Start button – Adding a Hook

Monday, September 16, 2013

In the previous post we saw how to find and remove the start button and move the task bar window to the left to occupy the free space left by the former start button.However, we saw that by opening the system tray, the task bar moves back to its original position. We need to know when that happens, and then use the same trick to move it back to the “right” position.To do that we would need to register somehow for the WM_MOVE message. This is one option, and we can verify this using Spy++’s Message window for task...

C# Extension Methods and Fluent Interfaces

Thursday, February 7, 2013

The idea of fluent interfaces is not new, and has many forms. The basic idea is to use a single statement to encompass a series of operations that are natural, or at least simple, to use. There are very few fluent interfaces in .NET – the most well known, which has some fluent interface semantics, is the System.Text.StringBuilder class. Here’s a simple example: public static string BuildInfo(Process process) { return new StringBuilder("Process ") .AppendLine(process.ProcessName) .Append("Started at ").AppendLine(process.StartTime.ToLongTimeString()) ...
one comment

Windows Phone 8 is soon upon us (and MS Israel hands out 7.5 phones)

Sunday, September 9, 2012

(this is not my typical technical post, but it’s nice to have something different for a change)A few days ago Microsoft and Nokia held a press conference in New York, in which Nokia presented two new phone devices running Windows Phone 8: The Lumia 820 and the Lumia 920. This announcement made a short while after Samsung announced its first WP8 device, the ATIV S.You can watch the press conference video here. The 920 sure looks impressive in style and functionality.Windows Phone 8 is expected to be publicly available on October 29th (according to rumors…), a few days after...
no comments

Windows Phone: Playing Sound Effects

Monday, September 3, 2012

I wanted to create a simple timer application for Windows Phone. The timer would count backwards from a user configured value and when it reached zero, it would play some sound effect to indicate expiration. Sounds simple enough…This is how the application looks like:The problem turned out to be playing that sound effect. I had a WAV file I wanted to play. Silverlight has a MediaElement object that is capable of playing video and/or audio, so it seemed to be a good candidate for the job. MediaElement is an element, so must be placed somewhere in the visual tree....
no comments

Console Calculator with Roslyn (Part 2)

Wednesday, August 8, 2012

In the first part we created a simple enough calculator, but it lacked two features I wanted to have:1. work with degrees or radians in trigonometric functions.2. allow simple variables to be used without first declaring them.Let’s see how we can implement these features, starting with the first.Trigonometric functions work in radians, which is sometimes inconvenient.What we need is a way to change the parameter to the trigonometric functions by multiplying it by PI/180 if degrees was requested.First, we’ll create a simple state managing class for the calculator with just one property: class CalculatorOptions {     public...
no comments

Towers of Hanoi–WPF Style (Part 2)

Monday, February 13, 2012

In the first part, we saw how to recursively solve the Towers of Hanoi problem in C#. In this post I want to show a graphic view of the solution. This is a starting position with 7 discs: This is how it looks when the problem is solved: In between, the discs move with animation from pole to pole, as the solution dictates. Options include speeding up the process (with the slider, very useful), pausing the animation and resetting to the initial state. Here’s something in the middle: The Poles The poles are built as thick...
2 comments

Towers of Hanoi–WPF Style (part 1)

Saturday, February 11, 2012

I remember many years ago (at least 15), I was learning Prolog. I used the “Turbo Prolog” package from (what was once) Borland. One of the nice examples there was a solution of the Towers of Hanoi, with a simple animation that showed the steps graphically. This was all textual graphics (today’s Console windows), but it was impressive (at least it impressed me). Prolog was used to show off its AI capabilities, which are, in fact, a recursive, backtracking engine. No matter; we can do it in C#. Towers of Hanoi The story of the Towers originate from an...
3 comments

A New Android Game in Town (by my brother)

Sunday, February 5, 2012

Anyone who has ever written a game knows it’s hard to get it done from start to finish. Sure, I can put on a demo of some game I’ve created in several hours. But creating all the graphics, sound, animation, levels, transitions, scoring, etc, from start to finish is quite a challenge, especially for a single developer. That’s why I’m very proud of my young brother, Yaniv, that has worked hard for the past 10 months (while maintaining a proper day job!) on an awesome  fun game called Micro Wars, targeted for the Android platform. This game plays especially...
5 comments

Calculating PI in .NET

Friday, December 30, 2011

I always loved mathematics. Although I’m certainly not a mathematician by profession, I’m always intrigued and inspired by math’s pureness and cleverness. One of the simplest and fascinating aspects of math is the number PI. Described simply as the ratio of a circle’s circumference to its diameter, it’s a constant with infinite digits after the decimal point and most importantly, non repeating (at least as far as I know). There are many ways to calculate PI, as evident within the PI Wikipedia link. I wanted to see how I can get a large number of digits of...
5 comments