flex绘制菱形

package com
{
	import mx.core.UIComponent;
	
	public class Draw extends UIComponent
	{
		private var WIDTH:int=60;
		private var HEIGHT:int=30;
		public function Draw()
		{
			
			drowOne();//绘制一个菱形
			drow();//绘制多行多列菱形
		}
		public function init():void{
			
		}
		/**
		 * 	绘制20行40列 800个菱形
		 *  
		 * **/
		public function drow():void{
			var h:int=HEIGHT/2;
			var w:int=WIDTH/2;
			for(var j:int=0;j<20;j++){
				for(var i:int=0;i<40;i++){
					trace("helloWorld");
					this.graphics.moveTo(i*WIDTH,HEIGHT*j+h);
					this.graphics.lineStyle(1,0x52432);
					this.graphics.lineTo(WIDTH*i+w,HEIGHT*j);
					this.graphics.lineTo(WIDTH*(i+1),HEIGHT*j+h);
					this.graphics.lineTo(WIDTH*i+w,HEIGHT*(j+1));
					this.graphics.lineTo(i*WIDTH,HEIGHT*j+h);
					this.graphics.endFill();
			
				}
			}
		}
	//绘制一行 10个菱形
//		public function drow():void{
//			var height:int=HEIGHT/2;
//			var width:int=WIDTH/2;
//			for(var i:int=0;i<10;i++){
//				this.graphics.moveTo(i*WIDTH,height);
//				this.graphics.lineStyle(1,0x52432);
//				this.graphics.lineTo(WIDTH*i+WIDTH/2,0);
//				this.graphics.lineTo(WIDTH*(i+1),HEIGHT/2);
//				this.graphics.lineTo(WIDTH*i+WIDTH/2,HEIGHT);
//				this.graphics.lineTo(i*WIDTH,height);
//				this.graphics.endFill();
//			}
//			
//		}
		/**
		 * 绘制一个 菱形,看成个长方体,取各边的中点连起来
		 * 我的方法是 左边中点--->上边中点--->右边中点----->下边中点---->左边中点
		 * 
		 * */
		public function drowOne():void{
			var height:int=400;
			var width:int=800;
			this.graphics.beginFill(0x82145);
			this.graphics.moveTo(200,300);//移动到某个点 (左边的中点)
			this.graphics.lineStyle(1);
			this.graphics.lineTo(200+width/2,300-height/2);//移动到上边中点
			this.graphics.lineTo(200+width,300);//移动到右边中点
			this.graphics.lineTo(200+width/2,300+height/2);//下边的重点
			this.graphics.lineTo(200,300);//移动到起始点
			this.graphics.endFill();
		}
		
		
	}
}

 

你可能感兴趣的:(Flex,J#)