Gradient Tooth

Actionscript:
  1. var canvas:BitmapData=new BitmapData(400,400,false,0x000000);
  2. addChild(new Bitmap(canvas));
  3.  
  4. var a:Number=-1.21;
  5. var r:Rectangle=new Rectangle(0,0,3,5);
  6. var halfWidth:Number=canvas.width/2;
  7. var halfHeight:Number=canvas.height/2;
  8.  
  9. render();
  10.  
  11. function render():void{
  12.     for (var x:Number = -2; x<=2; x+=.01) {
  13.         for (var y:Number = -2; y<=2; y+=.02) {
  14.    
  15.             // equation from : http://en.wikipedia.org/wiki/Bicuspid_curve
  16.             //(x^2 - a^2) * (x - a)^2 + (y^2 - a^2) * (y^2 - a^2) = 0
  17.    
  18.             // unpoptimized:
  19.             // var e:Number = (x*x - a*a) * (x-a)*(x-a) + (y*y-a*a) * (y*y-a*a);  
  20.             // optimized:
  21.             var x_a:Number=x-a;
  22.             // factoring: x^2 - a^2 = (x + a) * (x - a)
  23.             var y2_a2:Number =  (y + a) * (y - a);
  24.             var e:Number = (x + a) * x_a * x_a *  x_a +  y2_a2 * y2_a2;
  25.              
  26.                 r.x=halfWidth+y*50;
  27.                 r.y=halfHeight-x*100;
  28.                 var col:Number = e * 50;
  29.                 if (col <10){
  30.                     col = Math.abs(col) + 70;
  31.                     canvas.fillRect(r, col <<16 | col <<8 | col );
  32.                 }
  33.         }
  34.     }
  35. }

This is a variation on a post from a little while back.... it plots a modified Bicuspid that resembles a tooth:

This entry was posted in Math, pixel manipulation, setPixel and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*