// Se mor! // www.semor.dk // Mads Buch Stage // 2007 package semor.graphics { import flash.display.DisplayObject; import flash.display.Graphics; import flash.display.Shape; import flash.display.Sprite; public class XmasHeart extends Sprite { public var size:Number = 220; public var stripes:Number = 5; public var color1:uint = 0x000000; public var color2:uint = 0xc0c0c0; private var centerX:Number = 0; private var centerY:Number = 0; private var stripeSize:Number = size / stripes; private var heartSide:Number = Math.sqrt((size * size)/2); public function init(_size:Number, _stripes:Number, _color1:uint, _color2:uint) { size = _size; stripes = _stripes; color1 = _color1; color2 = _color2; draw(); } public function draw() { stripeSize = size / stripes; heartSide = Math.sqrt((size * size)/2); drawCircle(centerX + (size * 0.25), centerY - (size * 0.75), heartSide / 2, color1); drawCircle(centerX - (size * 0.25), centerY - (size * 0.75), heartSide / 2, color2); drawBigBox(centerX,centerY,color1); for(var i = 0; i < stripes; i++) { var baseX:Number = centerX - ((stripeSize / 2) * i); var baseY:Number = centerY - ((stripeSize / 2) * i); //trace("x: " + baseX + ", y: " + baseY); for(var j = 0; j < stripes; j++) { var thisColor:uint; if(i % 2 == 0) { if(j % 2 != 0) { drawBox(baseX + ((stripeSize / 2) * j), baseY - ((stripeSize / 2) * j), color2); } } else { if(j % 2 == 0) { drawBox(baseX + ((stripeSize / 2) * j), baseY - ((stripeSize / 2) * j), color2); } } } } } public function XmasHeart() { } private function drawBox(startX:Number, startY:Number, startColor:uint):void { var child:Shape = new Shape(); child.graphics.beginFill(startColor); child.graphics.lineStyle(0, startColor); child.graphics.moveTo(startX,startY); child.graphics.lineTo(startX+(stripeSize / 2), startY - (stripeSize / 2)); child.graphics.lineTo(startX, startY - stripeSize); child.graphics.lineTo(startX-(stripeSize / 2), startY - (stripeSize / 2)); //child.graphics.drawRect(0, 0, size, size); child.graphics.endFill(); addChild(child); } private function drawBigBox(startX:Number, startY:Number, startColor:uint):void { var child:Shape = new Shape(); child.graphics.beginFill(startColor); child.graphics.lineStyle(0, startColor); child.graphics.moveTo(startX,startY); child.graphics.lineTo(startX+(size / 2), startY - (size / 2)); child.graphics.lineTo(startX, startY - size); child.graphics.lineTo(startX-(size / 2), startY - (size / 2)); //child.graphics.drawRect(0, 0, size, size); child.graphics.endFill(); addChild(child); } //drawBox(mainShape,centerX+(stripeSize/2),centerY - (stripeSize/2),heartColor2); private function drawCircle(startX:Number, startY:Number, startRadius:Number, startColor:uint):void { var child:Shape = new Shape(); child.graphics.beginFill(startColor); child.graphics.lineStyle(0, startColor); child.graphics.drawCircle(startX, startY, startRadius); child.graphics.endFill(); addChild(child); } } }