wonderwhy-ER on DeviantArthttps://www.deviantart.com/wonderwhy-er/art/BitmapData-example-51731762wonderwhy-ER

Deviation Actions

wonderwhy-ER's avatar

BitmapData example

By
Published:
924 Views

Description

swerno092 asked me to explain how bitmapData. I started to create small fla that creates bmp and fills it acording to some function. I played a little and wen to far :D
You will need to wait becouse it takes time to draw them.
If you have some questions then ask.
Here is the code. Just put it on the first frame.
//-----------------------------------------------------------
import flash.display.BitmapData;
var bmp:BitmapData = new BitmapData(Stage.width, Stage.height, true, 0xFF000000);
/*true means that it has alpha.
After that goes fill color of a bitmap. format is 0xAARRGGBB where AA is Alpha RR is red GG green and BB blue.
Color is in hex format. 00=0 10=16 FF=255 0A=10.
so 0xFFFF0000 is red while 0x00FF0000 is transperent. Then 0xFF000000 is black and 0xFFFFFFFF is white.
*/
_root.attachBitmap(bmp, -1);
//Now i imported bmp.
bmpSize = Stage.width*Stage.height; //number of pixels.
colorNumber = 255*255*255;//number of colors
d = colorNumber/bmpSize;// color value per pixe
//i define functions which convert x and y coordiantes to a number which will be used as a color for a pixel
function Sin(x, y) {
return 255*255*Math.sin(y*x*100);
}
function Sin2(x, y) {
return colorNumber*Math.sin(y*x/1000);
}
function sq(x, y) {
return x*y;
}
function sum(x, y) {
return x+y;
}
function rad(x, y) {
dx = Stage.width/2-x;
dy = Stage.height/2-y;
return dx*dx+dy*dy;
}
function mutant(x, y) {
return rad(sq(x, y), sum(x, y));
}
var functions:Array = new Array();//array of functions
index = 0;//current index of the function
var func:Function = Sin;//function which is used o determien coor for a pixel
functions.push(Sin);
functions.push(Sin2);
functions.push(sum);
functions.push(sq);
functions.push(rad);
functions.push(mutant);
function reDraw() {//function which is used to draw
for (x=0; x<Stage.width; x++) {//for each x
for (y=0; y<Stage.height; y++) {//for each y
f = 0xFF000000+func(x, y);//determien a color
bmp.setPixel32(x, y, f);//draw a pixel
}
}
}
reDraw();
onMouseDown = function () {//on mouse click change function
index++;
func = functions[index%functions.length];
reDraw();
};
//-----------------------------------------------------------
Image size
550x400px 26.89 KB
© 2007 - 2024 wonderwhy-ER
Comments9
Join the community to add your comment. Already a deviant? Log In
Melindryad's avatar
Thank-you so much for sharing this. I'm relatively new to Flash & I get kinda' muddled by the 'jargon'; :confused: you know- the .abc makes the flibberjibbitt cogitate when connected to a blitblob = it makes the email work. :dizzy: :frustrated:
So when you give me a term I can look up & examples like you have, I'm impressed.:clap: Thanks for continuing the total philosophy of "Community". :community: