先看个Hello World吧。
大气象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>HTML5 Hello World</title>
    
<script type="text/javascript">
        
function f() {
            
var canvas = document.getElementById('panel');
            
var ctx = canvas.getContext("2d");//取得canvas对象
            ctx.clearRect(00200200);//清除一个区域
            ctx.strokeStyle = "blue";//线色
            ctx.strokeRect(1010180180);//画矩形
        }
    
</script>
</head>
<body>
<canvas id="panel" width="200" height="200" style="background-color:red;">
    你的浏览器不支持 Canvas 标签
</canvas>
<input type="button" value="画矩形" onclick="f();" />
</body>
</html>

画基本图形

大气象
//画矩形区域
function fillRect() {
    
var canvas = document.getElementById('test1');
    
var ctx = canvas.getContext("2d");
    ctx.clearRect(
00100200);
    ctx.fillStyle 
= "blue";
    ctx.fillRect(
1010180180);
}
//画三角形
function drawTri(){
    
var canvas = document.getElementById('test2');
    
var ctx=canvas.getContext("2d");
    ctx.beginPath();
    ctx.moveTo(
75,50);
    ctx.lineTo(
100,75);
    ctx.lineTo(
100,25);
    ctx.fill();
}

 

每天学一点吧。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-12-26
  • 2021-08-31
  • 2021-06-04
  • 2022-01-20
  • 2021-04-07
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2021-10-30
  • 2022-02-02
  • 2021-11-18
  • 2021-11-06
  • 2021-04-12
相关资源
相似解决方案