Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Last active June 2, 2016 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hasherezade/93859967f007beebb80f to your computer and use it in GitHub Desktop.
Save hasherezade/93859967f007beebb80f to your computer and use it in GitHub Desktop.
Xmass Tree
// CC-BY: hasherezade (hasherezade.net)
function makeTree(height = 6)
{
var treeHtml="";
var width = 1;
var leaf = "###"
var snow = "-*-";
var snowC = 4;
var background ="#000011";
treeHtml = "<pre style=\"background-color:"+background+";\"><center>\n\n";
treeHtml += "<font color=\"YELLOW\">/\\\n< >\n\\/\n</font>"; // star
treeHtml += "<font color=\"LIME\">";
var shade = false;
for (i=0; i <= height; i++) {
for (x=0; x <= 4; x++){
for (y=1; y <= width; y++) {
var rand = (Math.round((Math.random() * 1000)) % snowC) + 1;
if (rand == snowC) {
treeHtml += "</font><font color=WHITE>" + snow + "</font>";
shade = true;
}
else {
if (shade == false) {
treeHtml += leaf
} else {
treeHtml += "<font color=GREEN>" + leaf + "</font>";
}
}
}
treeHtml += "\n";
width++;
}
width=width-3;
}
treeHtml += "</font>";
treeHtml += "<font color=#000000><b style=\"background-color: #000000;\">#####\n";
treeHtml += "#####\n</b></font>";
treeHtml += "</center></pre>";
document.getElementById("tree").innerHTML = treeHtml;
}
function makeFlashyTree(height = 6)
{
makeTree(height);
setInterval( function() { makeTree(height); }, 1000);
}
<html>
<head>
<script language="javascript" src="tree.js"></script>
</head>
<body bgcolor="black" onload="makeFlashyTree(5)">
<div id="tree">
<!-- Tree will be placed here...-->
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment