STANDARD DISCLAIMER

Everything in this blog is my opinion and does not in any way, shape, or form represent the opinion or officially stated position of Microsoft, Google , or Kim Jong Il
this is fairly obvious when one considers I have no official capacity in any of these organizations.

Thursday, May 30, 2013

There is no way this happened randomly

One of the things I hear often re the universe , creation et al is the standard “There is no way this happened randomly just look around you man LOOK I SAY ! fractal clouds and cauliflower florets”

Which is all well and good and I am not going to debate the god superstition here however sometimes  its nice to look at the power of random( warning some minimal math and coding involved but you should be able to skip and skill get the flavour of what I am saying ) Editors Note Yeah Maybe

So let us start with a triangle . You know the things that aren’t squares rectangles or circles or anything other than triangles. So we have something like this

                            A

Bimage C

 

Cool Eh !

Now assume there is a point far far way somewhere in the universe . Now roll a perfectly fair die. Here is what we are going to do .

If the die shows up a 1 or a 2 we are going to pick a point halfway between the original point and A and color the midway point blue

if the dice is 3 or 4 then pick halfway between the current point and B and color it red

if the dice is 5 or 6 then pick halfway between the current point and C and color it green

Please note that the numbers on the dice are not relevant All we are doing is randomly picking one number from 3 where all 3 numbers are equally probable to occur in our random picking.

With me So far?

So lets say we rolled a 1 a 3 and a 6. After 3 attempts our triangle with dots ( in  G minor :-) ) now looks something like

image

AS the avid and observant readers will have figured out by now : you keep rolling the dice and the colours just randomly start filling up the triangle . On obvious point to note is that once a dot lands inside the triangle all further dots will lie inside the triangle too.There is nothing clever about this , since we are always computing half way point to each edge point we stay within the boundary of the triangle

 

So at his point we have this really clever way of randomly dumping dots on a triangle and really you can get any kid with a crayon and paper ( or wall ) to do this

 

But lets say we run this process a million times ( computers are pretty good at that source code later ). SO a million dots of the primary colours randomly placed over the screen. What do we expect the resultant picture to look like? Anyone?

Well my guess was this amorphous blob of black or gray or maybe even some weird mixing of colours or whatever but definitely almost no structure . And if we ran the program again well this time would get totally different dots of course so like some other random scribbling

 

 

I’ll spare you the suspense . HERE IS WHAT YOU GET EVERY SINGLE TIME NO MATTER THE ORDER OF THE DOTS

 

PRETTY EFFING COOL EH!

Pseudo code in the link…

 

Finally if you have more than a passing knowledge of the math needed to understand Fractals or affine transforms or IFS etc and you know who Michael Barnsley is please spare me everything that is wrong with my simplified explanation :-)

IT still always gets me all excited when a random dice roll can get us this . Maybe this is what the rest of the world is talking about when they talk about a “spiritual experience “

SIERPINSKI YEH TUNE KYA KI

 

image

OH YEAH!

You can generate this in code really easily

Start with a type

internal class VInfo
    {
        public int x;
        public int y;
        public Color c;
    }

int width = 2000;
int height = 1000;

Initialize thusly

Veritices[0].x = width / 2;
Veritices[0].y = 0;
  Veritices[0].c = Colors.Blue;
  

Veritices[1].x = 0;
Veritices[1].y = height;
  Veritices[1].c = Colors.Red;
  

Veritices[2].x = width;
Veritices[2].y = height;
  Veritices[2].c = Colors.Green;

So at this point you have the triangle set up right .

Now just run  a loop somewhere like so

Random r = new Random();
            Random InitPoint = new Random();
            VInfo pCurrent = new VInfo();
            pCurrent.x = InitPoint.Next(1000);
            pCurrent.y = InitPoint.Next(1000);

for (int i = 0; i < 10000000; i++ )
            {
                int p = r.Next() % 3;

                pCurrent.x = (pCurrent.x + Veritices[p].x) / 2;
                pCurrent.y = (pCurrent.y + Veritices[p].y) / 2;
                setpixel( bits,pCurrent.x,pCurrent.y,Veritices[p].c);

            }

So all you are doing  is getting a random point computing the halfway point between the random point and the vertices you need to and setting the pixel to that colour  AND…. repeat

Its really quite amazing how this simple random process can generate that image…

Sunday, May 12, 2013

But But they are stealing my hard earned money

 

This whole notion of how taxation equals theft and you know “hard earned money” just drives me nuts. IT IS NOT THEFT TO PAY YOUR TAXES

Libertarians love to drool on and on about you know contract law etc, well here's is the implied contract when you become a citizen of this country , YOU HAVE TO PAY TAXES, AND ELECTED LEGISLATORS GET TO DECIDE HOW MUCH THOSE TAXES ARE AND HOW THEY SPEND THAT MONEY

Your choices are

i) go to a jurisdiction that has no taxes, Dubai for example

ii) participate in the electoral process by electing people who agree with you in terms of tax rates and how your tax dollars should be spent

I happen to think that abstinence only education or creationism or the war on drugs or the war in Iraq  or no bid contracts to Halliburton or the house GOP spending money on defending DOMA or drug testing welfare recipients are all ABSOLUTELY HORRENDOUS, NO RETURN VALUE, ways to spend our money and so you wont find me in general voting for candidates or parties that support these positions

But it’s not theft. They did not steal my money . I would have to pay those taxes no matter what and you what I am just fine with that. That was the contract I signed on to when I got here , that I would pay taxes

Insisting that taxes are theft is like saying the cable company is stealing from me because you know I did not like every single hour of programming on every channel .

Just like you get to not like some programming you get to not like ( and or rant about )certain expenditures , AND you get to participate in whatever legal fashion you choose to change the laws so as to change govt. spending ( for example WA state just made weed legal , yes yes yes CO here’s looking at you too :-) ). But enough with the Theft bullshit already!

Morons !