SpreadsheetLight gradient fill function

I’m fascinated by gradient fills in a spreadsheet. More specifically, why would anyone want to have a cell with gradient colours? Is a standard block colour fill not enough? Is a texture image fill not enough? I guess this comes down to the visual aspect. Humans like to look at pretty colours. Especially if you have to stare at financial figures in a spreadsheet for hours.

So, that spreadsheet library I’m working on? It can do this:
Gradient fills in SpreadsheetLight

The code to do that is

SLDocument sl = new SLDocument(SLThemeTypeValues.Flow);

SLStyle style = new SLStyle();
style.Fill.SetCustomGradient(GradientValues.Linear, 45, null, null, null, null);
style.Fill.AppendGradientStop(0, SLThemeColorIndexValues.Light2Color);
style.Fill.AppendGradientStop(0.2, System.Drawing.Color.Red);
style.Fill.AppendGradientStop(0.4, System.Drawing.Color.Green);
style.Fill.AppendGradientStop(0.6, System.Drawing.Color.Blue);
style.Fill.AppendGradientStop(0.8, System.Drawing.Color.Yellow);
style.Fill.AppendGradientStop(1, SLThemeColorIndexValues.Accent1Color, 0.5);

sl.SetCellValue(2, 3, "Custom gradient function");
sl.SetCellStyle(2, 2, style);

style = new SLStyle();
style.Fill.SetGradient(SLGradientShadingStyleValues.DiagonalDown2, SLThemeColorIndexValues.Accent2Color, SLThemeColorIndexValues.Accent6Color);

sl.SetCellValue(4, 3, "Built-in gradient function");
sl.SetCellStyle(4, 2, style);

sl.SetColumnWidth(2, 24);
sl.SetRowHeight(2, 108);
sl.SetRowHeight(4, 108);


The gradient stops are positioned from 0.0 to 1.0. The “built-in” functions (simulating Excel) allow you to specify only 2 colours, even though you can have more.

You will notice that the library allows you to use both theme colours and System.Drawing.Color’s. You can even specify a tint modifier (as seen in the last gradient stop), which range from -1.0 to 1.0 (-1.0 being completely dark, and 1.0 being completely white).

You might also notice that you don’t need to declare many variables from the library. For most of your work, you just need to know SLDocument class (which handles most of the spreadsheet’s functions), and the SLStyle class (which handles all your styling needs). Most of the functions are overloaded, which is why the functions are squeezed into fewer classes.

Here’s my rationale: I walk into a party. I don’t really know anyone. I find one person that I recognise. Probably the host. Then I let the host introduce me to everything. Who the interesting people are. Where’s the food. Where’s the washroom. Look, I don’t mind meeting people in the party, but I’m not really into that particular party. I just want to mingle a little so I can tell my friend that yes, I was at the party. Mission accomplished…

Then I go to that other party that I really wanted to go. (no offense to the host of the first party. “None taken.” Aww, isn’t he a nice guy?).

I don’t want to burden you with yet another software library to learn. So I’ve made it easy. 2 classes for most of your needs. If you’re using one of them intelligent code editing software, you’d get auto-completion too. Exploring what else a class can do for you is just a “.” away.

Yes, I’m finishing the library. It’ll be ready soon, ok? Just a couple of features more, and some testing, and I’ll launch version 1 of the product. I don’t give a flying fishball about eternal software betas. (Just launch already, dammit! Stupid software startups…)

Colour of numbers

I was mucking around in my image editor (Paint.NET) because I was doing some CSS colour editing. While I was playing around with the HSV of the colour, I saw this in the RGB box: 314159. You know what that reminds me of? PI. No, not that pie, PI! Great, now I’m hungry…

So I wondered what numbers would look like if they had colours.

First, we have PI as 3.14159 (ratio of a circle’s circumference to its diameter)
Colour of PI

Then we have the constant e, 2.71828
Colour of e

Fibonacci and his sequence also make an appearance: 1, 1, 2, 3, 5, 8 (13, 21, 34, …)
Colour of Fibonacci sequence

We also have the golden ratio, 1.61803. It’s also the limit as the (n+1)th term divide by the nth term in the Fibonacci sequence.
Colour of golden ratio

For some reason, I remember the Avogadro constant, even though I don’t do chemistry or physics anymore… It’s 6.02214179 x 10^23. Yes, it’s a big number… The colour also reminds me of bromine gas, which is reddish-brown in colour. Wait, how come I still remember these things?
Colour of Avogadro constant

Here’s an interesting one. Absolute zero is the theoretical temperature where everything barely has energy. It’s defined as 0 Kelvin, and is equal to -273.15 degree Celsius. And you thought ice at 0 degree Celsius was cold…
Colour of Absolute Zero

Choosing colours

Colours of the rainbow
Graze from rage to royal
Beauty on eyes they bestow
Passions inside us they boil

What colour? by Christopher O Driscoll @ iStockphoto

We don’t have a graphic designer in the office. So it’s up to the individual developer to come up with graphics, styles and design. Well, you can imagine the look of the applications created. My colleagues and I try to assuage the situation by making sure our own applications look decent.

Without much training or good image editing software available, there’s only so much we could do. Swathes of colour, cool looking fonts and some simple images. Luckily I have Paint.NET to tide over some pixel operations.

Anyway, I have to choose colours fairly often. The colour of the text, that of the background, and that border lining. CSS does an amazing simplication for web applications. It can’t tell me what colours to use though.

I wrote about my agony over web safe colours before. This is like a continuation of sorts. So for colour selection, there’s the colour wheel and rectangular blocks of colour arranged in a grid according to red, green and blue values.

The thing with swathes of colour is that, they are continuous. Trying to decide which of two close points on the colour wheel give a better “feeling” makes my head hurt. So I have this handy colour chart to help with at least coming up with a starting colour. Please have a look before reading on.

Alright, so the colours defined by the KnownColor enumeration in .NET framework don’t form any kind of standard. You’re missing the point. I use them as a starting point, sometimes even as the colour I want. Because I arranged the chart by sorting with colour names alphabetically, the colour chart displays colours with similar hues usually away from each other.

This gives my eyes distinct patches of colour to look at. I can find that exact hue I want because of the added variable of distance. With the other surrounding colours, the ideal hue sometimes jump out at me.

The problem isn’t with designing. It’s about indecision. Whether you’re designing the look of a web page or designing the code structure is secondary. Your inability to decide, stalls the project.

I’m better with writing code. I’m learning to improve my web design skills. So I wrote a program to generate a colour chart, which helps me make faster design decisions. What did you do?