Created
October 4, 2014 19:46
-
-
Save Zhangerr/c4c4693f5a93231f7fd7 to your computer and use it in GitHub Desktop.
Diamond generator
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
// * | |
// *** | |
// ***** | |
// ******* | |
// ********* | |
// ******* | |
// ***** | |
// *** | |
// * | |
// * | |
// *** | |
// ***** | |
// *** | |
// * | |
function diamond(n) { | |
for(var i = 0; i < n; i++) { | |
var spaces = Math.abs((n-1)/2-i) | |
var ast = i <= (n-1)/2? 1+2*i : n-2*(i-(n-1)/2) | |
var s = '' | |
for(var c = 0; c < spaces; c++) { | |
s += ' ' | |
} | |
for(var c = 0; c < ast; c++) { | |
s += '*' | |
} | |
console.log(s) | |
} | |
} | |
for(var i = 1; i< 59; i+=2) { | |
setTimeout(diamond,20*i,i) | |
} | |
for(var i = 59; i>0; i-=2) { | |
setTimeout(diamond,50*20+20*(59-i),i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment