{"id":5,"date":"2011-12-10T00:02:42","date_gmt":"2011-12-10T05:02:42","guid":{"rendered":"https:\/\/peterabeles.com\/blog\/?p=5"},"modified":"2012-02-07T23:30:07","modified_gmt":"2012-02-08T04:30:07","slug":"programming-in-postscript","status":"publish","type":"post","link":"https:\/\/peterabeles.com\/blog\/?p=5","title":{"rendered":"Programming in PostScript"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div style=\"width: 282px\" class=\"wp-caption alignright\"><a href=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2011\/12\/grid_small.png\"><img loading=\"lazy\" decoding=\"async\" title=\"grid_small\" src=\"https:\/\/peterabeles.com\/blog\/wp-content\/uploads\/2011\/12\/grid_small.png\" alt=\"\" width=\"272\" height=\"353\" \/><\/a><p class=\"wp-caption-text\">Calibration target created using PS. Corners are detected and at a known distances apart, allowing intrinsic camera parameters to be determined.<\/p><\/div>\n<p>Recently I needed to design and create a calibration grid for calibrating a camera.\u00a0 The calibration grid was going to be very simple, just composed of squares, but their locations needed to be precise.\u00a0 I couldn&#8217;t just slap something together in power point and call it good enough.<\/p>\n<p>After considering a few options, I decided to give writing my own <a href=\"http:\/\/en.wikipedia.org\/wiki\/PostScript\" target=\"_blank\">PostScript<\/a> (PS) document from scratch a try.\u00a0 PS is a document standard best known for printers.\u00a0 Almost all laser printers can print PS documents.\u00a0 If you have ever looked at a PS document as raw text you know it&#8217;s ugly.\u00a0 Turned out to not be all that bad to work with after all.<\/p>\n<p>PS is in fact a real programming language and is <a href=\"http:\/\/en.wikipedia.org\/wiki\/Turing_completeness\" target=\"_blank\">Turing complete<\/a>.\u00a0 Someone has even coded up the <a href=\"http:\/\/www.tjhsst.edu\/%7Eedanaher\/pslife\/\" target=\"_blank\">game of life<\/a>, which you can run on your favorite or not so favorite printer!\u00a0 Once you get used to how PS loads everything from the stack, it&#8217;s not all that bad of a scripting language.<\/p>\n<p>The two tutorials\/documents which I found useful are:<\/p>\n<ul>\n<li><a href=\"http:\/\/homepage.mac.com\/andykopra\/pdm\/tutorials\/an_introduction_to_postscript.html\" target=\"_blank\">An Introduction to Postscript<\/a><\/li>\n<li><a title=\"Blue Book\" href=\"http:\/\/www-cdf.fnal.gov\/offline\/PostScript\/BLUEBOOK.PDF\" target=\"_blank\">BLUEBOOK.PDF<\/a><\/li>\n<\/ul>\n<p>Less than two hours after I started I now know the basics of PS and created the PS document below.\u00a0 See in line comments for explanation of the code.<\/p>\n<pre lang=\"Python\">%!PS\r\n% paper size\r\n\/pagewidth 8.5 72 mul def\r\n\/pageheight 10 72 mul def \r\n\r\n% ----- Define centimeter\r\n\/cm {28.346 mul} def\r\n% ----- square width\r\n\/w {3 cm} def\r\n\/ww {w 2 mul} def\r\n\/r {w 2 div} def\r\n% ----- Define procedure for drawing a box\r\n\/box {w 0 rlineto 0 w rlineto -1 w mul 0 rlineto closepath} def\r\n\r\n% take in account the size of a square\r\n\/pagewidth pagewidth ww sub def\r\n\/pageheight pageheight w sub def\r\n\r\n% draw all the boxes it can across a single row\r\n\/rowboxes {w ww pagewidth {newpath y moveto box fill} for} def\r\n\r\n% increments the y variable and draws all the rows\r\nw ww pageheight { \/y exch def rowboxes } for\r\n\r\nshowpage<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Recently I needed to design and create a calibration grid for calibrating a camera.\u00a0 The calibration grid was going to be very simple, just composed of squares, but their locations needed to be precise.\u00a0 I couldn&#8217;t just slap something together in power point and call it good enough. After considering a few options, I [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-programming"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5"}],"version-history":[{"count":10,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}