Last active
June 2, 2016 07:35
-
-
Save hasherezade/93859967f007beebb80f to your computer and use it in GitHub Desktop.
Xmass Tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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