{"id":268,"date":"2009-04-28T00:00:22","date_gmt":"2009-04-28T07:00:22","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1243"},"modified":"2009-04-28T00:00:22","modified_gmt":"2009-04-28T07:00:22","slug":"gradient-tooth","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=268","title":{"rendered":"Gradient Tooth"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar canvas:BitmapData=new BitmapData(400,400,false,0x000000);\r\naddChild(new Bitmap(canvas));\r\n\r\nvar a:Number=-1.21;\r\nvar r:Rectangle=new Rectangle(0,0,3,5);\r\nvar halfWidth:Number=canvas.width\/2;\r\nvar halfHeight:Number=canvas.height\/2;\r\n\r\nrender();\r\n\r\nfunction render():void{\r\n\tfor (var x:Number = -2; x&lt;=2; x+=.01) {\r\n\t\tfor (var y:Number = -2; y&lt;=2; y+=.02) {\r\n\t\r\n\t\t\t\/\/ equation from : http:\/\/en.wikipedia.org\/wiki\/Bicuspid_curve\r\n\t\t\t\/\/(x^2 - a^2) * (x - a)^2 + (y^2 - a^2) * (y^2 - a^2) = 0\r\n\t\r\n\t\t\t\/\/ unpoptimized:\r\n\t\t\t\/\/ var e:Number = (x*x - a*a) * (x-a)*(x-a) + (y*y-a*a) * (y*y-a*a);  \r\n\t\t\t\/\/ optimized:\r\n\t\t\tvar x_a:Number=x-a;\r\n\t\t\t\/\/ factoring: x^2 - a^2 = (x + a) * (x - a)\r\n\t\t\tvar y2_a2:Number =  (y + a) * (y - a);\r\n\t\t\tvar e:Number = (x + a) * x_a * x_a *  x_a +  y2_a2 * y2_a2;\r\n\t\t\t \r\n\t\t\t\tr.x=halfWidth+y*50;\r\n\t\t\t\tr.y=halfHeight-x*100;\r\n\t\t\t\tvar col:Number = e * 50;\r\n\t\t\t\tif (col &lt; 10){\r\n\t\t\t\t\tcol = Math.abs(col) + 70;\r\n\t\t\t\t    canvas.fillRect(r, col &lt;&lt; 16 | col &lt;&lt; 8 | col );\r\n\t\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>This is a variation on a post from a little while back&#8230;. it plots a modified Bicuspid that resembles a tooth:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/tooth_grad.gif\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var canvas:BitmapData=new BitmapData(400,400,false,0x000000); addChild(new Bitmap(canvas)); var a:Number=-1.21; var r:Rectangle=new Rectangle(0,0,3,5); var halfWidth:Number=canvas.width\/2; var halfHeight:Number=canvas.height\/2; render(); function render():void{ for (var x:Number = -2; x&lt;=2; x+=.01) { for (var y:Number = -2; y&lt;=2; y+=.02) { \/\/ equation from : http:\/\/en.wikipedia.org\/wiki\/Bicuspid_curve \/\/(x^2 &#8211; a^2) * (x &#8211; a)^2 + (y^2 &#8211; a^2) * (y^2 &#8211; a^2) = 0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121,25,26],"tags":[3,4],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-math","category-pixel-manipulation","category-setpixel","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}