Skip to: Navigation Content Search


Archive for August, 2008

Comments from beyond the DTD Tuesday, August 26th, 2008

According to the W3C validator, it’s ok to place comments above outside your doctype declaration. Like so:

<!-- page last built on October 24, 2007, 21:30 UTC v1.278484 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB">
<head ...

Sure it’s ok. It validates and all is well.

Or is it?

If you, like 90% of web lemmings, have a centred layout courtesy of

#mywrapper {
margin:0 auto;
}

[insert expletive] Internet Explorer 6 will not play ball. This is true for strict, transitional and loose DTDs. It will take your centred layout and crush it like a brick falling on a fresh tuna sandwich.

IE6 either ignores that specific CSS rule or pushes your container div to the left on purpose (I haven’t worked out exactly which). Everything else will look as normal.

Taking out these comments or moving them underneath the doctype declaration will fix it of course. I suppose it’s not surprising that the document syntax rules should really be the first element to appear in the document, but IE’s specific behaviour is still inexplicable.

* Update: Thanks to Scott G for his common sense. ie6 seems to go into quirks mode when comments are placed above the DTD. Taking out the comments and the DTD all together, or leaving in the comments and removing the DTD, cause the browser to behave in the same manner.

* Proposal: start a campaign of ridicule and intimidation targeting anyone still using ie6. Update 13th of November 2008: someone has beat us to it!

Let’s start things over Sunday, August 17th, 2008

Let's start things over

Hand drawn during stratospherically inane seminar, traced in Illustrator and touched up in Photoshop.

Trigonometry - hoorah! Friday, August 15th, 2008

Man I hated maths in high school. Not due to the endless formulae one had to commit to memory, nor thanks to the high-panted teachers whose droning nearly caused me several times to thrust the blackboard protractor into my heart; but because, apart from helping me to estimate how many beers my teenage income would allow me on a Friday night, maths never presented me with practical solutions for my everyday problems.

Because of this, I knew I was condemned to a life of esoteric artistic theory, beyond the influence of the harsh laws of the universe.

Now I realise I wasn’t being half has geeky as I should have been.

So, at present I’m working on an interface to present XML data of programme scheduling, which plots coordinates around a centre grouped by broadcasting network and positioned by the programme’s proximity to the current time. See Figure 1.

Figure 1

Each colour represents a different network’s programmes. In my version version you get the program information when you mouse over the circles.

The math is simple. We’re rotating around a centre point in degrees, defining a length from the centre (in my case based on the time from now) and, using trigonometry, calculating x and y values (the end point of the hypotenuse) to plot our points.

The basic setup will be a div - let’s give it an id of canvas.

<div id="canvas"></div>

And apply some CSS:

#canvas {
height:400px;
width:400px;
position:relative;
}

We’ll also need to define the CSS for our circles. Firstly the default style for the small dots:

.circle, .circle-red {
background:url (circle-blue.png) 0 0 no-repeat;
position:absolute;
cursor:pointer;
width:20px;
height:20px;
}

.circle-red {
background-image:url (circle-red.png);
}

And then our centre point:

#now.circle {
background:url (centre.png) 0 0 no-repeat;
width:40px;
height:40px;
}

The width and height is up to you. I’ve kept it as a square to make the calculations easier.

And the JavaScript. You will see that I’m using jquery.

First we need to store the centre point of our canvas. Unless you specify otherwise, JavaScript will think that your centre point is 0, 0. So it’s up to us to add the offset. :)

var CENTER_X = 200; // or $('#canvas').width()/2
var CENTER_Y = 200; // or $('#canvas').height()/2

This is where we get x y coords. We need to pass an angle in degrees (0 - 360) along which we want to plot our points and the distance (len) from the centre. In my version, I calculate the distance based on a ratio of the programme’s start time minus the current time.

function getCoords(degrees, len) {
// to use JavaScript's trig functions we need to convert degrees into radians
var radians = toRadians(degrees);

// calculate store our coords
// make sure to add the offset of our centre point so it actually appears in the centre rather than at 0, 0
var coords = {};
coords.x = CENTER_X + Math.floor(Math.cos(radians)*len);
coords.y = CENTER_Y + Math.floor(Math.sin(radians)*len);
return coords;
}


// degrees to radians
function toRadians(deg) {
return deg * Math.PI/180;
}

This is where we store all our created points for later reference.

var CIRCLES = {};

Now our circle factory. Arguments:

  • an id (for each point)
  • a class name (to control the look of our
  • the size of my point in pixels
  • the direction (angle) in which we want to travel from the centre
  • the distance from the centre we want to travel

You might find that you don’t need to pass through an id or want further parameters like mouseover content or whatever.

function Circle (id, classname, size, angle, len) {

// create and append the div that will be our point to our canvas
$('#canvas').append('<div id="' + id + '" class="' + classname + '></div>');

// get our x and y values
var coords = getCoords(angle, len);

// because we want them to line up nicely we change the registration point to the centre
var _left = coords.x - (size/2);
var _top = coords.y - (size/2);

// position it
$('#'+id).css({left:_left+"px", top:_top+"px"});

// store our default values
this.id = id;
this.size = size;
this.angle = angle;
this.len = len;
this.x = _left;
this.y = _top;
CIRCLES[id] = this;
}

So now we just need to create a circle on the page. Let’s start with the centre!

new Circle('now', 'circle', 40, 0, 0);

Now you’ll notice that I’ve been too lazy to check my arguments, provide fallbacks and defaults and have probably left a 100 things out, but you get the general idea.

If you find a biro, keep it Wednesday, August 6th, 2008

This one was done, once again, in a boring meeting but lovingly crafted with the use of a spiffy black biro I found on the floor beforehand.

Don’t waste biros!

Papervision 3D Sunday, August 3rd, 2008

If you haven’t heard, Papervision is a 3D class library for Flash. For non-maths heads like me, it’s fairly complex to get your head around. To make it even worse, the documentation is sparse, but there are some good tutorials out there. Check out gotoandlearn.

I’ve followed a guide created by Mark Walters to create my own Earth and Moon scene using Papervision for AS3. It’s basic I guess, but I’m only learning.

I’ve found that sometimes in Firefox at home, I needed to refresh the page to make the Earth appear. Not sure why.  Also, for all the astronomers, the dimensions and distances are probably way off. I was lucky to get it to work, so back off! :)