Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 09-21-2006, 07:36 PM   #1
pet-theory
Registered User
 
Join Date: May 2006
Posts: 25
Default scaling noise

I'd like to scale a bitmap that is never seen but used in order to create an effect.

Basically, I'd like noise, but a more pixelated, blockier noise than a per-pixel noise. So I need to noise-up a bitmapdata, then magnify it.

Well, bitmapData's aren't displayObjects, so they don't have scaleX and scaleY properties. And their width and height propertes are read-only. So how to scale up a texture bitmap, then?

All I can come up with so far is to try to get the bitmapData to draw part of itself (with a clipping matrix half its size, and a transform matrix that doubles that).

Code:
package
{
	
	import flash.geom.*;
	import flash.display.*;

	//
	public class Test extends Sprite
	{ 
		public function Test() {
			//make bitmapdata
			var bdata=new BitmapData(100, 100)
			bdata.noise(Math.random()*1000, 0, 255, 1)
			//make matrix
			var mtr=new Matrix()
			var scaleFactor=2;
			mtr.scale(scaleFactor,scaleFactor);
			//apply it to the bitmapdata
			bdata.draw(bdata, mtr, null, null, new Rectangle(0,0, bdata.width/scaleFactor, bdata.height/scaleFactor));
			//display it
			var bitmap=new Bitmap(bdata)
			bitmap.x=200;
			bitmap.y=200;
			addChild(bitmap);
		}
	
	}

}
The result some weird distortion that I can't explain.

I suppose I could blit it, scale it, and draw it, but I'm sure there is an easier way.

Thanks.
pet-theory is offline   Reply With Quote
Old 09-21-2006, 09:10 PM   #2
pet-theory
Registered User
 
Join Date: May 2006
Posts: 25
Default workaround to scaling noise

I can scale noise by putting a noised bitmapData into a bitmap, then scaling the bitmap, then drawing the bitmap, like this:

Code:
package
{
	import flash.geom.*;
	import flash.display.*;
	//
	public class Test extends Sprite
	{ 
		public function Test() {
			//make original bitmapdata to pixelate
			var bdata=new BitmapData(100, 100)
			bdata.noise(Math.random()*1000, 0, 255, 1)
			//do a virtual "blit" so bdata can be scaled
			var bitmap=new Bitmap(bdata);
			var scaleFactor=5;
			bitmap.scaleX=bitmap.scaleY=scaleFactor;
			//create bitmapdata another that copies the first, but at scaled size
			var bdata2=new BitmapData(100, 100)
			bdata2.draw(bitmap, bitmap.transform.matrix);
			//put it on screen
			addChild(new Bitmap(bdata2));
			//bdata.draw(bitmap, bitmap.transform.matrix);
			//bitmap.scaleX=bitmap.scaleY=1/scaleFactor;
			//addChild(bitmap);
		}
	
	}

}
but still, it seems like something I should be able to do in 1 line, not three or four...

if I try to make do (the last three lines, commented out) with one bitmapdata that a) is noised, and b) is the basis for the bitmap, AND c) draws the same scaled bitmap, I get the same weird distortion that I got before.

I don't know why a bitmapData drawing a Bitmap which is based on the bitmap should be a problem...but self-drawing does not work in this try or the last.
pet-theory is offline   Reply With Quote
Old 09-25-2006, 07:00 AM   #3
jsebrech
Joeri Sebrechts
 
Join Date: Apr 2005
Location: Antwerp, Belgium
Posts: 1,465
Default

How about attaching the bitmapdata to a movieclip, and scaling the movieclip?
jsebrech is offline   Reply With Quote
Old 09-25-2006, 06:33 PM   #4
pet-theory
Registered User
 
Join Date: May 2006
Posts: 25
Default yes, that's what I've done

...in my last post.

But in AS3 terms, not AS2.

In AS3, movieclips are one among many DisplayObjects, which have movieclip-like properties (scaling, position, etc--most everything but frames, which are the speciality of movieclips). So I put the BitmapData into a Bitmap (a DisplayObject) to scale it, then took a snapshot of it using BitmapData's draw.
pet-theory is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scaling vs. non scaling of loaded clips Joshua7 ActionScript 2.0 3 07-07-2006 02:06 AM
Scaling Bounding Box iliketheska JSFL - Extending Flash 4 03-21-2006 04:53 PM
Scaling question maxx ActionScript 2.0 0 10-19-2005 06:48 PM
HTML and/or ActionScript in error re scaling stage? jonanaimo ActionScript 2.0 0 06-01-2005 08:16 PM
achieve scaling after scaling zumpner ActionScript 1.0 (and below) 12 01-04-2005 06:01 AM


All times are GMT. The time now is 05:13 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.