graphic绘制闭合曲线问题,以及绘制环形图形
2016-05-17 19:31
519 查看
graphic绘制超过180度的闭合图形时,当有控件与其发生重叠,其闭合区间会发生变化,变成闭合图形减去重叠的部分,所以绘制大于180度的闭合图形时,要分两步绘制。充分利用余角,正弦,余弦
//画圆环进度条
public static drawRingProBar(shape: egret.Shape,angle: number,radius: number,color?:number): void {
if(shape && angle > 0) {
var coangle = Math.PI / 2 - angle;
var bigGap: number = 5;
var smallgap: number = 25;
var bigRadius: number = radius + bigGap;
var smallRadis: number = radius - smallgap;
var beginAngle: number = -Math.PI / 2;
var endAngle: number = angle - Math.PI / 2;
var halfAngle:number = Math.PI /2;
var color = color ? color : 0xFED655;
shape.graphics.clear();
shape.graphics.lineStyle(3,color);
shape.graphics.beginFill(color,1);
if(angle <= Math.PI){
shape.graphics.moveTo(radius,smallgap);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,endAngle,false);
shape.graphics.lineTo(Math.cos(coangle) * smallRadis + radius,radius - Math.sin(coangle) * smallRadis);
shape.graphics.drawArc(radius,radius,smallRadis,endAngle,beginAngle,true);
}else{
shape.graphics.moveTo(radius,smallgap);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,halfAngle,false);
shape.graphics.lineTo(radius,radius*2);
shape.graphics.drawArc(radius,radius,smallRadis,halfAngle,beginAngle,true);
shape.graphics.moveTo(radius,radius*2-smallgap);
shape.graphics.lineTo(radius,radius * 2+bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,halfAngle,endAngle,false);
shape.graphics.lineTo(Math.cos(coangle) * smallRadis + radius,radius - Math.sin(coangle) * smallRadis);
shape.graphics.drawArc(radius,radius,smallRadis,endAngle,halfAngle,true);
}
shape.graphics.endFill();
}
}
//画扇形
public static drawFanChart(shape: egret.Shape,angle: number,radius: number,color?: number):void{
if(shape && angle > 0) {
var coangle = Math.PI / 2 - angle;
var bigGap: number = 5;
var smallgap: number = 25;
var bigRadius: number = radius + bigGap;
var smallRadis: number = radius - smallgap;
var beginAngle: number = -Math.PI / 2;
var endAngle: number = angle - Math.PI / 2;
var halfAngle: number = Math.PI / 2;
var color = color ? color : 0xFED655;
shape.graphics.clear();
shape.graphics.lineStyle(3,color);
shape.graphics.beginFill(color,1);
if(angle <= Math.PI){
shape.graphics.moveTo(radius,radius);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,endAngle,false);
shape.graphics.lineTo(radius,radius);
}
else{
shape.graphics.moveTo(radius,radius);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,halfAngle,false);
shape.graphics.lineTo(radius,radius);
shape.graphics.moveTo(radius,radius);
shape.graphics.lineTo(radius,radius*2+bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,halfAngle,endAngle,false);
shape.graphics.lineTo(radius,radius);
}
shape.graphics.endFill();
}
}
//画圆环进度条
public static drawRingProBar(shape: egret.Shape,angle: number,radius: number,color?:number): void {
if(shape && angle > 0) {
var coangle = Math.PI / 2 - angle;
var bigGap: number = 5;
var smallgap: number = 25;
var bigRadius: number = radius + bigGap;
var smallRadis: number = radius - smallgap;
var beginAngle: number = -Math.PI / 2;
var endAngle: number = angle - Math.PI / 2;
var halfAngle:number = Math.PI /2;
var color = color ? color : 0xFED655;
shape.graphics.clear();
shape.graphics.lineStyle(3,color);
shape.graphics.beginFill(color,1);
if(angle <= Math.PI){
shape.graphics.moveTo(radius,smallgap);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,endAngle,false);
shape.graphics.lineTo(Math.cos(coangle) * smallRadis + radius,radius - Math.sin(coangle) * smallRadis);
shape.graphics.drawArc(radius,radius,smallRadis,endAngle,beginAngle,true);
}else{
shape.graphics.moveTo(radius,smallgap);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,halfAngle,false);
shape.graphics.lineTo(radius,radius*2);
shape.graphics.drawArc(radius,radius,smallRadis,halfAngle,beginAngle,true);
shape.graphics.moveTo(radius,radius*2-smallgap);
shape.graphics.lineTo(radius,radius * 2+bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,halfAngle,endAngle,false);
shape.graphics.lineTo(Math.cos(coangle) * smallRadis + radius,radius - Math.sin(coangle) * smallRadis);
shape.graphics.drawArc(radius,radius,smallRadis,endAngle,halfAngle,true);
}
shape.graphics.endFill();
}
}
//画扇形
public static drawFanChart(shape: egret.Shape,angle: number,radius: number,color?: number):void{
if(shape && angle > 0) {
var coangle = Math.PI / 2 - angle;
var bigGap: number = 5;
var smallgap: number = 25;
var bigRadius: number = radius + bigGap;
var smallRadis: number = radius - smallgap;
var beginAngle: number = -Math.PI / 2;
var endAngle: number = angle - Math.PI / 2;
var halfAngle: number = Math.PI / 2;
var color = color ? color : 0xFED655;
shape.graphics.clear();
shape.graphics.lineStyle(3,color);
shape.graphics.beginFill(color,1);
if(angle <= Math.PI){
shape.graphics.moveTo(radius,radius);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,endAngle,false);
shape.graphics.lineTo(radius,radius);
}
else{
shape.graphics.moveTo(radius,radius);
shape.graphics.lineTo(radius,-bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,beginAngle,halfAngle,false);
shape.graphics.lineTo(radius,radius);
shape.graphics.moveTo(radius,radius);
shape.graphics.lineTo(radius,radius*2+bigGap);
shape.graphics.drawArc(radius,radius,bigRadius,halfAngle,endAngle,false);
shape.graphics.lineTo(radius,radius);
}
shape.graphics.endFill();
}
}
相关文章推荐
- flex 控件的重要属性
- Delphi控件ListView的属性及使用方法详解
- web下载的ActiveX控件自动更新
- WinForm实现按名称递归查找控件的方法
- C#中父窗口和子窗口之间控件互操作实例
- Android编程之Button控件用法实例分析
- Android控件之CheckBox、RadioButton用法实例分析
- 在Android开发中使用自定义组合控件的例子
- Android重写View实现全新的控件
- MFC中动态创建控件以及事件响应实现方法
- WinForm自定义函数FindControl实现按名称查找控件
- C#实现图形位置组合转换的方法
- Android控件之ProgressBar用法实例分析
- WinForm拖拽控件生成副本的解决方法
- ASP.NET动态添加用户控件的方法
- C#实现判断图形文件格式的方法
- ASP.NET的HtmlForm控件学习及Post与Get的区别概述
- WinForm实现移除控件某个事件的方法
- C#实现图形路径变换的方法
- C#分屏控件用法实例