How to make circular graphics with JavaScript

Source: Internet
Author: User

"The idea of drawing questions"

1. Determine the number of times the graph has a total of several lines, that is, the outer loop
2. Make sure there are several elements in each row that represent several inner loops
3. Determine the number of each element, that is, the number of cycles per inner layer
Tips: Usually, find out the relationship between the number of each element and the line number, which is the maximum value of the current inner loop

Rectangle: Loop 5 times per line, then cycle 5 rows

<script type= "Text/javascript" >


for (Var a=1;a<=5;a++) {
for (Var b=1;b<=5;b++) {
document.write ("*");
}
document.write ("<br/>")
}



</script>

Right triangle: Like a rectangle, except that the number of loops in the line is equal to the row times

<script type= "Text/javascript" >


for (Var a=1;a<=5;a++) {
for (Var b=1;b<=a;b++) {
document.write ("*");
}
document.write ("<br/>")
}



</script>

Parallelogram: First design an accompanying increment of the space cycle, added in the rectangle

<script type= "Text/javascript" >


for (Var a=1;a<=5;a++) {
for (Var c=1;c<a;c++) {
document.write ("&nbsp&nbsp")
}

for (Var b=1;b<=5;b++) {
document.write ("*");

}
document.write ("<br/>")


}

</script>

Diamond: Divided into the upper and lower parts, the above section is similar to parallelogram structure, find * number and row of the relationship for 2n-1, complete the above loop. The lower half will be the upper part reversed.

<script type= "Text/javascript" >

for (var a = 1;a<=7;a=a+2) {
For (Var c=1;c<= (7-a)/2;c++) {
document.write ("&nbsp&nbsp")
}



for (var B = 1;b<=a;b=b+1) {
document.write ("1")
}

document.write ("<br/>")
}
for (var a = 5;a>=1;a=a-2) {
For (Var c=1;c<= (7-a)/2;c++) {
document.write ("&nbsp&nbsp")
}
for (var B = 1;b<=a;b=b+1) {
document.write ("1")
}
document.write ("<br/>")
}


</script>

Digital equilateral triangle: similar to the upper half of the diamond, but to be divided into left and right two loops, the left is incremented, the number is a row, and a decrement of the number of rows to 1

<script type= "Text/javascript" >

var D;


for (var a = 1;a<=7;a=a+2) {
For (Var c=1;c<= (7-a)/2;c++) {
document.write ("&nbsp&nbsp")
}

for (var B = 1;b<= (a+1)/2;b=b+1) {
document.write (b)
}

for (var B = (A-1)/2;b>=1;b=b-1) {
document.write (b)
}

document.write ("<br/>")
}



</script>

99 Multiplication Table

<script type= "Text/javascript" >

document.write ("<table border= ' 1px ' bordercolor= ' black ' align= ' center ' >")
for (var a = 1;a<=9;a++) {

document.write ("<tr>")
for (var b =1,c=1,e=b*c; b<=a;b++,c++) {
document.write ("<td>" +b+ "*" +c+ "=" +e+ "</td>")
}


document.write ("</tr>")
}

document.write ("</table>")


</script>

How to make circular graphics with JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.