This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10867|Reply: 4

[HTML/HTML5] HTML5 Canvas draws rectangles and circles

[Copy link]
Posted on 12/14/2018 4:41:58 PM | | | |
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        Steps to <!-- drawing: Get the canvas element - > get the context - > fill and draw the border - > set the drawing style - >
        <!-- drawing other complex graphs requires paths: Start Creating Path - > Create Drawing Path - > Close Path - > Drawing Graph - >
        <!--eg: Draw a rectangle - >
        Draw a rectangle: <canvas id="ca"></canvas><br/>
        Draw a circle: <canvas id="yuan"></canvas>
    </body>
</html>
<scrip{filter}t>
    Draw a rectangle
    function draw(){
        var canvas=document.getElementById('ca'); Get the canvas element
        if (canvas==null)
           return false;
        var context=canvas.getContext('2d'); Get context
        context.fillStyle='#EEEFF';   Fill color
        context.fillRect(0,0,400,300); Fill Rectangle (Rectangle 1)
        context.fillStyle='red';
        context.strokeStyle='blue'; Border color
        context.lineWidth=1;        Bezel width
        context.fillRect(50,50,100,100); Fill Rectangle (Inner Rectangle 2)
        context.strokeRect(50,50,100,100); Draw the border
        
    }
    Draw circles
   function drawarc(){
    var canvas2=document.getElementById('yuan'); Get the canvas element
        if (canvas2==null)
    if(canvas2==null)
       return false;
       var context2=canvas2.getContext('2d');  Get context
       context2.fillStyle='#EEEEEF';
       context2.fillRect(0,0,400,300);
       var n=0;
       for(var i=0; i<10; i++){
              context2.beginPath();  Start creating a path
              context2.arc(i*25,i*25,i*10,0,Math.PI*2,true);  Create a circular path
              context2.closePath();  Close the path
              context2.fillStyle='Rgba(255,0,0,0.25)'; Set the color
              context2.fill();  Fill the graphic
       }
}
   
   
</scrip{filter}t>

Score

Number of participants1MB+1 contribute+1 Collapse reason
Little scum + 1 + 1 Support the owner to post a good post, and I will also post a good post!.

See all ratings





Previous:Use the Sina interface to obtain the client IP
Next:Organize the secret recipe for food and snacks (long-term download)
Posted on 12/14/2018 5:18:19 PM |
Can you attach a screenshot? Thank you
Posted on 12/14/2018 5:37:03 PM |
Come on
Posted on 12/14/2018 7:00:39 PM |
On the same second floor, it is recommended that the owner take screenshots so that more people can see the effect
Posted on 12/17/2018 1:30:54 PM |

It runs like this, what is this?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com