Archive for October, 2007

HTML Canvases and Lindenmayer Systems

Tuesday, October 30th, 2007

I recently noticed that there is a canvas feature that has been implemented in most modern browsers (unsurprisingly not IE7). The canvas allows you to draw things using javascript which is a really nice feature. It opens up several possibilities for interactive applications in a way that runs reasonably quickly and doesn’t involve many pictures. I came across a website that had used the canvas for what is called a lindenmayer system. I have just take the idea from this website and I coded a version myself. If you look at the code we have implemented it fairly differently although the systems are obviously pretty similar.

It was quite fun to make, I had done a project that parsed a small expression in VB a couple of times so I knew how to implements that and the rest was just using the functions of the canvas system to rotate and draw lines. I have put my implementation below, you can give it a formula, tell it how many iterations to do and there is also a scaling option. The script has a go at scaling but it isn’t very good, all it does is scale it inversely proportional to the number of iterations so 2 iterations is half size, 4 iterations is a quarter etc. This will not work in Internet Explorer.

Lindenmayer system

Please post any interesting formulas that you find. The script has no error checking so I would avoid putting in stupidly big iterations since it will never complete and might lock up your browser.

Focus Fusion Technology

Sunday, October 28th, 2007

I recently noticed this interesting form of fusion technology. I became interested in fusion a few years ago and have mainly heard about the tokamak approach which is still progressing slowly.

Focus fusions uses pulses generated be a strong electric current to compress a small amount of hydrogen and boron in a very small area at a very high temperature which then starts off the fusion process. Since I only found out about it today I can’t really explain it at all but there are some good resources on the web about it.

They have a main website at http://focusfusion.org/

The is also a video from the Google Tech Talks here.

Cross Browser Scripting

Saturday, October 20th, 2007

Recently I have written an ajax tutorial. It was interesting and fairly easy to make since I was mainly using some normal ajax which I had lying around. The main point of the tutorial was to show that it would make a practical website.

The main code for the tutorial was written in a fairly short period of time, then I tried testing the script in Internet Explorer, which I probably should have done earlier. Suffice to say, the script did not function properly in Internet Explorer.

The strange thing about this bug however was that, although it did the same every time the page was loaded, what it did didn’t really make sense. It would run the first ajax request and then would not run any more requests. So my ajax code was correct because it worked but it only ran once. There was no errors according to IE’s debugging stuff. I still do not know why this error happens however I managed to find a solution on the internet. It involved switching round two lines of code.

http.onreadystatechange = handleResponse;
http.open('get', webpage);

Had to be changed to:

http.open('get', webpage);
http.onreadystatechange = handleResponse;

But this should not have been needed. Why should opening a connection change what function was attached to the onreadystatechange event? It doesn’t matter in other browsers, nor the first time the script is run.

The annoying thing was that I spent about 30 minutes trying to fix this, which was a disproportionate time to writing the script. First I thought it was due to the way that I called the function so I spent a while messing around with different ways of doing this, none of which fixed it. I know debugging code takes a while but I don’t see why it should take so long to make it work in another browser which should be implementing javascript in the same way.

There is also a problem when using css and html, and most often your code works properly in everything other than Internet Explorer. Most web developers will tell you this if they have tried developing for multiple browsers with slightly complex things. This is the main reason why I am so pleased with the growing popularity of non IE browsers. Hopefully this will encourage the internet explorer developers to increase compatibility with the W3C’s standards because it is greatly irritating for a web developer.

Trebuchet video

Sunday, October 14th, 2007

I have taken a video of the trebuchet that I talked about in this post. I also have a few more pictures.

The path of the apple

This is the path that the apple took. I have merged together several frames of the video and highlighted the apple in each one. The path looks a little odd because of a combination of a strange camera angle and the apple bouncing off the wall.

The remains of the apple

Here is what is left of the apple that was big enough for me to pick up. Some other apples were completely destroyed.

Close up of a joint

Another close up of a joint

This two pictures show the joints in greater detail. Notice the reinforcing metal rings.

Spark Pen

Sunday, October 14th, 2007

Recently our chemistry teacher said that if we wanted to bring in a lighter we could rather than having to wait for the matches. Never wanting to just follow the crowd I remembered a little project I had made a while back.

It was a little thing made with a film canister which you sprayed a little aerosol stuff into and then it had a couple of wires stuck into the canister which I then sparked by attaching them to part of an electronic cigarette lighter.

I took out the part from the lighter and stuck it into a pen and taped it up securely. It makes a nice spark across the gap and a benefit it has over a conventional lighter is that you can give people a small electric shock which is fun. here is a picture and a video of the thing.

The video isn’t that great. I had to do it in the dark so the spark shows up clearly and it is hard to hold the pen still because you are pushing down to get it to spark. Also the camera missed a few sparks because the frame rate was too slow.

My Trebuchet

Sunday, October 14th, 2007

I little while back I thought it would be pretty cool to build a trebuchet so I built one over a few days. It was actually pretty easy to make. It is basically constructed from two A frames attached together at their bases and then a long arm is attached to a pivot at the top of the A frames. The weight goes at one end of the arm and the sling goes at the other end. The weight falls and so the other end goes up and flings the projectile. This makes it pretty cheap to make which is an important consideration with my projects. I think that the total materials cost came to about £8 which was spent on buying a metal tube, a length of bolt and some nuts. The tube and bolt came in 2m and 1m lengths respectively so I still have quite a lot left over. I had the wood lying around as well as the weight so they didn’t cost anything.

Here is a picture of the trebuchet. It is not great because it was a little dark so it had to be taken with the flash. Also I had to hold the camera which means that it is not in the position you would fire from. The arm that is vertical is pulled right down to the ground so that the weight at the bottom is pulled up. It is about 1.8m high to the tip of the arm.

The range seems to be about 35-40m but it is hard to test since our garden isn’t 35m long so it has to be fired across the road so I don’t want to do it very much. I have fun lobbing stuff at the wall of our house though. One slightly rotten apple was completely mulched and ended up all over our drive.

Here are some pictures of the different parts of the trebuchet:

This is the frame. You can see how simple it is. The axle for the arm goes through the two holes in the cross pieces and I use nuts to keep it there.

This is the arm. You can see the end of the sling on the right hand side. I added a joint on the weight end. This makes the trebuchet more efficient because the weight drops in a straighter line. This also reduces the rocking of the trebuchet after firing. The axle is well reinforced because this is where there is a lot of strain. I have screwed a piece of wood onto either side to help stop sideways twisting. There is a piece of metal tubing in the hole. This stops the strain as the axle twists cutting into the wood and damaging the hole. This effect could quite easily wreck the axle since as it got worse the damage would increase due to more wobble. All of the moving joints have this done to them. This is the reason for the metal tubing. It also reduces friction since metal is sliding against metal.

This the weight. It is 28lbs (12.7 kg for us who like metric) which is fairly heavy. I originally used a couple of bricks but that wasn’t very impressive and luckily I found this at my gran’s house and there wasn’t any other use for it. I take it off the catapult when it is not in use because it is pretty heavy. It is attached by bolting it on, the bolt goes through under the bar on it and is annoyingly fiddly to fit.

This is the sling. Sorry the photo is a bit out of focus I will try and get a better one sometime. Basically the projectile (rotten apple) goes into the sling part and then the other end of the string is hooked onto the nail on the end of the arm. The angle of the nail is very important since it sets when the projectile is released. As the sling whips round it reaches a point when the loop in the end of the string slips off the nail and then the projectile is released as the sling straightens out. The sling method for a catapult is better in my opinion to something like an onager where there a sudden stop which makes the projectile fly off and makes the whole machine kick back like an onager (like a donkey) and hence the name.

The part that I haven’t photographed is the plank of wood that the projectile slides along at launch. The sling lies flat along this plank and then is pulled along it as the arm moves round, until it is lifted up. All the plank does is provide a smooth low friction surface.

I would recommend building a trebuchet yourself since they are great fun to play with and are very easy to make. All I used to make it was a hacksaw, screwdriver, pencil, ruler, needle file (for when I sawed through the bolt, to smooth the cut) and an electric drill. Most people would have these other than perhaps the needle file, and you could probably manage with the hacksaw since you just need to make sure you can fit the nut onto the bolt by removing the burr from the hacksaw cut.

I will try and get a video of it working some time and I will post it as soon as I do.

A sense of proportion

Wednesday, October 10th, 2007

Recently I heard a statistic about how many people there are in the UK due to people trafficking. The estimate was about 4000 which in a country of 60 million didn’t seem very significant. The fact that there are so many people who are effectively slaves in the UK is pretty bad but I don’t really want to post about that because for one thing I don’t really know enough about it.

I then thought about the size of the town which I live in, this is about 30 000. since there are 60 million people in the UK that is 1/2000 of the population. This means that if we had our fair share of these people from people trafficking there would be 2 in my town. Although my town has 30 000 people it doesn’t seem all that big. But it does contain a fairly large proportion of the country. But of course there are bigger towns and lots of small towns so when I looked it up it was about the 440th largest town in the country.

Looking at it this way makes the country seem quite a lot smaller. This is really a bit of deception though because 60 million people is a lot of people, the reason it seems smaller is because I have given my brain 2 smaller numbers which multiply to give the number and so individually they are not too big. 100 * 100 * 100 * 60 also gives 1 million but 100 people isn’t very much, I know well over 100 people.

I guess our brains just can’t really understand big numbers like this. They are just number to be represented in different ways. Some ways make our brain perceive the numbers as being bigger than they are while others make them seem smaller.

Reusing code

Wednesday, October 10th, 2007

A lot of modern programming focusses on making code reusable and modulated. This is clearly a good idea since there is no point writing code more than once since it is just a waste of time and gets pretty boring.

The tools which programmers have been able to use have become more and more sophisticated as languages have developed. Earlier languages had functions which you could use to put pieces of code into packets to be used elsewhere. Then object orientated programming was developed so you could easily package functions and variables together so that they could be reused. Files can be included so that you can just call in functions and objects from other files rather than having to copy them into your code.

Some programs that I have taken a look at recently are almost completely made up of functions and objects. This can be good but it is not good because they will be able to reuse the code, in reality most of the code is pretty specialised and couldn’t simply be put straight into another program. The main benefit that I see is keeping the code well organised. It is the idea that if you change one function that has a problem with it then the other functions don’t need to be changed, they should still work properly. This makes it a lot easier to debug code or make alterations clearly. And also as long as the structure is fairly clear then it makes it a lot easier for another coder to make some modification because they don’t have to worry about the whole structure, they just need to learn how the small section that they are trying to modify works.

One of the pitfalls that many programmers can fall into is creating code so that they can reuse it all in other projects. Some bits should be written so they can be reused but only some bits such as a database class. Writing too much of your program to be reusable will be very time consuming and will lead to a lot of unnecessary code being written. This will have a bad effect on performance since they is a lot of unnecessary code that has to be run. Also if you do want to reuse some code just because you wrote it specifically for one thing doesn’t mean you can’t reuse it. A small amount of modification will make it usable for another project.

Also a final thing which I have noticed with my own code is that if I look back at my old code it looks dreadful in many cases. I have only been programming for a few years so if I look back then at the time I wrote it I hadn’t been programming for very long so I didn’t know how to do things very well. So I wouldn’t even consider reusing the code I wrote then because I would rewrite it better now.

That is my opinion on these things anyway. It isn’t a simple right or wrong thing really as it does depend on what you like personally. I don’t really like spending too much time saving time later because I don’t seem to save time later in many cases.

How useful is website design?

Wednesday, October 10th, 2007

I’m not a designer at all really, I’m more of a coder. I was thinking about redesigning this blog because I have the default but I would like to make a custom one. I have thought about it and I really don’t seem to be able to come up with any ideas on what it should look like. I feel that if somebody told me what they would like their website to look like then I could have a fair go at making it for them, since I am ok at drawing stuff although not amazing. I just can’t seem to do anything when faced with a completely blank canvas so to speak.

I don’t really think that design is all that important anyway so I am not too bothered about not being able to reskin this. My thoughts are that the design is meant to be nice to look at but it is an extra thing, not the main attraction. people go to my site to look at the content. If the content is good then they will like my site and come back to it. So the design can’t get in the way of the content at all.

Even so when I visit websites I do realise that I am influenced by the design. I do value the content far more than the design but it does influence me as it must do with everybody else.

This reminds me of basically the only main feature that IE7 has that firefox does not which is the tab preview thing where you see the contents of all of the tabs in little pictures so you can see them at a glance. Although I said you can see the contents I didn’t really mean that. You cannot see the content, it is far too small to read, you get a preview of the design.

In the example demo video that I saw about IE7 the guy demonstrating did a search, then opened a load of the links as background tabs. He then proceeded to go to the tab preview thing and then select the ones he wanted. In my opinion this is just plain stupid. The little extract of text that is given to you by the search engine is clearly far more informative than the design of the web page. How pretty a site is doesn’t mean it has good content because the content is completely separate. Loads of sites get other people to make their design for them and then they add the content themselves, so the content could still be awful.

You can probably see from the quantumstate website that I have a view like this since I am sure that the design isn’t really very amazing, I am far more interested in writing the content for it than making it look really pretty. I did do the design myself. I am fairly pleased with it but I don’t think it is all that good.

Maybe I will manage to get a reskin done sometime for this blog but as I have said it isn’t a high priority.

My new blog

Wednesday, October 10th, 2007

I have decided to put up a blog so that I can put more informal things here.  My main site will continue with tutorials and source code but sometimes I feel like writing some other things which I don’t want to put onto my main site because I want to keep it just for the tutorials and source.

I had an old blog which I rediscovered recently over at blogspot and I have put a few posts onto it recently.  I will put these over onto this blog so there will be quite a few posts in a very short period of time.  I have opted for a wordpress blog because I can customise it properly since I have full source access.  Also I wanted to have the blog on the same site as the rest of the quantumstate website.

Hopefully you will like my blog.  I aim to make fairly high quality posts rather than large numbers of poor quality ones.  This will mean that I will probably update once a week, perhaps more often, it really depends on whether I can think of anything to write about.