# Flash, will you be my Valentines?

I refuse to celebrate a corporate holiday sponsored by the diamond industry and chocolate companies by purchasing a bunch of crap to further perpetuate the Valentine Industrial Complex. But that doesn’t mean I can’t celebrate in my own way by playing around with some trig and polar coordinates using Away3D to draw hearts in 3D space.

Here’s the simple version

 [kml_flashembed movie=”http://polygeek.com/flex/3512_Heart/_3512_SimpleHeart.swf” width=”550″ height=”700″ wmode=”normal” allowfullscreen=”true”/] view source

The Heart equation
Thanks to an anonymous submission at Mathworld.Wolfram.com I had the algebraic equation to work with without having to rediscover it on my own. Programmatically it looks like this:

```var r : Number =  2 - 2 * Math.sin( t ) +
Math.sin( t ) * Math.sqrt( Math.abs( Math.cos( t ) ) )
/ ( Math.sin( t ) + 7/5 );```

You can see that someone put it a lot of tweaking to get this just right.

Symbolically the equation looks like this:

Here’s the code for the loop that draws the dots.

```private function drawHeart():void {
for( var t:Number = 0; t < Math.PI * 2; t+= 0.01 ) {
var pixel : Sprite3D = makeParticle();
var r : Number =  2 - 2 * Math.sin( t ) +
Math.sin( t ) * Math.sqrt( Math.abs( Math.cos( t ) ) )
/ ( Math.sin( t ) + 7/5 );
// multiply by 80 to spread out the dots.
pixel.x = r * 80 * Math.cos( t );
pixel.y = r * 80 * Math.sin( t );
}
}```

Here’s a version that draws hearts in a heart patterns.

 [kml_flashembed movie=”http://polygeek.com/flex/3512_Heart/_3512_ComplexHeart.swf” width=”550″ height=”700″ wmode=”normal” allowfullscreen=”true”/] view source

I kept the heart count down in the example above so that the rotations wouldn’t be too chunky. ( Is Molehill out yet? I want it now, Now, NOW! )

I’m not sure why it looks like part of the heart slides into a shadow when it rotates to certain angels. I didn’t do that in Chrome when I was working on it.

Below are a few screen captures using many more hearts.

## 6 thoughts on “Flash, will you be my Valentines?”

1. Abraham says:

Pretty cool. Mathworld, nice resource :D

2. hippygeek says:

Thank you sweetheart!

1. @hippygeek It’s the least I can do. :-) Did you like the “Valentines Industrial Complex” comment? Huh? I thought that was pretty funny.

3. RobSmith says:

Your algebraic equation is going to blast the Valentine Industrial Complex onto their backsides! Happy Valentine's Day and nice work!