A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Creating noise with two absolute colors

  1. #1
    Senior Member somlemeg's Avatar
    Join Date
    Aug 2000

    resolved [RESOLVED] Creating noise with two absolute colors

    How do I create noise with only two colors, that is green (00FF00) and red (FF0000). The noise should only consist of theese two colors, not the shades in between.
    I have created it in AS2 using a vector square, but this resulted in a very cpu heavy script.
    I have tried to use the noise and threshold, but I can't get the hold of it. Perhaps I need to draw one pixel at the time?

    Here is my current script:

    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.display.Graphics;
    	import flash.display.Bitmap;
    	import flash.display.BitmapData;
        import flash.display.BitmapDataChannel;
    	import flash.geom.Rectangle;
    	import flash.geom.Point;
    	public class StaticNoise extends Sprite
    		const ww = 480;
    		const hh = 272;
    		var bgdata:BitmapData = new BitmapData(ww,hh,false,0x00FF00);
    		var bg:Bitmap = new Bitmap(bgdata);
    		var zeroPt:Point = new Point(0,0);
    		var rect = new Rectangle(20, 20, 40, 40);
    		var threshold:uint =  hexToUint("000000");
    		var color:uint = hexToUint("00FF00");
    		var masker:uint = hexToUint("7E0000");
    		public function CreateStaticNoise()
    			addEventListener(Event.ENTER_FRAME, drawBaby);
    		function drawBaby(e:Event)
    			bgdata.noise(Math.random() * 1000, 0, 255, 1, false);
    			bgdata.threshold(bgdata, rect, zeroPt, ">", threshold, color, masker, true)
    		function hexToUint (colorString:String)
    			//colorString = colorString.substr(1,6); // result FFFFFF
    			var colorUint:uint = parseInt("0x" + colorString);
    			return colorUint;

  2. #2
    Senior Member somlemeg's Avatar
    Join Date
    Aug 2000
    I was able to solve it using threshold.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center