Creating Shapes with PathBuilder

In a previous post I showed a quick demo of a PathBuilder class I created to help draw dynamic shapes. I would like to include a simple example of how to create Shape controls using the same tool.

I have created a very simple Triangle control which you can download and see run.

Download Triangle Demo

Here is the actual Triangle class

class Triangle : Shape
{
    private Geometry geometry;

    public static readonly DependencyProperty P1Property = DependencyProperty.Register(
        "P1",
        typeof(Point),
        typeof(Triangle),
        new UIPropertyMetadata(OnPointChanged));

    public static readonly DependencyProperty P2Property = DependencyProperty.Register(
        "P2",
        typeof(Point),
        typeof(Triangle),
        new UIPropertyMetadata(OnPointChanged));

    public static readonly DependencyProperty P3Property = DependencyProperty.Register(
        "P3",
        typeof(Point),
        typeof(Triangle),
        new UIPropertyMetadata(OnPointChanged));

    public Point P1
    {
        get { return (Point)GetValue(P1Property); }
        set { SetValue(P1Property, value); }
    }

    public Point P2
    {
        get { return (Point)GetValue(P2Property); }
        set { SetValue(P2Property, value); }
    }

    public Point P3
    {
        get { return (Point)GetValue(P3Property); }
        set { SetValue(P3Property, value); }
    }

    private static void OnPointChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        ((Triangle)sender).UpdateGeometry();
    }

    private void UpdateGeometry()
    {
        this.geometry = PathBuilder.Start()
            .Move(P1)
            .DrawLine(P2)
            .DrawLine(P3)
            .DrawLine(P1)
            .Close()
            .ToGeometry();
    }

    public Triangle()
    {
        this.UpdateGeometry();
    }
        

    protected override Geometry DefiningGeometry
    {
        get 
        {
            return this.geometry;
        }
    }
}

Notice I inherited from Shape and use the PathBuilder to generate a Geometry object and return it in the protected DefiningGeometry property.

I had to add one method to my PathBuilder:

public static Geometry ToGeometry(this IPath path)
{
    var converter = new GeometryConverter();
    return (Geometry)converter.ConvertFromString(path.Data);
}

This method converts the path string into a Geometry object. Here is the xaml to display this control:

<c:Triangle P1="0,0" P2="0,100" P3="100,100" StrokeThickness="1" Stroke="Black" Fill="Blue" />

And finally the Triangle in action

image

Remembering Complex Passwords

This is a problem that has been written about over and over again, the proposed solutions are complex and there appears to be no relief in sight. People are reusing the same simple passwords over and over again and the only alternative is a complex trade-off between poor user experience, incompatibility and putting all your eggs in a single basket. I’m not sure how brilliant of an idea my solution is but I’ll explain how I try to manage this complexity.

First off, I have 4 tiers of passwords. I have one very complex password for work, gmail and my bank account, one for less important sites that I really would rather wasn’t hacked like facebook and Windows Live. One that’s a throw away password that I really couldn’t care if anyone hacked and one that I share among family and friends (my home router, my personal svn, etc.)

For my top tier password I have come up with a trick for creating and remembering them. I think this is a handy trick and can work for anyone and will generate a very strong password. I have created a simple tool to help.

pass

EDIT: try it live at jsfiddle

Once a month or every other month simply print out, or write down the above graph onto a piece of paper. Visualize a line or a shape with a bend such as a V somewhere in the graph. This is your password. Remember the first letter, the last letter and the shape. Change your passwords and leave this sheet somewhere nearby face down. Try to login by remembering this complex password. If you cannot, flip over the sheet, take a look and try again. If you flip over the sheet start typing from the beginning again. After a couple of tries you will be able to remember without the sheet. Don’t discard it, keep it nearby in case you forget again.

In the meantime, if anybody finds your printed sheet it is not readable. If the CIA finds it, it might help them to narrow it down enough to crack it but if you’re concerned about that then I can’t really help you.

My second tier password I choose a word that is easy for me to remember and basically use l33t speak to augment it. Basically replace letters with either numbers or special characters depending on what the password box is requiring.

My third and fourth tier is just some stupid dictionary word that’s easy for me and friends to remember.

All but my top tier passwords are stored in a Google Docs spreadsheet so if I forget I can go and find it in there. That spread-sheet is protected by my top tier password.

The Moral Vegetarian

I came across a blog post today requesting moral arguments against vegetarianism. There were many interesting points and counter-points, many of which were simplistic. The author gathered the answers as fodder for writing longer rebuttals on her blog.

I have a response which I have been forming for several years, since I find moral vegetarianism to be trite and irrational and I have more than once been confronted with it I have had cause to think about my response more than once. Here was my response to K-Rina.

 

As far as I know plants don’t feel pain. As far as I know pain is purely an “animal” construct. This doesn’t mean that plants don’t have their own survival strategies however. We place a great deal of concern into pain and suffering, naturally, since we are animals and can empathize with pain and suffering. However pain is simply an adaptation for survival, different from plants but plants have their own similar adaptations. For a very interesting example read about the Acacia tree. When giraffes begin eating it, it will begin to produce a toxin that will make the leaves poisonous to giraffes. Therefore giraffes will approach the trees from down wind and only eat on them for a short period of time. There are many other examples of offensive and defensive mechanisms that plants have evolved as a means of surviving in their various habitats (thorns, poisons, colors, pine cones that open after fires, etc.)

Furthermore some animals have formed a co-evolutionary relationship with humans, where their existence as a species is completely dependent upon humans wanting to eat them. Many breeds of modern cows, for example, would probably not live long if they weren’t also eaten by humans. This is a similar relationship that bees have with orchids, corpse flowers have with flies, dairy ants have with aphids, etc.

The concepts of pain, suffering and personal death all have no meaning evolutionarily other than how it affects the adaptability and ultimately the survival of the entire species.

So plants are just as alive as animals and we humans tend to apply our anthropomorphic bias’ towards animals since we are ourselves animals. I think the moral vegetarian is simply showing a conceit and a overly simplistic understanding of evolution and the circle of life.

If I went into a forest right now and chopped down an old oak tree and left it there to rot would that be immoral? I think so. The moral wrong is the act of unnecessarily killing anything. Humans cannot photosynthesize therefore anytime we eat we must kill for that food. This is totally morally acceptable as long as what we eat improves our long term survival as well as the long term survival of other life forms. It’s ok to eat a few leaves off of a plant in the same way it’s ok to eat a few cows out of a herd.

As the most intelligent species on Earth it’s our duty to understand this and attempt to promote the largest diversity, continual evolution, and maximum habitation of life on this planet.

VS Minimalism

I’ve been trying to become more and more minimalist with my use of panels and toolbars lately. I realized I do almost everything with the keyboard and the few things I can’t do are in the main menu somewhere anyway. I never use those toolbars and they just add a lot of clutter. There’s also a host of other panels I never use (especially the TFS panels, which I hate). I do have an Expression Dark theme applied but I’m still decided whether or not I like it.

image

  • No toolbars
  • No main menu
  • No Solution Explorer (Solution Navigator instead)
  • No Toolbox or Document Outline
  • No left panels
  • TestDriven.NET
  • No Resharper

 

image