From 68b8ea8a79459f36a4a529bd1d3ddb582e0485f2 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 22 Dec 2010 12:06:51 +0000 Subject: [PATCH] Snow machichara improvements --- .../js/machichara/fractalsnow-bg-specific.js | 4 +- static/js/machichara/fractalsnow-specific.js | 82 ------------------- 2 files changed, 3 insertions(+), 83 deletions(-) diff --git a/static/js/machichara/fractalsnow-bg-specific.js b/static/js/machichara/fractalsnow-bg-specific.js index 6c7ea0a..5719484 100644 --- a/static/js/machichara/fractalsnow-bg-specific.js +++ b/static/js/machichara/fractalsnow-bg-specific.js @@ -18,6 +18,8 @@ Snow(); else window.addEventListener('DOMContentLoaded', Snow, false); + } else { + return; } var deg = Math.PI / 180; // For converting degrees to radians @@ -37,7 +39,7 @@ canvas.style.position = 'fixed'; canvas.style.top = '0px'; canvas.style.left = '0px'; - canvas.style.zIndex = '0'; + canvas.style.zIndex = '-1'; document.body.insertBefore(canvas, document.body.firstChild); sky = canvas.getContext('2d'); diff --git a/static/js/machichara/fractalsnow-specific.js b/static/js/machichara/fractalsnow-specific.js index b1374fd..cba0ea9 100644 --- a/static/js/machichara/fractalsnow-specific.js +++ b/static/js/machichara/fractalsnow-specific.js @@ -21,9 +21,6 @@ (function() { // If we don't have a working element, apologize and quit if (!document.createElement("canvas").getContext) { - alert("Your browser doesn't support \n" + - "No snow for you!\n" + - "Please try a recent version of Firefox, Chrome or Safari"); return; } @@ -70,9 +67,6 @@ var deg = Math.PI/180; // For converting degrees to radians var sqrt3_2 = Math.sqrt(3)/2; // Height of an equilateral triangle var flakes = []; // Things that are dropping - var cover = new Image(); - cover.src = "http://covers.oreilly.com/images/0636920016045/cat.gif"; - var coverwidth = 180, coverheight = 296; var scrollspeed = 80; // How often we animate things var snowspeed = 500; // How often we add a new snowflake var rand = function(n) { return Math.floor(n*Math.random()); } @@ -104,47 +98,6 @@ // Add the canvas to the document and to our array of snowflakes document.body.appendChild(canvas); flakes.push({elt:canvas, x: x, y:y, vy:3+rand(3)}); - - // Once in a while, add something different to the mix - if (rand(100) == 1) { - // drop the cover image - var img = document.createElement("img"); - img.src = cover.src; - var scale = Math.random()/2 + .25; - img.width = Math.round(coverwidth * scale); - img.height = Math.round(coverheight*scale); - img.style.position = "absolute"; - var x = rand(window.innerWidth - img.width - 150); - var y = window.pageYOffset; - img.style.top = y + "px"; - img.style.left = x + "px"; - img.style.zIndex = 200; - document.body.appendChild(img); - flakes.push({elt:img, x:x, y:y, vy:4}); - - // and drop a message, too - var div = document.createElement("div"); - div.style.width = "120px"; - div.style.height = "40px"; - div.style.position = "absolute"; - x = x + img.width + 20; - y = y + 30; - div.style.top = y + "px"; - div.style.left = x + "px"; - div.style.zIndex = 200; - document.body.appendChild(div); - - div.innerHTML = "Save 40% with code AUTHD"; - div.style.border = "solid red 2px"; - div.style.backgroundColor = "#c00"; - div.style.border = "solid black 1px"; - div.style.font = "bold 10pt sans-serif"; - div.style.color = "#fff"; - div.style.textAlign = "center"; - div.style.padding = "3px"; - - flakes.push({elt:div, x:x, y:y, vy:4}); - } } // This function animates the flakes falling down the screen @@ -182,41 +135,6 @@ var scrolltimer = setInterval(moveSnowflakes, scrollspeed); var snowtimer = setInterval(createSnowflake, snowspeed); - // - var controls = document.createElement("div"); - controls.style.position = "fixed"; - controls.style.left = "2%"; - controls.style.top = "5px"; - controls.style.width = "96%"; - controls.style.padding = "5px"; - controls.style.zIndex = 1000; - controls.style.backgroundColor = "#c00"; - controls.style.border = "solid black 1px"; - controls.style.borderRadius = "4px"; - controls.style.font = "bold 10pt sans-serif"; - controls.style.color = "#fff"; - - document.body.appendChild(controls); - - controls.innerHTML = - "Koch snowflake fractals from " + - "" + - "Canvas Pocket Reference. " + - "" + - "Learn how it works. Happy Holidays! "; - var stopbutton = document.createElement("button"); - stopbutton.innerHTML = "Stop"; - controls.appendChild(stopbutton); - - stopbutton.onclick = function() { - clearInterval(scrolltimer); - clearInterval(snowtimer); - for(var i = 0; i < flakes.length; i++) - document.body.removeChild(flakes[i].elt); - document.body.removeChild(controls); - }; } if (document.readyState === "complete") snow();