NoshBar's Dumping Ground




Compile using Visual Studio or GCC/G++ (gcc main.c -lm, or g++ main.cpp)


/*
 This simple program was thrown together to see if tossing thousands of sausages at lines can be used to calculate PI, described here: 
 http://www.wikihow.com/Calculate-Pi-by-Throwing-Frozen-Hot-Dogs
 Basically you take a sausage of length N, draw a bunch of lines that are distance N apart, and throw some sausages towards the line.
 For every throw, increment a throw counter TC, and for every hotdog that comes to rest crossing a line, increment a cross counter CC.
 After you're tired of manhandling sausages, calculate PI by doing: pi = TC * (2 / CC)

 There are many better ways to do this, this was simply the quickest way I knew to code it up for instant gratification.
 For what it's worth, this had PI accurate to 6 digits after a few million iterations (and was no better off after a few trillion)

 NOTE: It turns out that adjusting the hotdogGirth to be anything but 0.0f tosses the estimate/convergence out quite a bit.
       so for now, we're throwing _really_ thin needles instead.
	   (instead of a width of 0, I guess you could make a really long and thin needle too)
*/

#define _USE_MATH_DEFINES //to calculate some things, and compare our answer to M_PI, we need to set this define, so that math.h exposes it
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <stdint.h>       //for int64 support

int main(int argc, char *argv[])
{
	uint64_t tosses         = 0;                             //total number of tosses
	uint64_t crosses        = 0;                             //how many hotdogs came to rest crossing a line
	double   hotdogGirth    = 0.0f;                          //the width of the hotdog, defines the radius of the cap at the end
	double   capRadius      = hotdogGirth / 2.0f;            //the radius of the round bits/cap at the end
	double   shaftLength    = 1.0f;                          //the length of the hotdog shaft, that is, only of the straight parts, excluding the curved ends
	double   halfShaft      = shaftLength / 2.0f;            //we're working with circles centered around 0, so it makes sense to have some radius's pre-calculated
	double   totalLength    = shaftLength + (2 * capRadius); //the total length is the length of the shaft, plus both caps on the end
	int      output         = 0;                             //a toggle we use to show output

	double   best           = 0;                             //the best estimate of PI so far, could be a random one off chance, but meh
	double   bestDifference = 1000;                          //the difference between the best PI and real PI, start high so that our first hit should be lower
	uint64_t bestToss       = 0;                             //the iteration the best mostly-PI happened on

	//kick off the random number generator
	srand(time(NULL));

	while (1)
	{
		//pick a random position
		double x = (rand() / (double)RAND_MAX) * totalLength;
		double y = (rand() / (double)RAND_MAX) * totalLength;

		//pick a random angle, where angle = (random percent * PI), seeing as cos and sin use radians.
		double angle = (rand() / (double)RAND_MAX) * M_PI;

		//we center our hotdog around 0 initially, meaning that the tip of one end rotated at our random angle will be at cos(angle) and sin(angle)
		//we only use halfShaft as the length, we will cater for the caps later
		double xOffset = (cos(angle) * halfShaft);
		double yOffset = (sin(angle) * halfShaft);

		//seeing as we only calculated one tip, we need to find the opposite one. as we were rotating around zero, we can simply invert the points in space by multiplying them by -1.
		//also in this step, we move them to our random position
		double x1 = x - xOffset;
		double y1 = y - yOffset;
		double x2 = x + xOffset;
		double y2 = y + yOffset;

		//now we have the positions of the two ends of the _shaft_, from these points, we can simply add the radius of the caps either way and see if they cross a line
		if ( (x1 + capRadius >= totalLength) || (x2 + capRadius >= totalLength) || (x1 - capRadius <= 0) || (x2 - capRadius <= 0) )
			crosses++;

		//now work our sort-of PI out using the magic formula
		double kindaPi    = tosses * (2 / (double)crosses);
		double difference = M_PI - kindaPi;
		//if this is our best PI yet, store it for safe keeping
		if (fabs(difference) < fabs(bestDifference))
		{
			best           = kindaPi;
			bestDifference = difference;
			bestToss       = tosses - 1;
		}

		tosses++;

		output++;
		if (output == 10000000)
		{
			printf("tosses\t\t= %lld\n", tosses);
			printf("crosses\t\t= %lld\n", crosses);
			printf("~pi\t\t= %.15f\n", kindaPi);
			printf("pi\t\t= %.15f\n", M_PI);
			printf("difference\t= %f\n", difference);
			printf("best so far\t= %.15f (difference: %.15f @ %lld)\n", best, fabs(bestDifference), bestToss);
			printf("\n");
			output = 0;
		}
	}

	return 0;
}


[ view entry ] ( 311 views ) permalink print article

You tell someone something and they start laughing.

What a great feeling. Either your story is amusing, or something you said made them laugh… you’re funny.
You’ve managed to find something that touches this person, you’re in, you’re awesome, they will come to you again because of who you are.

Then you feel your face collapse as if you were having a stroke as they try to break their laughter so they can tell you how it reminded them of this one time, this other person, really funny…

You’re not funny, you’re a catalyst or proxy of funny.
You must be so dull that while you were telling something you thought was hilarious, they zoned out at the beginning, hearing only enough to remind them of someone else who is funny.

That crushing feeling, “Yay, I did good! Wait… no… no no no! ME!”, as you politely listen to their story, while trying to decide which of your knees will have the pleasure of finding out if their face has a seam down the middle from the manufacturing process.

But, it’s not always about you.
Following your belief in fairness, it should rarely be about you, everyone deserves their equal time-slice.

Conversations work through exchange of stories, and only some people will find me funny, I get it, that’s how the world works. But being so willingly outcastish is tough sometimes, you’re finally in a moment where you’re out of your element, you can shine, this is your moment… except, it’s not.

Too easily wound up?


Memo to self: listen to people again, fully, focused. No thinking of “funny” retorts or “me” stories.

[ view entry ] ( 270 views ) permalink print article

I get the bus (The DiseaseMobile!) to and from work every weekday, and have done so for the past 8 years.
As you can imagine (… is that assuming too much? Was that too condescending sweety?) I have many stories I could tell about my journeys, but today I’ll focus on just two aspects: shock at the obvious, and blame.

From a young age, I was taught a song that went something like “the wheels on the bus go round and round”… this was in South Africa, where you’d only catch a bus if you were testing out suits of armour, but I’ve heard people singing it here in the UK too.
It seems to be a simple concept, and you’d guess that it implies that the bus is capable of motion, yet -despite all this conditioning from youth- people are absolutely gobsmacked when the bus moves.

Whenever people are getting ready to depart (“get off”, uh huh huh) the bus, they push the button and slowly make their way to the front of the bus, clinging on to the railings as they go, because the bus is not a stable platform.

So why, WHY OH WHY do they let go when the bus comes to a temporary stop, at a traffic light or something?
Just because the bus isn’t moving right now, doesn’t mean it’s not going to. In fact, you’re pretty much relying on it moving again, annoyed if it didn’t.

Sure, it might be your first time on a bus, but you’ve just been riding on it, it was bloody shaking all over the place…
And it’s NOT the first time on the bus for most of you, I should know, I stalk just about every single one of you.
And and… the elderly! You barely made it onto the bus in the first place, despite it dipping so low down to the curb that gangsta’s came past and went “yeeaah boyee”… why stand at the front and let go?

All of this builds up to the moment that just makes my rage develop an ulcer… the shock.
Oh! my! sentient being! IT MOVED! THE DEVICE MADE FOR MOVING ME FROM ONE PLACE TO ANOTHER MOVED!
Quick! Grab onto one of the many rails provided there in the first place to remind you to hold the hell on!
IT’S THE END OF THE WORLD!

You’re so frail already, or you’re so laden with packages filled with expensive goods, or your child is already missing a tooth… why?

But yes, shock. A face of absolute horror, the day you almost died.
Just like yesterday.

But is it your fault?
Is it helling heck?

The bus driver doesn’t know how to drive, he pulls off too quickly (except for those times that you’re in a rush, and he’s just being so damn slow).
The buses are so rubbish, they should cater for this kind of thing (I’m definitely seeing padded walls of some kind).

Roads. Designed to cater for moving vehicles. Vehicles capable of causing injury whether you’re in them, or in front of them.
Yes, the world does revolve around you, but even your world is filled with people less intelligent and smart and pretty as you, so they make mistakes.
Mistakes like driving a vehicle. On a road. When they’re allowed to.
Sometimes even having the nerve to hoot at you as you’ve just started walking into the road without looking again.

Again, the look of shock and disgust… A BUS? ON A ROAD? WHAT ARE THE CHANCES?

It doesn’t matter if it’s just a tiny side-road… that still implies that a vehicle needed to go through there, so a path was made… for the vehicle.

Again, the blame lies with the big bad bus and the driver. Hands are thrown up in disgust, words are thrown like the tar-coated balls of ignorance and self-defense they are.

Sure, I get it. You made a mistake, you’re feeling kinda dumb about it… but that’s because you were kinda dumb about it, don’t make that someone else’s problem.
Just be a little bit more aware… think.
For the love of your pretty little god, think.

That’s that, I’ll go back to being perfect in every way and leave you alone now.

[ view entry ] ( 252 views ) permalink print article

So, some progress on Tweenimator:



Astute readers may notice that images are now working, meaning I could add the world's ugliest test-UI too.

Also shown is how complex stick figures can be built from scratch.

Not show in action are the "move stick figure" and "rotate stick figure" options.
The "move" action works just peachy.
The "rotate" action, well...

See, in TISFAT, if you wanted to rotate a stick figure, you had to manually rotate the points. I can only imagine how difficult that must have been, because I never had the patience to do that kind of thing (sicko's!).
I _would_ have added the rotation option, but I had no idea how to handle mouse clicks on a rotated entity.
Now I do.

So, rotating an entire stick figure between frames means you can still edit the poses just by clicking on the stick figure like usual.

However, as this is prototype stage, I'm cutting myself some slack, in that the order of the rotations, or the center of which, must be wrong... when I rotate the stick figure, it goes way off screen.

That aside, progress is pretty good.

There is also an option to keep one "stick"/"limb" at the same angle to the one it is connected to, quite handy.
Except that I'm a mathematical genius * -1, and can't seem to get the angle right. I think I'm not transferring something during tweening...

Anyway, it's still fun, and that's what counts.
Especially when the world around me is covered in running combusting screaming monkeys.

[ view entry ] ( 196 views ) permalink print article

First there was the fine motor skills of an elephant.
Then there was TISFAT, which worked for a while, mostly, almost.
Then there was an unreleased tisfatTOO, which did nothing but frustrate me.

But now that tablets are common-place, and there are touch-screens actually capable of being useful (eat dust, resistivity!), I decided it would be fun just to see what animating a stick figure on them would be like.
So I whipped up a quick prototype to test it... and, well, damn. I've got the disease again.



It may not look like much, but the original TISFAT started with something way more basic/hideous.
AND it runs on iPad, TouchPad, and PlayBook already, huzzah!

To the FutureMobile!

[ view entry ] ( 148 views ) permalink print article

<<First <Newer | Older> Last>>