# Random shape tween

**URL:** <https://forum.kirupa.com/t/random-shape-tween/9501>\
**Category:** Uncategorized\
**Created:** [December 12, 2002, 11:40pm UTC](https://forum.kirupa.com/t/random-shape-tween/9501 "2002-12-12T23:40:03Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanwright](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ivanwright/32/119_2.png) [@ivanwright](https://forum.kirupa.com/u/ivanwright)\
**Post date:** [December 12, 2002, 11:40pm UTC](https://forum.kirupa.com/t/random-shape-tween/9501/1 "2002-12-12T23:40:03Z")

</div>

is there a script or method that would allow you to randomly shape tween a shape? in other words i would have no control over what shape the turns out to be?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2002, 11:53pm UTC](https://forum.kirupa.com/t/random-shape-tween/9501/2 "2002-12-12T23:53:06Z")

</div>

With a lot of math and the drawing API in MX, but well… you have to be really good at both of those to actually make it compose a final shape other than a square.

IMO. Maybe someone else knows an easier way.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 12:36am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/3 "2002-12-13T00:36:59Z")

</div>

Well, this is not so difficult, really. All you have to do is have a certain number of points move randomly, and then draw lines between the points. No math involved 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 12:38am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/4 "2002-12-13T00:38:33Z")

</div>

Yeah… for you it is easy… Mr. AS Master 😛

Picturing in my head it seems difficult, but I was assuming that he wanted actual shapes, like defined, instead of a random “mess”.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 12:40am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/5 "2002-12-13T00:40:59Z")

</div>

Pom that sounds really interesting, do you think you could throw together a lil fla? :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:04am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/6 "2002-12-13T02:04:24Z")

</div>

Here’s something I did for the bit contest. I cleaned the code a bit and I used curveTo but the idea is there:

```auto
/ ***Variables*** /
friction=.96;
nClip=10;
radius=100;

/ ***"Random elasticity" prototype inspired from Robert Penner*** /
MovieClip.prototype.effect=function(){
	this.centerX = _root._xmouse+this.centx;
	this.centerY = _root._ymouse+this.centy;
	if (!(this.loop=(++this.loop)%(5))) {
		this.brownX = (Math.random() - .5) * .35;
		this.brownY = (Math.random() - .5) * .35;}
	this.velX += (-.002 * (this._x - this.centerX)) + this.brownX;
	this.velY += (-.002 * (this._y - this.centerY)) + this.brownY;
	this._x += (this.velX *= friction);
	this._y += (this.velY *= friction);
};

/ ***I draw a dot to make it clearer*** /
_root.createEmptyMovieClip("ball",0);
ball.lineStyle(5,0,100);
ball.lineTo(0.15,0.45);

/ ***Duplicates and positions all dots in circle*** /
for (var p=0;p < nClip;p++){
	mc=ball.duplicateMovieClip("ball"+p,p+1);
	mc.centx=radius*Math.cos(p*Math.PI*2/nClip);
	mc.centy=radius*Math.sin(p*Math.PI*2/nClip);
	mc.onEnterFrame=effect;
}

/ ***Draws the fill*** /
_root.onEnterFrame=function(){
	mid=new Array();
	for (var j=0;j < nClip;j++){
		mid.push({x:(_root["ball"+j]._x+_root["ball"+(j+1)%nClip]._x)/2,y:(_root["ball"+j]._y+_root["ball"+(j+1)%nClip]._y)/2});
	}
	this.clear();
	this.lineStyle(1, 0, 100);
	this.beginFill(0x384862, 50);
	this.moveTo(mid[0].x, mid[0].y);
	for (j=1;j <= nClip;j++)
		this.curveTo(_root["ball"+j%nClip]._x, _root["ball"+j%nClip]._y, mid[j%nClip].x, mid[j%nClip].y);};

```

pom :crazy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:22am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/7 "2002-12-13T02:22:01Z")

</div>

With lines:

```auto
/ ***Variables*** /
friction=.96;
nClip=10;
radius=100;

/ ***"Random elasticity" prototype inspired from Robert Penner*** /
MovieClip.prototype.effect=function(){
	this.centerX = _root._xmouse+this.centx;
	this.centerY = _root._ymouse+this.centy;
	if (!(this.loop=(++this.loop)%(5))) {
		this.brownX = (Math.random() - .5) * .35;
		this.brownY = (Math.random() - .5) * .35;}
	this.velX += (-.002 * (this._x - this.centerX)) + this.brownX;
	this.velY += (-.002 * (this._y - this.centerY)) + this.brownY;
	this._x += (this.velX *= friction);
	this._y += (this.velY *= friction);
};

/ ***I draw a dot to make it clearer*** /
_root.createEmptyMovieClip("ball",0)._visible=0;
ball.lineStyle(5,0,100);
ball.lineTo(0.15,0.45);

/ ***Duplicates and positions all dots in circle*** /
myClips=new Array();
for (var p=0;p < nClip;p++){
	myClips[p]=ball.duplicateMovieClip("ball"+p,p+1);
	myClips[p].centx=radius*Math.cos(p*Math.PI*2/nClip);
	myClips[p].centy=radius*Math.sin(p*Math.PI*2/nClip);
	myClips[p].onEnterFrame=effect;
}

/ ***Draws the fill*** /
_root.onEnterFrame=function(){
	this.clear();
	this.lineStyle(1, 0, 100);
	this.beginFill(0x384862, 50);
	this.moveTo(myClips[0]._x, myClips[0]._y);
	for (j=1;j <= nClip;j++){
		this.lineTo(myClips[j%nClip]._x, myClips[j%nClip]._y);
	}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:24am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/8 "2002-12-13T02:24:32Z")

</div>

holy cr\*p, how on earth do you come up with code like this?! Tell me, I want to learn even if its going to take me a million yrs! :o

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:29am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/9 "2002-12-13T02:29:23Z")

</div>

It really looks harder than it actually is. If we look at it:  
[list][_]The effect prototype is the hardest part. If you’ve read the elesticity tute, you should recognize it easily, but the loop thinggy is a bit tricky. This is the part I borrowed from Robert Penner by the way. What it does is this: every 5 frames, Flash choses a random force for each clip, what is called brown in the code. This force is of course added to the elastic force to give vel[_]We put all our clips in an array to manipulate them more easily[\*]The main enterFrame runs through the array and draws a line between 2 consecutive clips.[/list]And voilà.

pom :crazy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:33am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/10 "2002-12-13T02:33:26Z")

</div>

That is amazing, I hope you don’t mind if I tinker with your code. I’m gonna try to see if I can make something different or add to it, but thanks a lot for the demonstration. I seriously need to cut back on designing a bit and concentrate more on coding. Thanks again. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:36am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/11 "2002-12-13T02:36:10Z")

</div>

Well thanks :beam:  
And please do whatever you like, I’d love to see what you’ll do with it. [SIZE=1]And you’re rigth, coding can be fun too. I’ve just bought myself Fresh Flash by the way…[/SIZE]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:41am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/12 "2002-12-13T02:41:37Z")

</div>

Woo, I like this one too:

```auto
/ ***Draws the fill*** /
depth=100;
_root.onEnterFrame=function(){
	var mc=this.createEmptyMovieClip("c"+(++depth),depth);
//	this.clear();
	mc.lineStyle(1, 0, 100);
	mc.beginFill(0x384862, 50);
	mc.moveTo(myClips[0]._x, myClips[0]._y);
	for (j=1;j <= nClip;j++){
		mc.lineTo(myClips[j%nClip]._x, myClips[j%nClip]._y);
	}
	mc.onEnterFrame=function(){
		this._alpha-=10;
		if (this._alpha <=0) this.removeMovieClip();
	}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 2:47am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/13 "2002-12-13T02:47:23Z")

</div>

lol that is awesome!! its like an onion skin effect!! I like that. 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 3:32am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/14 "2002-12-13T03:32:07Z")

</div>

Ilyas… you have no idea how much you make me want to cry.

1. Because your so good and I know it will take me a billion years before I reach your level ☹

2. Because your stuff is just soooo beautiful 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 4:05am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/15 "2002-12-13T04:05:09Z")

</div>

:crazy:  
i dont know whether to cream my pants or \*\*\*\* myself that is awesome

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 11:20am UTC](https://forum.kirupa.com/t/random-shape-tween/9501/16 "2002-12-13T11:20:18Z")

</div>

😛 :beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 4:54pm UTC](https://forum.kirupa.com/t/random-shape-tween/9501/17 "2002-12-13T16:54:38Z")

</div>

thanks! that’s awesome… it’s almost exactly what i was looking for! i want to try and get it stationary though instead of following the mouse around! thanks again!
