{"assets":[{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/001.png","local":"\/data\/posts\/2014\/11\/e0c56219f57f06f0102c7a99d555c337.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/0021.png","local":"\/data\/posts\/2014\/11\/0c67d27ee8ba3a38093253466b86e7bc.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/003.png","local":"\/data\/posts\/2014\/11\/6db065eb280d2193fc6d2ee51204767b.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/004.png","local":"\/data\/posts\/2014\/11\/ac21ba8d88ff6a07cefc17721242c263.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/005.png","local":"\/data\/posts\/2014\/11\/41e50e2cc49cc53947abac2044674dee.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/001.png","local":"\/data\/posts\/2014\/11\/e0c56219f57f06f0102c7a99d555c337.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/0021.png","local":"\/data\/posts\/2014\/11\/0c67d27ee8ba3a38093253466b86e7bc.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/003.png","local":"\/data\/posts\/2014\/11\/6db065eb280d2193fc6d2ee51204767b.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/004.png","local":"\/data\/posts\/2014\/11\/ac21ba8d88ff6a07cefc17721242c263.png"},{"original":"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/005.png","local":"\/data\/posts\/2014\/11\/41e50e2cc49cc53947abac2044674dee.png"}],"author_link":"author\/r2d2upgrade\/","author_name":"r2d2upgrade","cat":"LD #31","categories":["LD #31"],"comments":[],"epoch":1415681100,"event":"LD31","likes":20,"metadata":{"p_key":"82768","p_author":"r2d2upgrade","p_authorkey":"0","p_urlkey":"293500","p_title":"How to draw a Perfect Octagon!","p_cat":"LD #31","p_event":"LD31","p_time":"1415681100","p_likes":"20","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1417737600","event_key":"26","event_name":"LD31"},"source_url":"2014\/11\/11\/how-to-draw-a-perfect-octagon\/","text":"<p>I did some maths while I was bored, and I calculated a way to draw a perfect octagon.<br\/>\nI thought this might come in useful for some of you :3<\/p>\n<p><strong>Warning! Maths ahead!<\/strong><\/p>\n<p>\u00a0<\/p>\n<p><em><strong>Maths:<\/strong><\/em><\/p>\n<p>Imagine a square, with side length <strong>a<\/strong>.<\/p>\n<p><a href=\"\/data\/posts\/2014\/11\/e0c56219f57f06f0102c7a99d555c337.png\"><img alt=\"001\" class=\"alignnone size-full wp-image-397565\" height=\"94\" src=\"\/data\/posts\/2014\/11\/e0c56219f57f06f0102c7a99d555c337.png\" width=\"106\"\/><\/a><\/p>\n<p>Our octagon will fit in this square.<\/p>\n<p>We will call the length of a side of the octagon <strong>b<\/strong>.<\/p>\n<p><a href=\"\/data\/posts\/2014\/11\/0c67d27ee8ba3a38093253466b86e7bc.png\"><img alt=\"002\" class=\"alignnone size-full wp-image-397575\" height=\"95\" src=\"\/data\/posts\/2014\/11\/0c67d27ee8ba3a38093253466b86e7bc.png\" width=\"107\"\/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>Now you put <strong>a<\/strong> into this equation:<\/p>\n<p><a href=\"\/data\/posts\/2014\/11\/6db065eb280d2193fc6d2ee51204767b.png\"><img alt=\"003\" class=\"alignnone size-full wp-image-397567\" height=\"30\" src=\"\/data\/posts\/2014\/11\/6db065eb280d2193fc6d2ee51204767b.png\" width=\"62\"\/><\/a><\/p>\n<p>Which can also be written as:<\/p>\n<p><a href=\"\/data\/posts\/2014\/11\/ac21ba8d88ff6a07cefc17721242c263.png\"><img alt=\"004\" class=\"alignnone size-full wp-image-397568\" height=\"15\" src=\"\/data\/posts\/2014\/11\/ac21ba8d88ff6a07cefc17721242c263.png\" width=\"181\"\/><\/a><\/p>\n<p>And you get <strong>b<\/strong>.<\/p>\n<p>Now, round <strong>b<\/strong> to the nearest number. We can\u2019t be dealing with fractions of pixels now, can we?<\/p>\n<p>Now you have <strong>b<\/strong>, we can draw the octagon.<\/p>\n<p>\u00a0<\/p>\n<p><em><strong>Drawing:<\/strong><\/em><\/p>\n<p>For this example, our reference point will be in the center of the octagon, which is also the center of our imaginary square.<\/p>\n<p><a href=\"\/data\/posts\/2014\/11\/41e50e2cc49cc53947abac2044674dee.png\"><img alt=\"005\" class=\"alignnone size-full wp-image-397569\" height=\"94\" src=\"\/data\/posts\/2014\/11\/41e50e2cc49cc53947abac2044674dee.png\" width=\"94\"\/><\/a><\/p>\n<p>Our first 2 co-ordinates will be <strong>a\/2<\/strong> up and <strong>b\/2<\/strong> to either side.<\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/006.png\"><img alt=\"006\" class=\"alignnone size-full wp-image-397570\" height=\"94\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/006.png\" width=\"94\"\/><\/a><\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/007.png\"><img alt=\"007\" class=\"alignnone size-medium wp-image-397571\" height=\"94\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/007.png\" width=\"94\"\/><\/a><\/p>\n<p>For the sides, it will be <strong>a\/2<\/strong> to the side and <strong>b\/2<\/strong> up or down.<\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/008.png\"><img alt=\"008\" class=\"alignnone size-full wp-image-397572\" height=\"94\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/008.png\" width=\"94\"\/><\/a><\/p>\n<p>Then, draw lines between the co-ordinates to finish the octagon.<\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/009.png\"><img alt=\"009\" class=\"alignnone size-full wp-image-397573\" height=\"94\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/009.png\" width=\"94\"\/><\/a><\/p>\n<p>And there you have a regular octagon!<\/p>\n<p>\u00a0<\/p>\n<p><em><strong>Pseudo code:<\/strong><\/em><\/p>\n<p><b>Initialize<\/b><strong>:<\/strong><\/p>\n<p>size = (length of side of square)<br\/>\noct_side = round((size*sqrt(2))\/(2+sqrt(2)))<\/p>\n<p><strong>Loop:<\/strong><\/p>\n<p>coord_1x = x \u2013 oct_side\/2<br\/>\ncoord_1y = y + size\/2<br\/>\ncoord_2x = x + oct_side\/2<br\/>\ncoord_2y = y + size\/2<br\/>\ncoord_3x = x + size\/2<br\/>\ncoord_3y = y + oct_side\/2<br\/>\ncoord_4x = x + size\/2<br\/>\ncoord_4y = y \u2013 oct_side\/2<br\/>\ncoord_5x = x + oct_side\/2<br\/>\ncoord_5y = y \u2013 size\/2<br\/>\ncoord_6x = x \u2013 oct_side\/2<br\/>\ncoord_6y = y \u2013 size\/2<br\/>\ncoord_7x = x \u2013 size\/2<br\/>\ncoord_7y = y \u2013 oct_side\/2<br\/>\ncoord_8x = x \u2013 size\/2<br\/>\ncoord_8y = y + oct_side\/2<\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/010.png\"><img alt=\"010\" class=\"alignnone size-full wp-image-397574\" height=\"94\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/010.png\" width=\"94\"\/><\/a><\/p>\n<p>\/\/<em>draw_line(from_x,from_y,to_x,to_y)<\/em><\/p>\n<p>draw_line(coord_1x,coord_1y,coord_2x,coord_2y)<br\/>\ndraw_line(coord_2x,coord_2y,coord_3x,coord_3y)<br\/>\ndraw_line(coord_3x,coord_3y,coord_4x,coord_4y)<br\/>\ndraw_line(coord_4x,coord_4y,coord_5x,coord_5y)<br\/>\ndraw_line(coord_5x,coord_5y,coord_6x,coord_6y)<br\/>\ndraw_line(coord_6x,coord_6y,coord_7x,coord_7y)<br\/>\ndraw_line(coord_7x,coord_7y,coord_8x,coord_8y)<br\/>\ndraw_line(coord_8x,coord_8y,coord_1x,coord_1y)<\/p>\n<p>\u00a0<\/p>\n<p>And that\u2019s how to draw a perfect octagon!<\/p>\n<p><strong>Coming soon: How to draw a perfect hexagon!<\/strong><\/p>\n<p>\u00a0<\/p>\n<p>To those interested in the maths involved to get the equation:<\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/Maths1.png\"><img alt=\"Maths\" class=\"alignnone size-medium wp-image-397583\" height=\"300\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/11\/Maths1-96x300.png\" width=\"96\"\/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>I originally calculated this to be able to draw the Aperture Science logo by hand, but I also saw the use of it on the computer!<\/p>\n<p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/code\/\" rel=\"tag\">code<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/drawing\/\" rel=\"tag\">drawing<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/maths\/\" rel=\"tag\">maths<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/octagon\/\" rel=\"tag\">octagon<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/tutorial\/\" rel=\"tag\">tutorial<\/a><\/p>","time":"November 11th, 2014 4:45 am","title":"How to draw a Perfect Octagon!","title_was_empty":false}