ExtJS中运用HTML5 Canvas简单例子
2012-04-13 15:00
344 查看
在ExtJS的Panel组件上使用HTML5的Canvas对象画图
的简单例子,效果如下:
![](http://my.csdn.net/uploads/201204/13/1334300467_7396.png)
怎么运行源代码:
新建两个文件,分别命名为mydemo.html, mydemo.js以后,将对应的HTML源代码
与JavaScript代码copy到各自的文件中,在同一目录下使用Google Chrome浏览器
或者IE9.0打开html文件即可看到效果!
HTML的代码如下:
一定要有ExtJS的库文件支持!!!
本文出自 “流浪的鱼” 博客,请务必保留此出处http://gloomyfish.blog.51cto.com/8837804/1400368
的简单例子,效果如下:
![](http://my.csdn.net/uploads/201204/13/1334300467_7396.png)
怎么运行源代码:
新建两个文件,分别命名为mydemo.html, mydemo.js以后,将对应的HTML源代码
与JavaScript代码copy到各自的文件中,在同一目录下使用Google Chrome浏览器
或者IE9.0打开html文件即可看到效果!
HTML的代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Example</title> <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" /> <link rel="stylesheet" type="text/css" href="../shared/example.css" /> <script type="text/javascript" src=\'#\'" /../bootstrap.js"></script> <script language="javascript" src=\'#\'" /script> </head> <body> <h1>ExtJS with HTML5 Demo</h1> <p>The js is not minified so it is readable. See <a href="mydemo.js">source code</a>.</p> <div id="my-demo"></div> </body> </html>ExtJS的代码如下:
/** * HTML5 Canvas Demo */ // create namespace Ext.namespace('Test'); // create application Test.app = function() { return { // public methods init: function() { var grid = new Ext.Panel({ renderTo: 'my-demo', title:'Simple HTML5 Canvas Demo', bodyStyle: 'padding: 10px;', borders: true, plain: true, xtype: 'panel', width:400, height:400, html: '<canvas id="canvas" width="400" height="400"></canvas>' }); }, // end of init onDraw: function() { this.canvas = document.getElementById('canvas'); this.ctx = this.canvas.getContext("2d"); // create a blank image data var canvas2Data = this.ctx.createImageData(this.canvas.width, this.canvas.height); for ( var x = 0; x < canvas2Data.width; x++) { for ( var y = 0; y < canvas2Data.height; y++) { // Index of the pixel in the array var idx = (x + y * canvas2Data.width) * 4; // assign gray scale value var distance = Math.sqrt((x - canvas2Data.width / 2) * (x - canvas2Data.width / 2) + (y - canvas2Data.height / 2) * (y - canvas2Data.height / 2)); var cvalue = (128.0 + (128.0 * Math.sin(distance / 8.0))); canvas2Data.data[idx + 0] = cvalue; // Red channel canvas2Data.data[idx + 1] = cvalue; // Green channel canvas2Data.data[idx + 2] = cvalue; // Blue channel canvas2Data.data[idx + 3] = 255; // Alpha channel } } this.ctx.putImageData(canvas2Data, 0, 0); // at coords 0,0 // draw author infomation this.ctx.fillStyle = "red"; this.ctx.font = "24px Times New Roman"; this.ctx.fillText("HTML5 Demo - by gloomyfish ", 50, 60); } }; }(); // end of app Ext.onReady(function(){ Test.app.init(); Test.app.onDraw() // alert('ext.onready') }); // Ext.onReady(Test.app.init, Test.app);
一定要有ExtJS的库文件支持!!!
本文出自 “流浪的鱼” 博客,请务必保留此出处http://gloomyfish.blog.51cto.com/8837804/1400368
相关文章推荐
- ExtJS中运用HTML5 Canvas简单例子
- ExtJS中运用HTML5 Canvas简单例子
- Html5 canvas 简单画布画板涂鸦例子
- html5中的canvas属性一些简单例子
- Html5 Canvas一个简单的画笔例子
- HTML5 Canvas 碰撞检测的简单实现
- html5 canvas 实现一个简单的叮当猫头部
- 自己写的HTML5 canvas动画制作函数,非常简单易懂
- 玩转 html5 (二) ---- 用 canvas 结合脚本在画布上画简单的图 (html5 又一强大功能)
- html5的几个简单例子
- 【Bugly干货分享】一起用 HTML5 Canvas 做一个简单又骚气的粒子引擎
- HTML5画布Canvas线段、矩形、弧形及贝塞尔曲线等简单图形绘制
- Extjs中加载异步树的最简单例子实现
- HTML5 画的简单走势图例子
- [Web Chart系列之一(续)]Web端图形绘制SVG,VML, HTML5 Canvas 简单实例
- 如何开发一个简单的HTML5 Canvas 小游戏
- HTML5 Canvas 练习(简单时钟)
- 怎样用HTML5 Canvas制作一个简单的游戏
- [Web Chart系列之一(续)]Web端图形绘制SVG,VML, HTML5 Canvas 简单实例
- 使用html5 canvas绘制简单图形小作品~灰太狼