[心得] BitmapData PerlinNoise 效果调试

今天看看了BitmapData的perlinNoise参数比较多,为了更好的理解各个参数的意义所以就写了个简单调试的例子,
以下是源码,有兴趣的可以看下。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx"
                           width="740" height="450"
                           creationComplete="callLater(init)">
        <fx:Script>
                <![CDATA[
                        private var bitmapData:BitmapData;
                        private var bitmap:Bitmap;
                        private function init():void{
                                bitmapData = new BitmapData(400,448);
                                bitmap = new Bitmap(bitmapData);
                                content.addChild(bitmap);
                                changeBitmap();
                        }
                        public function changeBitmap():void{
                                var channelOptions:uint=0;
                                if(red.selected){
                                        channelOptions = BitmapDataChannel.RED;
                                }
                                if(blue.selected){
                                        if(channelOptions != 0)
                                                channelOptions = channelOptions | BitmapDataChannel.BLUE;
                                        else
                                                channelOptions = BitmapDataChannel.BLUE;
                                }
                                if(green.selected){
                                        if(channelOptions != 0)
                                                channelOptions = channelOptions | BitmapDataChannel.GREEN;
                                        else
                                                channelOptions = BitmapDataChannel.GREEN;
                                }
                                if(alphas.selected){
                                        if(channelOptions != 0)
                                                channelOptions = channelOptions | BitmapDataChannel.ALPHA;
                                        else
                                                channelOptions = BitmapDataChannel.ALPHA;
                                }
                                var offset:Array;
                                if(useOffset.selected && textArea.text !=''){
                                        offset = [];
                                        var arr:Array = textArea.text.split("|");
                                        for(var i:int=0;i<arr.length;i++){
                                                if(arr[i]!=''){
                                                        var s:Array = arr[i].split(',');
                                                        var point:Point=new Point();
                                                        point.x=s[0];
                                                        point.y=s.length==2?s[1]:0;
                                                        offset.push(point);
                                                } 
                                        }
                                }
                                bitmapData.perlinNoise(400,448,numOctaves.value,randomSeed.value,stitch.selected,fractalNoise.selected,channelOptions,grayScale.selected,offset);
                        }
                ]]>
        </fx:Script>        
        <s:HGroup width="740" height="450">
                <mx:UIComponent id="content" width="400" height="448"/>
                <s:Form width="334" height="448" backgroundColor="0xcccccc">
                        <s:FormItem label="numOctaves">
                                <s:HSlider id="numOctaves" value="6" change="changeBitmap()" maximum="20" minimum="0"/>
                        </s:FormItem>
                        <s:FormItem label="randomSeed">
                                <s:HSlider id="randomSeed" value="10" change="changeBitmap()" maximum="100" minimum="0"/>
                        </s:FormItem>
                        <s:FormItem label="stitch">
                                <s:CheckBox id="stitch" selected="true" click="changeBitmap()"/>
                        </s:FormItem>
                        <s:FormItem label="fractalNoise"> 
                                <s:CheckBox id="fractalNoise"  selected="true" click="changeBitmap()"/>
                        </s:FormItem>
                        <s:FormItem label="channelOptions">
                                <s:CheckBox id="red" label="red" selected="true" click="changeBitmap()"/>
                                <s:CheckBox id="green" label="green" selected="true" click="changeBitmap()"/>
                                <s:CheckBox id="blue" label="blue" click="changeBitmap()"/>
                                <s:CheckBox id="alphas" label="alpha" click="changeBitmap()"/>
                        </s:FormItem>
                        <s:FormItem label="grayScale">
                                <s:CheckBox id="grayScale" click="changeBitmap()"/>
                        </s:FormItem>
                        <s:FormItem label="userOffset">
                                <s:CheckBox id="useOffset" selected="true" click="changeBitmap()"/>
                                <s:TextArea id="textArea" text="0,10|0,20" restrict="0-9|," 
                                                        change="changeBitmap()" height="50" enabled="{useOffset.selected}"/>
                        </s:FormItem>
                </s:Form>
        </s:HGroup>
</s:Application>

你可能感兴趣的:(xml)