{"id":75,"date":"2008-10-30T00:03:27","date_gmt":"2008-10-30T07:03:27","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=28"},"modified":"2008-10-30T00:03:27","modified_gmt":"2008-10-30T07:03:27","slug":"setpixel-cubic-bezier","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=75","title":{"rendered":"setPixel() Cubic Bezier"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar canvas:BitmapData=new BitmapData(280,280,false,0x000000);\r\naddChild(new Bitmap(canvas, PixelSnapping.AUTO, true));\r\n\r\nvar color:uint;\r\n\r\n\/\/ anchor x1, anchor y1, \r\n\/\/ control-handle x2, control-handle y2, \r\n\/\/ anchor x3, anchor y3, control-handle x4, \r\n\/\/ control-handle y4, &#x5B;resolution incremental value between 0-1]\r\nfunction cubicBezier(x1:Number, y1:Number, x2:Number, y2:Number, \r\n\t                      x3:Number, y3:Number, x4:Number, y4:Number, resolution:Number=.03):void {\r\n\t\r\n\tvar b:Number,pre1:Number,pre2:Number,pre3:Number,pre4:Number;\r\n\tfor (var a = 0; a &lt; 1; a+=resolution) {\r\n\t\tb=1-a;\r\n\t\tpre1=(a*a*a);\r\n\t\tpre2=3*(a*a)*b;\r\n\t\tpre3=3*a*(b*b);\r\n\t\tpre4=(b*b*b);\r\n\t\tcanvas.setPixel(pre1*x1 + pre2*x2 + pre3*x4 + pre4*x3 ,\r\n\t\t\t\t         pre1*y1 + pre2*y2 + pre3*y4 + pre4*y3, color);\r\n\t}\r\n}\r\n\r\n\/\/ draw a few\r\n\r\ncolor = 0xFFFFFF;\r\n\r\ncubicBezier(100,100, \r\n                    150, 50, \r\n                    200, 100, \r\n                    150, 150);\r\n\r\ncolor = 0xFF0000;\r\n\r\ncubicBezier(10,10,\r\n                    150, 10,\r\n                    200, 200, \r\n                    250, 150,\r\n\t\t\t    .01);\r\n\/*\r\nWARNING: This code was written for fun. Use at your own risk.\r\n*\/\r\n<\/pre>\n<p>This draws cubic bezier curves with setPixel. I&#8217;m pretty sure I picked up the original math from somewhere on the processing forums in &#8217;03 or &#8217;04&#8230; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>var canvas:BitmapData=new BitmapData(280,280,false,0x000000); addChild(new Bitmap(canvas, PixelSnapping.AUTO, true)); var color:uint; \/\/ anchor x1, anchor y1, \/\/ control-handle x2, control-handle y2, \/\/ anchor x3, anchor y3, control-handle x4, \/\/ control-handle y4, &#x5B;resolution incremental value between 0-1] function cubicBezier(x1:Number, y1:Number, x2:Number, y2:Number, x3:Number, y3:Number, x4:Number, y4:Number, resolution:Number=.03):void { var b:Number,pre1:Number,pre2:Number,pre3:Number,pre4:Number; for (var a = 0; a &lt; 1; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,24,26],"tags":[31],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-bezier","category-bitmapdata","category-setpixel","tag-cubic-bezier"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/75","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=75"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}