Removed baked script file.
authorEugen Sawin <sawine@me73.com>
Sat, 07 Jan 2012 01:34:40 +0100
changeset 91d02866e68bdd
parent 90 49897f71f067
child 92 290ad5d7652b
Removed baked script file.
script.js
     1.1 --- a/script.js	Sat Jan 07 01:33:27 2012 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,838 +0,0 @@
     1.4 -var QUOTES_NUMBER = 39;
     1.5 -var SERVER = "http://" + window.location.hostname + ":" + window.location.port;
     1.6 -var simulation;
     1.7 -var gameoflife;
     1.8 -
     1.9 -$(document).ready(function() {   
    1.10 -    simulation = new Simulation(document.getElementById("sim"), 
    1.11 -                                670, 50, 6, green, background);  
    1.12 -    var image = new Image();
    1.13 -    image.onload = init_logo;
    1.14 -    image.src = "images/logobase.png";
    1.15 -    $("#logo").click(handle_click);   
    1.16 -    $("#logo").hover(function(event) {
    1.17 -        $(this).css("cursor", "pointer");        
    1.18 -    }, function() {
    1.19 -        $(this).css("cursor", "auto");
    1.20 -    });
    1.21 -    $("#logo").mousemove(function(event) { handle_hover(event); });
    1.22 -    $("#logo").mouseout(function(event) { handle_mouse_out(event); });
    1.23 -    $("#sim").mousemove(function(event) { simulation.mouse_moved(mouse_pos(event, "#sim")); });
    1.24 -    var onEachFrame;
    1.25 -    if (window.webkitRequestAnimationFrame) {
    1.26 -        onEachFrame = function(cb) {
    1.27 -            var _cb = function() { cb(); webkitRequestAnimationFrame(_cb); }
    1.28 -            _cb();
    1.29 -        };
    1.30 -    } else if (window.mozRequestAnimationFrame) {
    1.31 -        onEachFrame = function(cb) {
    1.32 -            var _cb = function() { cb(); mozRequestAnimationFrame(_cb); }
    1.33 -            _cb();
    1.34 -        };
    1.35 -    } else {
    1.36 -        onEachFrame = function(cb) {
    1.37 -            setInterval(cb, 1000 / 30);
    1.38 -        }
    1.39 -    }    
    1.40 -    window.onEachFrame = onEachFrame;   
    1.41 -    window.onEachFrame(update);  
    1.42 -    var pos = document.location.href.lastIndexOf("/") + 1; 
    1.43 -    var page = document.location.href.substr(pos);
    1.44 -    if (page == "mandelbrot.html") {
    1.45 -        draw(0, 0, 0, 0, 0);
    1.46 -    } else if (page == "" || page == "index.html") {
    1.47 -        init_gameoflife("ME73");
    1.48 -    } else if (page == "gameoflife.html") {
    1.49 -        init_gameoflife("");
    1.50 -    }
    1.51 -});
    1.52 -
    1.53 -$(document).keypress(function(event) {
    1.54 -    if (event.which == 13) {      
    1.55 -	event.preventDefault();
    1.56 -        update_logo();	    
    1.57 -    }
    1.58 -});
    1.59 -
    1.60 -var menu_width = 670;
    1.61 -var menu_height = 100;
    1.62 -var menu_splits = new Array(180, 350, 505);
    1.63 -
    1.64 -var click_events = new Array();
    1.65 -click_events["logo"] = new Array();
    1.66 -click_events["logo"][0] = new Object();
    1.67 -click_events["logo"][0]["min_x"] = 0;
    1.68 -click_events["logo"][0]["max_x"] = menu_splits[0];
    1.69 -click_events["logo"][0]["min_y"] = 0;
    1.70 -click_events["logo"][0]["max_y"] = menu_height;
    1.71 -click_events["logo"][0]["func"] = switch_page;
    1.72 -click_events["logo"][0]["args"] = new Array("personalwork.html");
    1.73 -click_events["logo"][1] = new Object();
    1.74 -click_events["logo"][1]["min_x"] = menu_splits[0] + 1;
    1.75 -click_events["logo"][1]["max_x"] = menu_splits[1];
    1.76 -click_events["logo"][1]["min_y"] = 0;
    1.77 -click_events["logo"][1]["max_y"] = menu_height;
    1.78 -click_events["logo"][1]["func"] = switch_page;
    1.79 -click_events["logo"][1]["args"] = new Array("howiwork.html");
    1.80 -click_events["logo"][2] = new Object();
    1.81 -click_events["logo"][2]["min_x"] = menu_splits[1] + 1;
    1.82 -click_events["logo"][2]["max_x"] = menu_splits[2];
    1.83 -click_events["logo"][2]["min_y"] = 0;
    1.84 -click_events["logo"][2]["max_y"] = menu_height;
    1.85 -click_events["logo"][2]["func"] = switch_page;
    1.86 -click_events["logo"][2]["args"] = new Array("books.html");
    1.87 -click_events["logo"][3] = new Object();
    1.88 -click_events["logo"][3]["min_x"] = menu_splits[2] + 1;
    1.89 -click_events["logo"][3]["max_x"] = menu_width - 1;
    1.90 -click_events["logo"][3]["min_y"] = 0;
    1.91 -click_events["logo"][3]["max_y"] = menu_height;
    1.92 -click_events["logo"][3]["func"] = switch_page;
    1.93 -click_events["logo"][3]["args"] = new Array("links.html", "linksend.html");
    1.94 -
    1.95 -function mouse_pos(event, id) { 
    1.96 -    var offset = $(id).offset();   
    1.97 -    return new Array(event.pageX - offset.left, 
    1.98 -                     event.pageY - offset.top);
    1.99 -}
   1.100 -
   1.101 -function handle_click(event) {
   1.102 -    var xy = mouse_pos(event, "#logo");
   1.103 -    var x = xy[0];
   1.104 -    var y = xy[1];
   1.105 -    for (var i in click_events[event.target.id]) {
   1.106 -        var ces = click_events[event.target.id][i];
   1.107 -        if (ces && x >= ces["min_x"] && x <= ces["max_x"]
   1.108 -            && y >= ces["min_y"] && y <= ces["max_y"]) {    
   1.109 -            ces["func"](event.target.id, ces);
   1.110 -            last_colours[0] = black;
   1.111 -            break;
   1.112 -        }
   1.113 -    }
   1.114 -}
   1.115 -
   1.116 -function handle_hover(event) {
   1.117 -    var xy = mouse_pos(event, "#logo");
   1.118 -    var x = xy[0];
   1.119 -    var y = xy[1];
   1.120 -    for (var i in click_events[event.target.id]) {
   1.121 -        var ces = click_events[event.target.id][i];
   1.122 -        if (ces && x >= ces["min_x"] && x <= ces["max_x"]
   1.123 -            && y >= ces["min_y"] && y <= ces["max_y"]) {    
   1.124 -            highlight_menu(event.target.id, ces);
   1.125 -            break;
   1.126 -        }
   1.127 -    }
   1.128 -}
   1.129 -
   1.130 -function handle_mouse_out(event) {
   1.131 -    highlight_menu(event.target.id, null);
   1.132 -}
   1.133 -
   1.134 -function switch_page(id, params) {
   1.135 -    var page = params["args"][0];
   1.136 -    $("body").load(page);
   1.137 -    document.location.href = page;    
   1.138 -}
   1.139 -var last_highlight;
   1.140 -var last_colours = new Array();
   1.141 -function highlight_menu(id, p) {
   1.142 -    if (last_highlight == p) {
   1.143 -        return;
   1.144 -    }
   1.145 -    var canvas = document.getElementById("logo");
   1.146 -    var context = canvas.getContext("2d");    
   1.147 -    var image = context.getImageData(0, 0, menu_width, menu_height);
   1.148 -    if (last_highlight && last_colours && last_colours[0] && last_colours[1]) {        
   1.149 -        page = last_highlight["args"][0]; 
   1.150 -        min_x = last_highlight["min_x"];
   1.151 -        max_x = last_highlight["max_x"];
   1.152 -        min_y = last_highlight["min_y"];
   1.153 -        max_y = last_highlight["max_y"];
   1.154 -        colour_area(image, min_x + 10, max_x - 10, 0, 60, 
   1.155 -                    last_colours[0]);
   1.156 -        colour_area(image, min_x + 10, max_x - 10, 60, max_y - 10, 
   1.157 -                    last_colours[1]);
   1.158 -    }
   1.159 -    if (p) {    
   1.160 -        var page = p["args"][0]; 
   1.161 -        var min_x = p["min_x"];
   1.162 -        var max_x = p["max_x"];
   1.163 -        var min_y = p["min_y"];
   1.164 -        var max_y = p["max_y"];       
   1.165 -        last_colours[0] = colour_area(image, min_x + 10, max_x - 10, 0, 60, 
   1.166 -                                      orange);
   1.167 -        last_colours[1] = colour_area(image, min_x + 10, max_x - 10, 60, max_y - 10, 
   1.168 -                                      white);        
   1.169 -    }
   1.170 -    
   1.171 -    context.putImageData(image, 0, 0);
   1.172 -    last_highlight = p;
   1.173 -}
   1.174 -
   1.175 -function colour_area(image, min_x, max_x, min_y, max_y, colour) {   
   1.176 -    var pixels = image.data;
   1.177 -    var old_colour;
   1.178 -    for (var y = min_y; y <= max_y; y += 1) {
   1.179 -        for (var x = min_x; x <= max_x; x += 1) {
   1.180 -            var pix_colour = getPixel(image, x, y);
   1.181 -            if (pix_colour.a > 0) {
   1.182 -                colour.a = pix_colour.a;               
   1.183 -                setPixel(image, x, y, colour); 
   1.184 -                if (pix_colour.a == 255) {
   1.185 -                    old_colour = new Colour(pix_colour.r,
   1.186 -                                            pix_colour.g,
   1.187 -                                            pix_colour.b,
   1.188 -                                            pix_colour.a);
   1.189 -                }
   1.190 -            }
   1.191 -        }
   1.192 -    }
   1.193 -    return old_colour;
   1.194 -}
   1.195 -
   1.196 -function init_logo(event) {
   1.197 -    var canvas = document.getElementById("logo");
   1.198 -    var context = canvas.getContext("2d");    
   1.199 -    canvas.width = menu_width;
   1.200 -    canvas.height = menu_height;
   1.201 -    context.drawImage(event.target, 0, 0);
   1.202 -    var image = context.getImageData(0, 0, menu_width, menu_height);    
   1.203 -    for (var i in click_events["logo"]) {
   1.204 -        var p = click_events["logo"][i]; 
   1.205 -        var min_x = p["min_x"];
   1.206 -        var max_x = p["max_x"];
   1.207 -        var min_y = p["min_y"];
   1.208 -        var max_y = p["max_y"];
   1.209 -        var pos = document.location.href.lastIndexOf("/") + 1; 
   1.210 -        var page = document.location.href.substr(pos);        
   1.211 -        for (var j in p["args"]) {
   1.212 -            if (page == p["args"][j]) {         
   1.213 -                colour_area(image, min_x, max_x, 0, 60, black);
   1.214 -                colour_area(image, min_x, max_x, 60, max_y, white);
   1.215 -                break;
   1.216 -            }
   1.217 -            else {
   1.218 -                colour_area(image, min_x, max_x, 0, 60, white);
   1.219 -                colour_area(image, min_x, max_x, 60, max_y,  orange);  
   1.220 -            }
   1.221 -        }       
   1.222 -    } 
   1.223 -    context.putImageData(image, 0, 0);      
   1.224 -    // context.fillStyle = green.str();
   1.225 -    // console.log((found["max_x"] - found["min_x"]) / 2 + found["min_x"] - 2);
   1.226 -    // context.fillRect((found["max_x"]-found["min_x"])/2+found["min_x"]-1, 95, 2, 5);  
   1.227 -    draw_menu_lines();   
   1.228 -}
   1.229 -
   1.230 -function draw_menu_lines() {
   1.231 -    var canvas = document.getElementById("logo");
   1.232 -    var context = canvas.getContext("2d");  
   1.233 -    var image = context.getImageData(0, 0, menu_width, menu_height);
   1.234 -    var pixels = image.data;
   1.235 -    context.lineCap = "round";
   1.236 -    context.lineWidth = 1;
   1.237 -    var colour1a = new Colour(0, 0, 0, 0.1);
   1.238 -    context.beginPath();   
   1.239 -    context.moveTo(0, menu_height - 1);
   1.240 -    context.lineTo(menu_width - 1, menu_height - 1);   
   1.241 -    context.closePath();  
   1.242 -    context.strokeStyle = colour1a.str();
   1.243 -    context.stroke(); 
   1.244 -    var colour1e = new Colour(0, 0, 0, 0.05);  
   1.245 -    context.beginPath();   
   1.246 -    context.moveTo(70, menu_height - 1);
   1.247 -    context.lineTo(menu_width - 71, menu_height - 1);   
   1.248 -    context.closePath();  
   1.249 -    context.strokeStyle = colour1e.str();
   1.250 -    context.stroke();  
   1.251 -    var colour1b = new Colour(0, 0, 0, 0.05);  
   1.252 -    context.beginPath();   
   1.253 -    context.moveTo(50, menu_height - 1);
   1.254 -    context.lineTo(menu_width - 51, menu_height - 1);   
   1.255 -    context.closePath();  
   1.256 -    context.strokeStyle = colour1b.str();
   1.257 -    context.stroke();
   1.258 -    var colour1c = new Colour(0, 0, 0, 0.05);  
   1.259 -    context.beginPath();   
   1.260 -    context.moveTo(25, menu_height - 1);
   1.261 -    context.lineTo(menu_width - 26, menu_height - 1);   
   1.262 -    context.closePath();  
   1.263 -    context.strokeStyle = colour1c.str();
   1.264 -    context.stroke();
   1.265 -    var colour1d = new Colour(0, 0, 0, 0.05);  
   1.266 -    context.beginPath();   
   1.267 -    context.moveTo(10, menu_height - 1);
   1.268 -    context.lineTo(menu_width - 11, menu_height - 1);   
   1.269 -    context.closePath();  
   1.270 -    context.strokeStyle = colour1d.str();
   1.271 -    context.stroke();  
   1.272 -    
   1.273 -    var colour2 = new Colour(0, 0, 0, 0.2);
   1.274 -    context.beginPath();  
   1.275 -    context.moveTo(menu_splits[0], 0); 
   1.276 -    context.lineTo(menu_splits[0], menu_height - 1);
   1.277 -    context.moveTo(menu_splits[1], 0);
   1.278 -    context.lineTo(menu_splits[1], menu_height - 1);
   1.279 -    context.moveTo(menu_splits[2], 0);
   1.280 -    context.lineTo(menu_splits[2], menu_height - 1);
   1.281 -    context.closePath();
   1.282 -    context.strokeStyle = colour2.str();
   1.283 -    context.stroke();
   1.284 -
   1.285 -    context.clearRect(menu_splits[0] - 1, menu_height - 1, 2, 2);
   1.286 -    context.clearRect(menu_splits[1] - 1, menu_height - 1, 2, 2);
   1.287 -    context.clearRect(menu_splits[2] - 1, menu_height - 1, 2, 2);
   1.288 -
   1.289 -    context.clearRect(menu_splits[0] - 1, menu_height - 2, 1, 1);
   1.290 -    context.clearRect(menu_splits[1] - 1, menu_height - 2, 1, 1);
   1.291 -    context.clearRect(menu_splits[2] - 1, menu_height - 2, 1, 1);
   1.292 -}
   1.293 -
   1.294 -function clearMenuLines() {
   1.295 -    var canvas = document.getElementById("logo");
   1.296 -    var context = canvas.getContext("2d");  
   1.297 -    var image = context.getImageData(0, 0, menu_width, menu_height);
   1.298 -    var pixels = image.data;
   1.299 -    context.clearRect(0, menu_height - 2, menu_width - 1, 2);
   1.300 -    context.clearRect(menu_splits[0] - 1, 0, 2, menu_height - 1);
   1.301 -    context.clearRect(menu_splits[1] - 1, 0, 2, menu_height - 1);
   1.302 -    context.clearRect(menu_splits[2] - 1, 0, 2, menu_height - 1);
   1.303 -}
   1.304 -
   1.305 -function draw_sim_lines() {
   1.306 -    var w = 670;
   1.307 -    var h = 50;
   1.308 -    var canvas = document.getElementById("sim");
   1.309 -    var context = canvas.getContext("2d");  
   1.310 -    var image = context.getImageData(0, 0, w, h);
   1.311 -    var pixels = image.data;
   1.312 -    context.lineCap = "round";
   1.313 -    context.lineWidth = 1;
   1.314 -    var colour1a = new Colour(0, 0, 0, 0.1);
   1.315 -    context.beginPath();   
   1.316 -    context.moveTo(0, h - 1);
   1.317 -    context.lineTo(w - 1, h - 1);   
   1.318 -    context.closePath();  
   1.319 -    context.strokeStyle = colour1a.str();
   1.320 -    context.stroke(); 
   1.321 -    var colour1e = new Colour(0, 0, 0, 0.05);  
   1.322 -    context.beginPath();   
   1.323 -    context.moveTo(70, h - 1);
   1.324 -    context.lineTo(w - 71, h - 1);   
   1.325 -    context.closePath();  
   1.326 -    context.strokeStyle = colour1e.str();
   1.327 -    context.stroke();  
   1.328 -    var colour1b = new Colour(0, 0, 0, 0.05);  
   1.329 -    context.beginPath();   
   1.330 -    context.moveTo(50, h - 1);
   1.331 -    context.lineTo(w - 51, h - 1);   
   1.332 -    context.closePath();  
   1.333 -    context.strokeStyle = colour1b.str();
   1.334 -    context.stroke();
   1.335 -    var colour1c = new Colour(0, 0, 0, 0.05);  
   1.336 -    context.beginPath();   
   1.337 -    context.moveTo(25, h - 1);
   1.338 -    context.lineTo(w - 26, h - 1);   
   1.339 -    context.closePath();  
   1.340 -    context.strokeStyle = colour1c.str();
   1.341 -    context.stroke();
   1.342 -    var colour1d = new Colour(0, 0, 0, 0.05);  
   1.343 -    context.beginPath();   
   1.344 -    context.moveTo(10, h - 1);
   1.345 -    context.lineTo(w - 11, h - 1);   
   1.346 -    context.closePath();  
   1.347 -    context.strokeStyle = colour1d.str();
   1.348 -    context.stroke();   
   1.349 -}
   1.350 -
   1.351 -function update_logo() {
   1.352 -    var canvas = document.getElementById("logo");
   1.353 -    var context = canvas.getContext("2d");  
   1.354 -    var image = context.getImageData(0, 0, menu_width, menu_height);
   1.355 -    var pixels = image.data;
   1.356 -    var white = new Colour(255, 255, 255);
   1.357 -    for (var y = 0; y < menu_height; y += 1) {
   1.358 -        for (var x = 0; x < menu_width; x += 1) {
   1.359 -            var pix_colour = getPixel(image, x, y);
   1.360 -            if (pix_colour.a > 0) {
   1.361 -                setPixel(image, x, y, new Colour(90, 215, 21, pix_colour.a));
   1.362 -            }
   1.363 -        }
   1.364 -    }   
   1.365 -    context.putImageData(image, 0, 0);
   1.366 -}
   1.367 -
   1.368 -var char_map = new Array();
   1.369 -char_map["A"] = new Array(new Array(0, 4), new Array(1, 3),
   1.370 -                          new Array(2, 2), new Array(3, 1),
   1.371 -                          new Array(4, 0), new Array(5, 1),
   1.372 -                          new Array(6, 2), new Array(7, 3),
   1.373 -                          new Array(8, 4), new Array(2, 3),
   1.374 -                          new Array(3, 3), new Array(4, 3),
   1.375 -                          new Array(5, 3), new Array(6, 3));
   1.376 -char_map["M"] = new Array(new Array(0, 4), new Array(0, 3),
   1.377 -                          new Array(0, 2), new Array(0, 1),
   1.378 -                          new Array(0, 0), new Array(0, 5),
   1.379 -                          new Array(5, 4), new Array(5, 3),
   1.380 -                          new Array(5, 2), new Array(5, 1),
   1.381 -                          new Array(5, 0), new Array(5, 5),
   1.382 -                          new Array(1, 1), new Array(2, 2), 
   1.383 -                          new Array(4, 2), new Array(5, 1),
   1.384 -                          new Array(3, 3));
   1.385 -char_map["E"] = new Array(new Array(0, 4), new Array(0, 3),
   1.386 -                          new Array(0, 2), new Array(0, 1),
   1.387 -                          new Array(0, 0), new Array(0, 5),
   1.388 -                          new Array(1, 0), new Array(2, 0),
   1.389 -                          new Array(3, 0),
   1.390 -                          new Array(1, 3), new Array(2, 3),                       
   1.391 -                          new Array(1, 5), new Array(2, 5),
   1.392 -                          new Array(3, 5))
   1.393 -char_map["7"] = new Array(new Array(0, 0), new Array(1, 0),
   1.394 -                          new Array(2, 0),
   1.395 -                          new Array(0, 5), new Array(0, 4),
   1.396 -                          new Array(1, 3), new Array(2, 2));
   1.397 -char_map["3"] = new Array(new Array(2, 4), new Array(2, 3),
   1.398 -                          new Array(2, 2), new Array(2, 1),
   1.399 -                          new Array(0, 0), new Array(0, 5),
   1.400 -                          new Array(1, 0), new Array(2, 0),                         
   1.401 -                          new Array(1, 3), new Array(2, 3),                          
   1.402 -                          new Array(1, 5), new Array(2, 5))
   1.403 -
   1.404 -function init_gameoflife(text) {
   1.405 -    var canvas = document.getElementById("gameoflife");
   1.406 -    var cell_size = 16;
   1.407 -    if (canvas) {
   1.408 -        gameoflife = new Simulation(canvas, 670, 670, cell_size,
   1.409 -                                    green, black);
   1.410 -        $("#gameoflife").mousemove(function(event) { 
   1.411 -            gameoflife.mouse_moved(mouse_pos(event, "#gameoflife")); 
   1.412 -        });       
   1.413 -        var offset = new Array(13, 16);
   1.414 -        for (var c in text) {            
   1.415 -            var w = 0;
   1.416 -            for (p in char_map[text[c]]) {
   1.417 -                var x = char_map[text[c]][p][0];
   1.418 -                var y = char_map[text[c]][p][1];
   1.419 -                w = Math.max(w, x);
   1.420 -                var pos = new Array((x + offset[0]) * cell_size, 
   1.421 -                                    (y + offset[1]) * cell_size);
   1.422 -                gameoflife.activate_cell(pos);
   1.423 -            }            
   1.424 -            offset[0] += w + 2;
   1.425 -        }       
   1.426 -    }    
   1.427 -}
   1.428 -
   1.429 -function Colour(r, g, b, a) {
   1.430 -    this.r = r;
   1.431 -    this.g = g;
   1.432 -    this.b = b;
   1.433 -    this.a = a == undefined ? 255 : a;
   1.434 -}
   1.435 -Colour.prototype.equals = function(rhs) {
   1.436 -    for (p in this) {
   1.437 -        if (typeof(rhs[p]) == undefined
   1.438 -           || this[p] != rhs[p]) {           
   1.439 -            return false;
   1.440 -        }
   1.441 -    }
   1.442 -    return true;
   1.443 -}
   1.444 -Colour.prototype.str = function() {
   1.445 -    return "rgba(" + this.r + "," + this.g + "," + this.b + "," + this.a + ")";
   1.446 -}
   1.447 -
   1.448 -var white = new Colour(255, 255, 255);
   1.449 -var black = new Colour(0, 0, 0, 255);
   1.450 -var orange = new Colour(201, 87, 35, 255);
   1.451 -var green = new Colour(90, 215, 21, 255);
   1.452 -var background = new Colour(34, 34, 34, 255);
   1.453 -
   1.454 -function setPixel(image, x, y, colour) {
   1.455 -    var index = 4 * (x + y * image.width);
   1.456 -    image.data[index] = colour.r;
   1.457 -    image.data[index + 1] = colour.g;
   1.458 -    image.data[index + 2] = colour.b;
   1.459 -    image.data[index + 3] = colour.a;
   1.460 -}
   1.461 -
   1.462 -function getPixel(image, x, y) {   
   1.463 -    var index = 4 * (x + y * image.width);
   1.464 -    var r = image.data[index];
   1.465 -    var g = image.data[index + 1];
   1.466 -    var b = image.data[index + 2];
   1.467 -    var a = image.data[index + 3];
   1.468 -    return new Colour(r, g, b, a);
   1.469 -}
   1.470 -
   1.471 -function load_random_quote() {
   1.472 -    var file = "/quotes/quote" + Math.floor(Math.random() * QUOTES_NUMBER + 1) + ".html";
   1.473 -    $.ajax({url: SERVER + file,
   1.474 -            success: write_quote});
   1.475 -}
   1.476 -
   1.477 -function write_quote(data, status, xhr) {   
   1.478 -    $("#random_quote").html(data);
   1.479 -}
   1.480 -
   1.481 -function load_footer()
   1.482 -{
   1.483 -	var file = "/footer.html";
   1.484 -	var currentFile = self.location.hostname + self.location.pathname;		
   1.485 -	var request = http_request_object();
   1.486 -	var url  = "http://" + self.location.hostname + file;	
   1.487 -	request.open("GET", url, false);
   1.488 -	request.setRequestHeader("User-Agent", navigator.userAgent);
   1.489 -	request.send(null)
   1.490 -	// if (oRequest.status == 200) alert(oRequest.responseText);
   1.491 -	// else alert("Error executing XMLHttpRequest call!");	
   1.492 -	//document.write(url);
   1.493 -	//document.write(request.responseText);
   1.494 -    document.getElementById('footer').innerHTML = request.responseText;
   1.495 -}
   1.496 -
   1.497 -
   1.498 -
   1.499 -// Mandelbrot functions
   1.500 -function Complex(real, imag) 
   1.501 -{
   1.502 -	this.real = real;
   1.503 -	this.imag = imag;
   1.504 -}
   1.505 -
   1.506 -var MIN_C = new Complex(-2.2, -1.4);
   1.507 -var MAX_C = new Complex(1.0, 1.4);
   1.508 -var min_c = MIN_C;
   1.509 -var max_c = MAX_C;
   1.510 -var MIN_ITER = 100;
   1.511 -var max_iter = MIN_ITER;
   1.512 -var zoom = 1.0;
   1.513 -var resolution = 3;
   1.514 -var bailout = 4.0;
   1.515 -
   1.516 -function Result(z, iter) 
   1.517 -{
   1.518 -	this.z = z;
   1.519 -	this.iter = iter;
   1.520 -}
   1.521 -
   1.522 -function complex_quad(c)
   1.523 -{
   1.524 -	return new Complex(Math.pow(c.real, 2) - Math.pow(c.imag, 2), 
   1.525 -		2.0 * c.real * c.imag);
   1.526 -}
   1.527 -
   1.528 -function complex_quad_value(c)
   1.529 -{
   1.530 -	return Math.pow(c.real, 2) + Math.pow(c.imag, 2);
   1.531 -}
   1.532 -
   1.533 -function complex_add(c1, c2)
   1.534 -{
   1.535 -	return new Complex(c1.real + c2.real, c1.imag + c2.imag);
   1.536 -}
   1.537 -
   1.538 -function complex_equal(c1, c2)
   1.539 -{	
   1.540 -	return (c1.real == c2.real) && (c1.imag == c2.imag);
   1.541 -}
   1.542 -
   1.543 -function iterate(z, c) 
   1.544 -{
   1.545 -	z_quad = complex_quad(z);
   1.546 -	return new Complex(z_quad.real + c.real, z_quad.imag + c.imag);
   1.547 -}
   1.548 -
   1.549 -function test(c, max_iter) 
   1.550 -{
   1.551 -	var iter = 0;
   1.552 -	var z = new Complex(0.0, 0.0);
   1.553 -	var last_z = new Complex(-1.0, 0.0);
   1.554 -	var quad_z = complex_quad_value(z);
   1.555 -	
   1.556 -	while (iter < max_iter
   1.557 -		&& !complex_equal(z, last_z)
   1.558 -		&& quad_z <= bailout)
   1.559 -	{
   1.560 -		last_z = z;
   1.561 -		z = iterate(z, c);
   1.562 -		quad_z = complex_quad_value(z);
   1.563 -		iter++;
   1.564 -	}
   1.565 -	return new Result(quad_z, iter);
   1.566 -}
   1.567 -
   1.568 -function draw(diter, dx, dy, dz, dres)
   1.569 -{  
   1.570 -	var canvas = document.getElementById('mandelbrot'); 
   1.571 -	
   1.572 -	if (canvas.getContext)
   1.573 -	{  
   1.574 -		zoom += dz;
   1.575 -		var ctx = canvas.getContext('2d');
   1.576 -
   1.577 -		if (dres != 0)
   1.578 -		{		
   1.579 -			resolution = Math.max(1, resolution + dres);
   1.580 -		}
   1.581 -
   1.582 -		if (diter != 0)
   1.583 -		{
   1.584 -			max_iter = Math.max(MIN_ITER, max_iter + diter);
   1.585 -		}
   1.586 -		
   1.587 -		var red = "rgb(255, 0, 0)";
   1.588 -		var white = "rgb(255, 255, 255)";
   1.589 -		var width = canvas.width;
   1.590 -		var height = canvas.height;
   1.591 -		var dim = Math.max(width, height);
   1.592 -		var dim_ratio = Math.round(width / height);	
   1.593 -		var diff_c = new Complex(max_c.real - min_c.real,
   1.594 -			max_c.imag - min_c.imag);
   1.595 -		dx_min = diff_c.real / 100 * (dx + dz);
   1.596 -		dx_max = diff_c.real / 100 * (dx - dz);
   1.597 -
   1.598 -		dy_min = diff_c.imag / 100 * (dy + dz);
   1.599 -		dy_max = diff_c.imag / 100 * (dy - dz);
   1.600 -
   1.601 -		var min_inc = new Complex(dx_min * dim_ratio / 2.0, dy_min);
   1.602 -		var max_inc = new Complex(dx_max * dim_ratio / 2.0, dy_max);
   1.603 -		min_c = complex_add(min_c, min_inc);
   1.604 -		max_c = complex_add(max_c, max_inc);
   1.605 -		diff_c = new Complex(max_c.real - min_c.real,
   1.606 -			max_c.imag - min_c.imag);
   1.607 -		
   1.608 -		for (var y = 0; y < height; y += resolution) 
   1.609 -		{
   1.610 -			for (var x = 0; x < width; x += resolution) 
   1.611 -			{    			
   1.612 -				var c = new Complex(min_c.real + diff_c.real / dim * x, 
   1.613 -					min_c.imag + diff_c.imag / dim * y);  	
   1.614 -			 	var result = test(c, max_iter);	
   1.615 -		 		var r = Math.min(255, Math.pow(Math.max(0, 
   1.616 -		 			(result.iter - max_iter / 20.0)), 2));
   1.617 -				var g = Math.min(255, Math.pow(Math.max(0, 
   1.618 -					(result.iter - max_iter / 25.0)), 2));			
   1.619 -		 		var b = Math.min(255, Math.pow(Math.max(0, 
   1.620 -					(result.iter - max_iter / 20.0)), 2));
   1.621 -		 		var colour = "rgb(" + r + "," + g + "," + b + ")";
   1.622 -		 		ctx.fillStyle = colour; 
   1.623 -				ctx.fillRect(x, y, resolution, resolution);			
   1.624 -			}
   1.625 -  		}
   1.626 -	}  
   1.627 -} 
   1.628 -
   1.629 -function getEventOffsetX(evt)
   1.630 -{
   1.631 -	if (evt.offsetX != null)
   1.632 -		return evt.offsetX;
   1.633 - 
   1.634 -    var obj = evt.target || evt.srcElement;
   1.635 -   	setPageTopLeft(obj);
   1.636 -    return (evt.clientX - obj.pageLeft);
   1.637 -}
   1.638 -
   1.639 -function getEventOffsetY(evt)
   1.640 -{
   1.641 -	if (evt.offsetY != null)
   1.642 -		return evt.offsetY;
   1.643 - 
   1.644 -    var obj = evt.target || evt.srcElement;
   1.645 -   	setPageTopLeft(obj);
   1.646 -    return (evt.clientY - obj.pageTop);
   1.647 -}
   1.648 - 
   1.649 -function setPageTopLeft( o )
   1.650 -{
   1.651 -    var top = 0,
   1.652 -    left = 0,
   1.653 -    obj = o;
   1.654 - 
   1.655 -    while (o.offsetParent)
   1.656 -     {
   1.657 -         left += o.offsetLeft ;
   1.658 -         top += o.offsetTop ;
   1.659 -         o = o.offsetParent ;
   1.660 -    };
   1.661 - 
   1.662 -    obj.pageTop = top;
   1.663 -    obj.pageLeft = left; 
   1.664 -}
   1.665 - 
   1.666 -function draw2(evt) {
   1.667 -    var iter = 0;
   1.668 -    var res = 0;
   1.669 -    var x = (getEventOffsetX(evt) - 335) / 167.5;
   1.670 -    var y = (getEventOffsetY(evt) - 140) / 70;
   1.671 -    var z = 0;
   1.672 -    draw(iter, x, y, z, res);
   1.673 -}
   1.674 -
   1.675 -function update() {
   1.676 -    simulation.update();
   1.677 -    simulation.draw();
   1.678 -    if (gameoflife) {
   1.679 -        gameoflife.update();
   1.680 -        gameoflife.draw();
   1.681 -    }
   1.682 -}
   1.683 -
   1.684 -function Grid(width, height, cell_size) {
   1.685 -    this.width = parseInt(width / cell_size + 0.5);
   1.686 -    this.height = parseInt(height / cell_size + 0.5);
   1.687 -    this.canvas_width = width;
   1.688 -    this.canvas_height = height;
   1.689 -    this.cell_size = cell_size;  
   1.690 -    this.cells = new Array();
   1.691 -    for (var y = 0; y < this.height; ++y) { 
   1.692 -        this.cells[y] = new Array();
   1.693 -        for (var x = 0; x < this.width; ++x) {
   1.694 -            this.cells[y][x] = new Cell(x, y, 0, this);
   1.695 -        }
   1.696 -    }
   1.697 -}
   1.698 -Grid.prototype.cell = function(x, y) {   
   1.699 -    return this.cells[y][x];
   1.700 -}
   1.701 -Grid.prototype.pick_cell = function(x, y) {
   1.702 -    var lx = parseInt(x / this.cell_size - 0.5);
   1.703 -    var ly = parseInt(y / this.cell_size - 0.5);
   1.704 -    return this.cells[ly][lx];
   1.705 -}
   1.706 -
   1.707 -function Cell(x, y, value, grid) {
   1.708 -    this.x = x;
   1.709 -    this.y = y;  
   1.710 -    this.canvas_x = x * grid.cell_size;
   1.711 -    this.canvas_y = y * grid.cell_size;
   1.712 -    this.value = value;
   1.713 -    this.grid = grid;
   1.714 -    this._neighbours = new Array();
   1.715 -    this.last_mod = 0;
   1.716 -}
   1.717 -Cell.prototype.hash = function() {
   1.718 -    return this.x + ", " + this.y;
   1.719 -}
   1.720 -Cell.prototype.set_value = function(value) {
   1.721 -    this.value = value;
   1.722 -    this.last_mod = $.now();
   1.723 -}
   1.724 -Cell.prototype.neighbours = function() {
   1.725 -    if (this._neighbours.length) {
   1.726 -        return this._neighbours;
   1.727 -    }
   1.728 -    if (this.x > 0) {
   1.729 -        this._neighbours.push(this.grid.cell(this.x-1, this.y));
   1.730 -        if (this.y > 0) {
   1.731 -            this._neighbours.push(this.grid.cell(this.x-1, this.y-1));
   1.732 -            this._neighbours.push(this.grid.cell(this.x, this.y-1));
   1.733 -        }
   1.734 -        if (this.y + 1 < this.grid.height) {
   1.735 -            this._neighbours.push(this.grid.cell(this.x-1, this.y+1));
   1.736 -        }
   1.737 -    }   
   1.738 -    if (this.x + 1 < this.grid.width) {
   1.739 -        this._neighbours.push(this.grid.cell(this.x+1, this.y));
   1.740 -        if (this.y + 1 < this.grid.height) {
   1.741 -            this._neighbours.push(this.grid.cell(this.x+1, this.y+1));
   1.742 -            this._neighbours.push(this.grid.cell(this.x, this.y+1));
   1.743 -        }
   1.744 -        if (this.y > 0) {
   1.745 -            this._neighbours.push(this.grid.cell(this.x+1, this.y-1));
   1.746 -        }
   1.747 -    }
   1.748 -    return this._neighbours;
   1.749 -}
   1.750 -Cell.prototype.density = function() {
   1.751 -    var d = 0;
   1.752 -    var neighbours = this.neighbours();
   1.753 -    for (var n in neighbours) {
   1.754 -        d += neighbours[n].value;
   1.755 -    }
   1.756 -    return d;
   1.757 -}
   1.758 -
   1.759 -function Simulation(canvas, w, h, cell_size, life_colour, dead_colour) {
   1.760 -    this.last_update = $.now() + 3000;
   1.761 -    this.last_draw = 0;
   1.762 -    this.last_mouse_moved = 0;
   1.763 -    this.redraw = new Array();   
   1.764 -    this.canvas = canvas;
   1.765 -    this.canvas.width = w;
   1.766 -    this.canvas.height = h;
   1.767 -    this.context = canvas.getContext("2d");    
   1.768 -    this.pos_queue = new Array();
   1.769 -    this.cell_queue = new Array();  
   1.770 -    this.cell_size = cell_size;
   1.771 -    this.life_colour = life_colour;
   1.772 -    this.dead_colour = dead_colour;
   1.773 -    this.grid = new Grid(this.canvas.width, this.canvas.height, cell_size);
   1.774 -    draw_sim_lines();
   1.775 -}
   1.776 -Simulation.prototype.draw = function() {
   1.777 -    var now = $.now();
   1.778 -    if (this.redraw.length) {
   1.779 -        var cell = this.redraw[0];
   1.780 -        this.redraw.shift();
   1.781 -        this.context.fillStyle = cell.value == 1 ? 
   1.782 -            this.life_colour.str() : this.dead_colour.str();
   1.783 -        this.context.fillRect(cell.canvas_x, cell.canvas_y, 
   1.784 -                              this.grid.cell_size, this.grid.cell_size);
   1.785 -        this.last_draw = $.now();
   1.786 -    }
   1.787 -}
   1.788 -Simulation.prototype.update = function() {
   1.789 -    var now = $.now();
   1.790 -    while (this.pos_queue.length) {
   1.791 -        var pos = this.pos_queue.pop();       
   1.792 -        if (pos[0] < this.canvas.width
   1.793 -            && pos[1] < this.canvas.height) {
   1.794 -            var cell = this.grid.pick_cell(pos[0], pos[1]);
   1.795 -            cell.set_value(1);
   1.796 -            this.cell_queue.push(cell);
   1.797 -            this.cell_queue.concat(cell.neighbours()); 
   1.798 -            this.redraw.unshift(cell);          
   1.799 -        }
   1.800 -    }
   1.801 -    if (this.last_update + 1000 > now) {
   1.802 -        return;
   1.803 -    }
   1.804 -    var changed = new Array();
   1.805 -    var next_cell_queue = new Array();
   1.806 -    while (this.cell_queue.length) {
   1.807 -        var cell = this.cell_queue.pop();       
   1.808 -        if (changed[cell.hash()]) {           
   1.809 -            continue;
   1.810 -        }
   1.811 -        var d = cell.density();
   1.812 -        if (d == 3 && cell.value == 0) {           
   1.813 -            changed[cell.hash()] = cell;            
   1.814 -            next_cell_queue = next_cell_queue.concat(cell.neighbours());               
   1.815 -        } else if (cell.value == 1) {
   1.816 -            if (d < 2 || d > 3) {              
   1.817 -                changed[cell.hash()] = cell;                
   1.818 -                next_cell_queue = next_cell_queue.concat(cell.neighbours());               
   1.819 -            }
   1.820 -        }       
   1.821 -    }
   1.822 -    for (var pos in changed) {
   1.823 -        var cell = changed[pos];      
   1.824 -        cell.set_value(1 - cell.value);
   1.825 -        this.redraw.push(cell);
   1.826 -    }
   1.827 -    this.cell_queue = next_cell_queue;
   1.828 -    this.last_update = now;  
   1.829 -}
   1.830 -Simulation.prototype.activate_cell = function(pos) {
   1.831 -    this.pos_queue.push(pos);   
   1.832 -}
   1.833 -Simulation.prototype.mouse_moved = function(pos) {
   1.834 -    var now = $.now();    
   1.835 -    if (this.last_mouse_moved + 50 < now) {       
   1.836 -        this.pos_queue.push(pos);      
   1.837 -        this.last_mouse_moved = now;       
   1.838 -    }
   1.839 -}
   1.840 -
   1.841 -