本文主要包含Html5,画板,涂鸦板等相关知识,佚名 希望在学习及工作中可以帮助到您
最近了解到html5强大的绘图功能让我惊奇,于是,写了个小玩意---涂鸦板,能实现功能有:画画,改色,调整画笔大小
html5的绘图可以分为点,线,面,圆,图片等,点和线,这可是所有平面效果的基点,有了这两个东西,没有画不出来的东西,只有想不到的算法。
先上代码了:
html- <body style="cursor:pointer">
- <canvas id="mycavas" width="1024" height="400" style="border:solid 4px #000000"></canvas><!--画布-->
- <input type="color" id="color1" name="color1"/><!--设色器-->
- <output name="a" for="color1" onforminput="innerHTML=color1.value"></output>
- <input type="range" name="points" id="size" min="5" max="20" /><!--拖动条-->
- </body>
效果:
好了,一个简陋的画图界面就搞好啦,下面开始写一些画线的代码
- $.Draw = {};
- $.extend($.Draw, {
- D2: "",
- CX:"",
- Box: "mycavas",//画布id
- BoxObj:function(){//画布对象
- this.CX=document.getElementById(this.Box);
- },
- D2:function(){//2d绘图对象
- this.D2 = this.CX.getContext("2d");
- },
- Cricle: function (x, y, r, color) {//画圆
- if (this.D2) {
- this.D2.beginPath();
- this.D2.arc(x, y, r, 0, Math.PI * 2, true);
- this.D2.closePath();
- if (color) {
- this.D2.fillStyle = color;
- }
- this.D2.fill();
- }
- &nbs