主要将canvas的方法列举,并且有实例
/*
<canvas> 初始化是空白的,要在上面用脚本画图首先需要其渲染上下文(rendering context),
它可以通过 canvas 元素对象的 getContext 方法来获取,同时得到的还有一些画图用的函数。getContext() 接受一个用于描述其类型的值作为参数。
*/
var canvas = {
$ : function(id){return (typeof id) === 'string' ? document.getElementById(id) : id;},
context : function(id){
var vas = canvas.$(id);
if(vas.getContext){
var ctx = vas.getContext('2d');
return ctx;
}else{
return null;
}
},
/*
绘制矩形
不像 SVG,canvas 只支持一种基本形状——矩形,所以其它形状都是有一个或多个路径组合而成。还好,有一组路径绘制函数让我们可以绘制相当复杂的形状。
*/
rectangleTwo : function(id){
var ctx = canvas.context(id);
if(ctx){
ctx.fillStyle = 'rgb(200,0,0)';//填充颜色
ctx.fillRect(10,10,55,50);//制作形状
ctx.fillStyle = 'blue';
ctx.fillRect(30,30,55,50);
//fillRect(x,y,width,height) : Draws a filled rectangle
//ctx.fillRect(25,25,100,100);
//clearRect(x,y,width,height) : Clears the specified area and makes it fully transparent
//ctx.clearRect(45,45,60,60);
//strokeRect(x,y,width,height) : Draws a rectangular outline
//ctx.strokeRect(50,50,50,50);
//ctx.rect(100,100,50,50);
}
},
triangle : function(id){
var ctx = canvas.context(id);
if(ctx){
ctx.beginPath();
ctx.moveTo(75,50);
ctx.lineTo(100,75);
ctx.lineTo(100,25);
ctx.fill();
}
},
thegoneheart : function(id){
var ctx = canvas.context(id);
if(ctx){
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
ctx.moveTo(110,75);
ctx.arc(75,75,35,0,Math.PI,false); // Mouth (clockwise)
ctx.moveTo(65,65);
ctx.arc(60,65,5,0,Math.PI*2,true); // Left eye
ctx.moveTo(95,65);
ctx.arc(90,65,5,0,Math.PI*2,true); // Right eye
ctx.stroke();
ctx.beginPath();
ctx.moveTo(40,75);
ctx.lineTo(60,65);
ctx.lineTo(90,65);
ctx.moveTo(110,75);
ctx.lineTo(125,75);
ctx.stroke();
}
},
triangleTwo : function(id){
var ctx = canvas.context(id);
if(ctx){
// 填充三角形
ctx.beginPath();
ctx.moveTo(25,25);
ctx.lineTo(105,25);
ctx.lineTo(25,105);
ctx.fill();
// 勾边三角形
ctx.beginPath();
ctx.moveTo(125,125);
ctx.lineTo(125,45);
ctx.lineTo(45,125);
ctx.closePath();
ctx.stroke();
}
},
arc : function(id){
//面积(s)=圆周率π(3.14)*半径(r)的平方
//圆的周长公式C=2π r
//圆的面积公式S=π r2
var ctx = canvas.context(id);
if(ctx){
/*for(var i=0;i<4;i++){
for(var j=0;j<3;j++){
ctx.beginPath();
var x = 25 + j*50,
y = 25 + i
HTML5.Canvas.教程_计算机软件及应用_IT/计算机_专业资料。方便各位学习新技术,web前端开发HTML5 Canvas 教程原作者:Eric Rowell 原文地址:http://www.html5...
HTML5的Canvas标签详解_计算机硬件及网络_IT/计算机_专业资料。 <canvas>是html5当中的一个标签,通过Javascript来画图。 <canvas id=”canvas” width=”150〃 ...
Html5 Canvas 初探学习笔记(1)-画一个矩形 canvas 元素是 Html5 相对于之前的 Html 的一个新增特性, 本部分的博客文章就将研究 这个组件的应用,尤其是在网页...
html5基础教程_canvas标签介绍_计算机软件及应用_IT/计算机_专业资料。html视频教程,专注html教程,提供专业的html视频教程下载。html基础教程-零基础学习html-html...
//dev.w3.org/html5/canvas-api/canvas-2d-api.html 摘要...2 1 1.1 2 2.1 2.2 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.8.1...
HTML5高级篇-canvas_计算机软件及应用_IT/计算机_专业资料。HTML5移动开发 ——Canvas篇 内容大纲 1. canvas简介 2. canvas基础应用 3. canvas动画 1、canvas...
html5基础教程_canvas实例2-太阳系1 课件_其它语言学习_外语学习_教育专区。html视频教程,专注html教程,提供专业的html视频教程下载。html基础教程-零基础学习html-...
HTML5 Canvas 属性、定义及方法_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 HTML5 Canvas 属性、定义及方法_IT/计算机_专业资料。HTML5 Canvas ...
Html5 Canvas 基础 HTML 5 规 范引 进 了很 多新 特性 ,其中 最令人 期待 的之 一 就是 canvas 元素。 HTML 5 canvas 提 供了 通过 JavaScript 绘制图...
html5 canvas基本属性与用法介绍_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 html5 canvas基本属性与用法介绍_IT/计算机_专业资料。这个ppt就是用来...
热门文档