HTML5之Canvas画正方形
来源:互联网 发布:hifiman supermini知乎 编辑:程序博客网 时间:2024/05/17 08:05
HTML5之Canvas画正方形
1、设计源码
<!DOCTYPE html><head><meta charset="utf-8" /><title>HTML5之Canvas画正方形</title><script type="text/javascript"> function drawFour(id){//获取canvas元素var canvas = document.getElementById("canvas");if(canvas == null) return false;//获取上下文var context = canvas.getContext('2d');//设定填充图形的样式context.fillStyle = "#EEEEFF";//绘制图形context.fillRect(0,0,800,800);context.fillStyle = "yellow";//设定图形边框的样式context.strokeStyle = "blue";//指定线宽context.lineWidth = 150;context.fillRect(50,50,500,500);context.strokeRect(50,50,500,500);}</script></head><body onLoad="drawFour('canvas')"> <canvas id="canvas" width="1200" height="560"/></body>
2、设计结果
3、分析说明
(1)获取Canvas元素
var canvas = document.getElementById("canvas");
(2)取到上下文
var context = canvas.getContext('2d');
(3)填充绘制边框
context.fillStyle = "#EEEEFF";//填充的样式
(4)设定绘图样式
strokeStyle:图形边框的样式
(5)指定线宽
context.lineWidth = 150;
(6)指定颜色值
(7)绘制正方形
context.fillRect(50,50,500,500);
context.strokeRect(50,50,500,500);
1 0
- HTML5之Canvas画正方形
- HTML5之Canvas画圆形
- HTML5 画一个正方形
- HTML5 canvas性能之画圈
- HTML5中canvas画图之画圆形
- Html5 之 Canvas
- HTML5研究之canvas
- Html5系列之Canvas
- html5之canvas
- html5之canvas动画
- html5--canvas之arcTo()
- html5 之canvas标签
- HTML5之Canvas
- html5之canvas起步
- html5之canvas进阶
- html5之canvas进阶
- HTML5学习之-Canvas
- 初识之-html5 Canvas
- 调用bios喇叭发声
- POJ 1125 Stockbroker Grapevine(floyd两点间最短距离)
- zookeeper原理(转)
- ubuntu cpu 占有率 100%
- Using the Material Theme
- HTML5之Canvas画正方形
- 黑马程序员————Foundation
- Scala-5 - 1 - Lecture 4.1 - Functions as Objects (8_04)
- 【转载】Java中静态的代码块,静态变量,静态方法
- 装双系统(win7/win8/ubuntu)的问题总结
- 【归并排序】php实现
- gcc编译器优化给我们带来的麻烦???
- Windows安装和使用zookeeper
- POJ1004 Financial Management