Canvas1——基础api实验



  
  
  
  
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<script src="app.js"></script>
</head>
<body>
 
</body>
</html>
  
  
  
  
var CANVAS_HEIGHT = 500, CANVAS_WIDth = 500;
var mycanvas, context;
 
window.onload = function () {
createCanvas();
drawRect();
}
 
function createCanvas() {
document.body.innerHTML = "<canvas id=\"mycanvas\" width=\""+CANVAS_WIDth+"\" height=\""+CANVAS_HEIGHT+"\"></canvas>"
mycanvas = document.getElementById("mycanvas");
context = mycanvas.getContext("2d");
}
 
function drawRect() {
context.fillStyle="red";
context.translate(200,200);
context.scale(2,0.5);
context.fillRect(0,0,200,200);
}
 
function drawImage() {
var img = new Image();
img.src = "12.jpg";
img.onload = function () {
context.drawImage(img, 0, 0);
}
}
   
   
   
   
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<script src="app.js"></script>
</head>
<body>
 
</body>
</html>
   
   
   
   
var CANVAS_HEIGHT = 500, CANVAS_WIDth = 500;
var mycanvas, context;
 
window.onload = function () {
createCanvas();
drawRect();
}
 
function createCanvas() {
document.body.innerHTML = "<canvas id=\"mycanvas\" width=\""+CANVAS_WIDth+"\" height=\""+CANVAS_HEIGHT+"\"></canvas>"
mycanvas = document.getElementById("mycanvas");
context = mycanvas.getContext("2d");
}
 
function drawRect() {
context.fillStyle="red";
context.translate(200,200);
context.scale(2,0.5);
context.fillRect(0,0,200,200);
}
 
function drawImage() {
var img = new Image();
img.src = "12.jpg";
img.onload = function () {
context.drawImage(img, 0, 0);
}
}

你可能感兴趣的:(Canvas1——基础api实验)