# Pixel random move question

**URL:** <https://forum.kirupa.com/t/pixel-random-move-question/185496>\
**Category:** Uncategorized\
**Created:** [April 13, 2006, 6:14pm UTC](https://forum.kirupa.com/t/pixel-random-move-question/185496 "2006-04-13T18:14:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aBnest](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abnest/32/2177_2.png) [@aBnest](https://forum.kirupa.com/u/aBnest)\
**Post date:** [April 13, 2006, 6:14pm UTC](https://forum.kirupa.com/t/pixel-random-move-question/185496/1 "2006-04-13T18:14:21Z")

</div>

Hello guys, i am trying to make a so called pixel effect in witch I want to make a shape only from pixels that are positioned in some random place on the stage. And all these pixels move to a certain point and create that shape.

I now this is a long shot for a newbe like me but i’m willing to learn.

So could somebody give me some clue on how to begin this. I’ve been looking into BitmapData Class but i don’t now if that is the best way to do it.

:ear:

---

<div class="post-metadata">

**Author:** ![rmo518](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@rmo518](https://forum.kirupa.com/u/rmo518)\
**Post date:** [April 14, 2006, 2:54am UTC](https://forum.kirupa.com/t/pixel-random-move-question/185496/2 "2006-04-14T02:54:08Z")

</div>

There is more than one way to do this of course. Here’s one way. It’s inspired by (although not identical to) Hack #2 in Sham Bhangal’s _Flash Hacks_, which you might want to check out if you can get a hold of it.

[AS]function move() {  
this.\_x += (-this.\_x+this.x)/this.speed;  
this.\_y += (-this.\_y+this.y)/this.speed;  
if (Math.abs(this.\_x - this.x)\<.5 && Math.abs(this.\_y - this.y)\<.5) {  
delete (this.onEnterFrame);  
}  
}  
pixelnum=0;  
for (i=shape.\_x; i\<shape.\_x+shape.\_width; i++) {  
for (j=shape.\_y; j\<shape.\_y+shape.\_height; j++) {  
if (shape.hitTest(i, j, true)) {  
clip = \_root.attachMovie(“pixel”, “pixel”+pixelnum, pixelnum);  
clip.x = i;  
clip.y = j;  
clip.speed = (Math.random()\*2)+2;  
clip.\_x = Math.random()\*Stage.width;  
clip.\_y = Math.random()\*Stage.height;  
pixelnum++  
}  
}  
}  
launcher = 0;  
queue = setInterval(launch, 5);  
function launch(){  
\_root[“pixel”+launcher].onEnterFrame = move;  
launcher++;  
if (launcher == pixelnum){  
clearInterval(queue);  
}  
}[/AS]

---

<div class="post-metadata">

**Author:** ![aBnest](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/abnest/32/2177_2.png) [@aBnest](https://forum.kirupa.com/u/aBnest)\
**Post date:** [April 14, 2006, 2:43pm UTC](https://forum.kirupa.com/t/pixel-random-move-question/185496/3 "2006-04-14T14:43:52Z")

</div>

thanks man! this will give me a head start !😃
