Home  >  Article  >  Web Front-end  >  How to draw js hollow graphics quickly

How to draw js hollow graphics quickly

巴扎黑
巴扎黑Original
2016-11-25 11:54:411413browse

/*空心直角三角形*/

    for (var i = 0; i < 10; i++) {

        (i == 0 || i == 9) ? document.write(Array(i + 2).join("* ") + "
") : document.write("*" + Array(i + 1).join("   ") + "*
");

    }

    /*空心菱形*/

    var arr = [];

    for (var p = 0; p < 6; p++) {

        (p == 0) ? arr.push(Array(6).join("   ") + "*
") : arr.push(Array(6 - p).join("   ") + "*" + Array(p * 2 + 1).join("   ") + "*
");

    }

    (document.write(arr.join("")), arr.pop(), document.write(arr.reverse().join("")));


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn