{"id":510,"date":"2017-09-28T10:57:00","date_gmt":"2017-09-28T15:57:00","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=510"},"modified":"2017-10-08T14:33:30","modified_gmt":"2017-10-08T19:33:30","slug":"processing-py-how-to-implement-10-print","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2017\/09\/28\/processing-py-how-to-implement-10-print\/","title":{"rendered":"Processing.py: How to implement 10 PRINT"},"content":{"rendered":"<p>Continuing the Processing.py series, this article demonstrates how to implement &#8217;10 PRINT&#8217; to create interesting line images. 10 PRINT is an old Commodore 64 one-line program written in\u00a0BASIC that looks like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">10 PRINT CHR$(205.5+RND(1)); : GOTO 10<\/pre>\n<p>For more information, see <a href=\"http:\/\/10print.org\/\">10print.org<\/a>.<\/p>\n<p>For the previous entry in the Processing.py series, see this page:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"7IxPmqos6k\"><p><a href=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/09\/26\/processing-py-how-to-use-shapes-placements-and-colors\/\">Processing.py: How to use shapes, placements, and colors<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/09\/26\/processing-py-how-to-use-shapes-placements-and-colors\/embed\/#?secret=7IxPmqos6k\" data-secret=\"7IxPmqos6k\" width=\"600\" height=\"338\" title=\"&#8220;Processing.py: How to use shapes, placements, and colors&#8221; &#8212; Chris Nielsen Code Walk\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>Here is the Processing.py code to implement 10 PRINT:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">x = 0\r\ny = 0\r\nspacing = 10\r\nrand_point = 0.50\r\n\r\ndef setup():\r\n    size(400, 400)\r\n    background(0)\r\n    stroke(255)\r\n    # stroke('#2C4AF0')  # blue\r\n    # stroke('#106A09')  # green\r\n    # stroke('#611ED6')  # purple\r\n    # strokeWeight(3)\r\n\r\ndef draw():\r\n    global x, y, spacing, rand_point\r\n    if (random(1) &lt; rand_point):\r\n        line(x, y, x+spacing, y+spacing)\r\n    else:\r\n        line(x, y+spacing, x+spacing, y)\r\n    x += spacing\r\n\r\n    if x &gt; width:\r\n        x = 0\r\n        y += spacing\r\n\r\n    saveFrame(\"print10_21.gif\")<\/pre>\n<p>Notes about this code:<\/p>\n<ul>\n<li>The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">draw()<\/code> function in Processing.py acts like a continuous loop, similar to a Pygame main event loop<\/li>\n<li>The\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">spacing<\/code> variable controls the length of the diagonal lines<\/li>\n<li>The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">background()<\/code> variable controls the color of the background<\/li>\n<li>The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">stroke()<\/code> variable controls the color of the lines<\/li>\n<li>The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">strokeWeight()<\/code> variable controls the thickness of the lines<\/li>\n<li>The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">rand_point<\/code> is the sorting point at which each random number that is generated will be rendered as either a forward slash or a back slash.<\/li>\n<\/ul>\n<p>By playing with all of these variables, it is possible to create a wide variety of outputs. For example:<\/p>\n<div id=\"attachment_514\" style=\"width: 410px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-514\" class=\"wp-image-514 size-full\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2017\/09\/print10_animated.gif\" alt=\"\" width=\"400\" height=\"400\" \/><p id=\"caption-attachment-514\" class=\"wp-caption-text\">A wide variety of outputs can be achieved.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Continuing the Processing.py series, this article demonstrates how to implement &#8217;10 PRINT&#8217; to create interesting line images. 10 PRINT is an old Commodore 64 one-line program written in\u00a0BASIC that looks like this: 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 For more information, see 10print.org. For the previous entry in the Processing.py series, see this page: Processing.py: &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2017\/09\/28\/processing-py-how-to-implement-10-print\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Processing.py: How to implement 10 PRINT<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,46],"tags":[36,4],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-processing-language","category-processing-py","tag-processing-py","tag-python"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":5,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"predecessor-version":[{"id":540,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/510\/revisions\/540"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}