{"id":247,"date":"2009-04-09T09:32:59","date_gmt":"2009-04-09T16:32:59","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1134"},"modified":"2009-04-09T09:32:59","modified_gmt":"2009-04-09T16:32:59","slug":"supershapes-superformula","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=247","title":{"rendered":"Supershapes \/ Superformula"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ Superformula (equations from):\r\n\/\/ http:\/\/www.geniaal.be\/downloads\/AMJBOT.pdf\r\n\/\/ http:\/\/en.wikipedia.org\/wiki\/Superformula\r\nconst TWO_PI:Number = Math.PI * 2;\r\nfunction superShape(a:Number, b:Number, m:Number, n1:Number, n2:Number, n3:Number, pnt:Point, scale:Number):void{\r\n\tvar r:Number = 0\r\n\tvar p:Number = 0;\r\n\tvar xp:Number = 0, yp:Number = 0;\r\n\twhile(p &lt;= TWO_PI){\r\n\t\tvar ang:Number = m * p \/ 4;\r\n\t\twith(Math){\r\n\t\t\tr = pow(pow(abs(cos(ang) \/ a), n2) + pow(abs(sin(ang) \/ b), n3),-1\/n1);\r\n\t\t\txp = r * cos(p);\r\n\t\t\typ = r * sin(p);\r\n\t\t}\r\n\t\tp += .01;\r\n\t\tcanvas.setPixel(pnt.x + xp *scale, pnt.y + yp * scale,  0xFFFFFF);\r\n\t }\r\n}\r\n\/\/ test it out:\r\nvar canvas:BitmapData = new BitmapData(700,600,false, 0x000000);\r\naddChild(new Bitmap(canvas, &quot;auto&quot;, true));\r\n \r\nsuperShape(1, 1, 5, 23, 23, 23, new Point(100,80), 30);\r\nsuperShape(1, 1, 5, 13, 13, 3, new Point(200,80), 30);\r\nsuperShape(1, 1, 8, 3, 13, 3, new Point(300,80), 30);\r\nsuperShape(10,8, 16, 30, 13, 3, new Point(450,80), 30);\r\nsuperShape(1,1, 1, .5, .5, .5, new Point(100,190), 100);\r\n\r\nfor (var i:int = 0; i &lt;150; i++){\r\n  superShape(1,1, 2, 1+i\/800, 4, 8-i * .1, new Point(550,350), 50);\r\n}\r\nfor (i = 0; i &lt;20; i++){\r\n  superShape(1.1,1.2, 6, 2 + i , 4, 9 - i, new Point(200,350), 50);\r\n}\r\n<\/pre>\n<p>The above snippet demos a function that will draw Supershapes using the Superformula&#8230;<\/p>\n<p>From wikipedia:<br \/>\n<em><strong>The Superformula appeared in a work by Johan Gielis. It was obtained by generalizing the superellipse, named and popularized by Piet Hein&#8230;<\/strong><\/em><\/p>\n<p>Here is the result of the above code:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/superformula.gif\" \/><br \/>\nYou can read more about the Superformula <a href=\"http:\/\/www.geniaal.be\/downloads\/AMJBOT.pdf\" target=\"blank\">here in the original paper by Gielis<\/a>.<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Superformula\" target=\"blank\">wikipedia entry&#8230;<\/a><\/p>\n<p><a href=\"http:\/\/local.wasp.uwa.edu.au\/~pbourke\/geometry\/supershape3d\/\" target=\"blank\">3d Supershapes by Paul Bourke<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ Superformula (equations from): \/\/ http:\/\/www.geniaal.be\/downloads\/AMJBOT.pdf \/\/ http:\/\/en.wikipedia.org\/wiki\/Superformula const TWO_PI:Number = Math.PI * 2; function superShape(a:Number, b:Number, m:Number, n1:Number, n2:Number, n3:Number, pnt:Point, scale:Number):void{ var r:Number = 0 var p:Number = 0; var xp:Number = 0, yp:Number = 0; while(p &lt;= TWO_PI){ var ang:Number = m * p \/ 4; with(Math){ r = pow(pow(abs(cos(ang) \/ a), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114,121,94,26],"tags":[3,4],"class_list":["post-247","post","type-post","status-publish","format-standard","hentry","category-graphics-algorithms","category-math","category-misc","category-setpixel","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/247","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=247"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/247\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}