3.1_文本的描边与填充
来源:互联网 发布:网狐gameengine源码 编辑:程序博客网 时间:2024/06/15 04:50
3.1_文本的描边与填充
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>文本的描边与填充</title> <style> body{ background: #eee; } #controls{ position: absolute; left: 60px; top: 25px; } #canvas{ background: #fff; cursor: pointer; margin-left: 10px; margin-top: 10px; box-shadow: 4px 4px 8px rgba(0,0,0,0.5); -webkit-box-shadow: 4px 4px 8px rgba(0,0,0,0.5); -moz-box-shadow: 4px 4px 8px rgba(0,0,0,0.5); } </style> </head> <body> <canvas id="canvas" width="600" height="400"></canvas> <div id="controls"> 描边:<input type="checkbox" id="strokeCheckbox" checked="true" /> 填充:<input type="checkbox" id="fillCheckbox" /> 阴影:<input type="checkbox" id="shadowCheckbox" /> </div> </body> <script> var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); var fillCheckbox = document.getElementById('fillCheckbox'); var strokeCheckbox = document.getElementById('strokeCheckbox'); var shadowCheckbox = document.getElementById('shadowCheckbox'); var text = 'HTML5'; //初始化 context.font = '128px palatino'; context.lineWidth = 1.0; context.fillStyle = 'cornflowerblue'; turnShadowsOn(); draw(); //开启阴影效果 function turnShadowsOn(){ context.shadowColor = 'rgba(0,0,0,0.8)'; context.shadowOffsetX = 5; context.shadowOffsetY = 5; context.shadowBlur = 10; } //关闭阴影效果 function turnShadowsOff(){ context.shadowColor = undefined; context.shadowOffsetX = 0; context.shadowOffsetY = 0; context.shadowBlur = 0; } //绘制文字 function draw(){ context.clearRect(0,0,canvas.width,canvas.height); drawBackground(); if(shadowCheckbox.checked){ turnShadowsOn(); }else{ turnShadowsOff(); } drawText(); } //绘制带横线的纸张 function drawBackground(){ context.save(); turnShadowsOff(); var step_y = 12; var top_margin = step_y*4; var left_margin = step_y*3; var i = canvas.height; //水平线 context.strokeStyle = 'lightgray'; context.lineWidth = 0.5; while(i>top_margin){ context.beginPath(); context.moveTo(0,i); context.lineTo(canvas.width,i); context.stroke(); i-=step_y; } //竖线 context.strokeStyle = 'rgba(100,0,0,0.3)'; context.lineWidth = 1; context.beginPath(); context.moveTo(left_margin,0); context.lineTo(left_margin,canvas.height); context.stroke(); context.restore(); } //绘制文本 function drawText(){ var text_x = 65; var text_y = canvas.height/2+35; context.strokeStyle = 'orange'; if(fillCheckbox.checked){ context.fillText(text,text_x,text_y); } if(strokeCheckbox.checked){ context.strokeText(text,text_x,text_y); } } //控件事件 fillCheckbox.onchange = draw; strokeCheckbox.onchange = draw; shadowCheckbox.onchange = draw; </script></html>
0 0
- 3.1_文本的描边与填充
- 2.6_路径描边与填充
- 6.2.1_描边与填充绘制器
- 6.2.1_描边与填充绘制器
- 6.2.1_描边与填充绘制器
- 3.1_使用渐变色及图案来填充文本
- canvas图像的描边与填充效果
- (zhuan)路径、描边与填充
- canvas路径,描边与填充
- 375_改变图片的填充颜色
- Word表格自动填充(简单序号的填充,复杂序号的填充,相同文本的填充)
- 字典的填充与查找
- android 常用到的shape属性(填充与描边)
- [Play with T]_[C# 类与属性操作] 通过克隆实现ObjectMap对List的填充
- HTML5 Canvas 填充与描边(Fill And Stroke)
- 画弧线填充描边与使用中心
- canvas画矩形之清除,描边与填充
- 让CStatic控件根据自己的需要改变,文本,文本颜色,填充背景色
- KEIL中无IAP或者STC芯片型号怎么办
- 卸载CentOS中的JDK:
- C语言两种for循环
- mysql建立MS,MM配置相关参数。
- 根据当前日期,获得本周的周一及周日日期即本周的开始时间和结束时间
- 3.1_文本的描边与填充
- Easy-35
- mysql中的日期类型
- oracle shrink space 与move
- js 将时间戳转成年月日时分秒格式
- QTableView和QTableWidget翻页功能实现---Qt学习笔记5
- 3.3.1_水平与垂直定位
- 新手初次安装caffe,cifar10训练过程初次体验(二)
- java中的自动拆箱、装箱是指什么?