Draw Stars 星型を描きます。三角関数の勉強用。 satrex forked:0favorite:0lines:52license : MIT License modified : 2011-03-17 11:24:44 Embed Tweet package { import flash.display.AVM1Movie; import flash.geom.Point; import flash.ui.Mouse; import flash.display.Sprite; public class FlashTest extends Sprite { public function FlashTest() { // write as3 code here.. this.drawStyledStar(200, 50, 100); this.drawStyledStar(400, 150, 50); } private function drawStyledStar(x:Number, y:Number, width:Number) { this.drawStarWith(x,y, width,20,0x000000); this.drawStarWith(x,y, width,10,0x0000ff); this.drawStarWith(x,y, width,2,0x00ff00); } private function drawStarWith(x:Number, y:Number, width:Number, lineB:Number, lineC:Number):void{ graphics.lineStyle(lineB, lineC); drawStar(x,y,width); } private function drawStar(x:Number, y:Number, width:Number):void { var d:Number = Math.PI / 180; graphics.moveTo(x,y); var rightBottomX:Number = x + Math.sin(18 * d) * width; var rightBottomY:Number = y + Math.cos(18 * d) * width; var rightBottom:Point = new Point(); rightBottom.x = x + Math.sin(18 * d) * width; rightBottom.y = y + Math.cos(18 * d) * width; var leftBottom:Point = new Point(); leftBottom.x = x - Math.sin(18 * d) * width; leftBottom.y = y + Math.cos(18 * d) * width; var rightShoulder:Point = new Point(); rightShoulder.x = leftBottom.x + Math.sin((36 + 18) * d) * width ; rightShoulder.y = leftBottom.y - Math.cos((36 + 18) * d) * width; var leftShoulder:Point = new Point(); leftShoulder.x = rightBottom.x - Math.sin((36 + 18) * d) * width; leftShoulder.y = rightBottom.y - Math.cos((36 + 18) * d) * width; graphics.lineTo(rightBottom.x ,rightBottom.y); graphics.lineTo(leftShoulder.x, leftShoulder.y); graphics.lineTo(rightShoulder.x, rightShoulder.y); graphics.lineTo(leftBottom.x ,leftBottom.y); graphics.lineTo(x,y); // graphics.lineTo(x + Math.cos(d / 2) * width ,y + Math.sin(s / 2) * width); //graphics.lineTo(x,y); } } } class Point{ public function Point() { } public var x:Number; public var y:Number; } Code Fullscreen Preview Fullscreen ブラウザで無料ではじめるas3 P.28 by satrex at 2011/03/06 09:15:04 Study width Point Math.cos Math.sin Math.PI Sprite Number