弹幕示例:绘画多边型
出自嗶哩嗶哩百科
目录 |
三角型
function createTriangle(g,width,height) { g.graphics.moveTo(width/2,0); g.graphics.lineTo(0,height); g.graphics.lineTo(width,height); g.graphics.lineTo(width/2,0); }
箭头
function createArrow(g,width,height,arrow_height) { var w=width/2; g.graphics.moveTo(w,0); g.graphics.lineTo(0,arrow_height); g.graphics.lineTo(width,arrow_height); g.graphics.lineTo(w,0); g.graphics.drawRect(w/2,arrow_height,w,height); }
空心圆
参数
- g:Shape - 创建的图型元件
- x:Number - 圆心 X
- y:Number - 圆心 Y
- r:Number - 外环半径
- mr:Number - 中空半径
function createHollowCircle(g,x,y,r,mr) { g.graphics.drawCircle(x,y,r); g.graphics.drawCircle(x,y,mr); }
示例
a=$.createShape({x:100,y:100}); a.graphics.beginFill(0xFF0000); createHollowCircle(a,0,0,100,90); a.graphics.endFill();
星型
参数
- g:Shape - 创建的图型元件
- x:Number - 圆心 X
- y:Number - 圆心 Y
- innerRadius:Number - 内环半径
- outerRadius:Number - 外环半径
- points:Number - 角数
- angel:Number - 起始角
function drawStar(g, x, y, innerRadius, outerRadius, points, angle ) { var count=Math.abs(points); if (count>=2) { var step=(Math.PI*2)/points; var halfStep=step/2; var start=(angle/180)*Math.PI; g.graphics.moveTo(x+(Math.cos(start)*outerRadius),y-(Math.sin(start)*outerRadius)); for (var i=1;i<=count*2;i++) { var radius = (i%2==0 ? outerRadius : innerRadius); g.graphics.lineTo(x+(Math.cos(start+(halfStep*i))*radius),y-(Math.sin(start+(halfStep*i))*radius)); } } }
示例
var fw=$.createShape({x:140,y:140,alpha:0.8}); fw.graphics.lineStyle(1, 33023, 1, false, "vertical","none", "miter", 10); drawStar(fw,10,10,20,50,5,0);