【菜鸟日记】001 六边形(雷达图)画法

//雷达图(有锯齿)

drawRadarChart(sortArray,dataArray){
var drawDataArray=[100,100,100,100,100,100];//六边形半径
var mCenterX=pos.x;//中心点x,自己定义中心点
var mCenterY=posr.y;//中心点y
var mAngle = Math.PI * 2 / 6; //角度:Math.PI代表180°(不清楚的请百度),那么mAngle =60°,正好是六边形的夹角。
//算坐标,画图。canvas是左上角为原点,我这个是逆时针画法。
for(var i = 0; i < 6; i ++){
var x = mCenterX + Math.sin(mAngle * i)*drawDataArray[i]*1.5;
console.log(“sin+”+Math.sin(mAngle * i));
var y = -(mCenterY + Math.cos(mAngle * i)*drawDataArray[i]*1.5);//负号是因为需要镜像y坐标。
console.log(“cos+”+Math.cos(mAngle * i));
if(i==0){
this.graphics.moveTo(x, y);
}
else{
this.graphics.lineTo(x, y);
}
}
this.graphics.stroke();
this.graphics.lineWidth = 0.1;
this.graphics.strokeColor = cc.hexToColor(’#0000ff’);
this.graphics.strokeColor = cc.hexToColor(’#0000ff’);
this.graphics.fillColor =cc.color(100, 100,255,100);
this.graphics.fill();
},

1赞

吐槽一下,论坛对新手真是不太友好。

一言不合就贴代码,要博取关注,起码贴个效果图吧

re…贴个github,给个demo和效果图,说不定还能攒点赞

支持!!!!!

加个效果图出来

粘贴赋值就好了啊

就是这个样子 商业用还是差了不少 主要是有锯齿

画个2倍大的,然后scale到0.5试试呢

去试试