{"id":3577,"date":"2017-12-04T12:11:19","date_gmt":"2017-12-04T20:11:19","guid":{"rendered":"http:\/\/miriamposner.com\/classes\/dh101f17\/?page_id=3577"},"modified":"2017-12-04T12:13:57","modified_gmt":"2017-12-04T20:13:57","slug":"lets-play-with-p5","status":"publish","type":"page","link":"https:\/\/miriamposner.com\/classes\/dh101f17\/tutorials-guides\/programming\/lets-play-with-p5\/","title":{"rendered":"Let&#8217;s play with p5!"},"content":{"rendered":"<p>In class today, we&#8217;re going to do a little bit of drawing with p5.js. As you learned, p5.js is a JavaScript library designed to help you make interactive drawings and share them on the web.<\/p>\n<h2><a id=\"user-content-open-up-the-web-editor\" class=\"anchor\" href=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/blob\/master\/let-s-play-with-p5-.md#open-up-the-web-editor\" aria-hidden=\"true\"><\/a>Open up the web editor<\/h2>\n<p>There are a few different ways you could code in p5. One of the most common ways is to download p5, write your program in a text editor, and view your drawing in a browser. Then, when you&#8217;re ready, you could upload the whole package to a server so other people can see it. That&#8217;s pretty easy to do!<\/p>\n<p>But because there are a lot of us, and we&#8217;re all using differently configured computers, we&#8217;re going to do something even easier: We&#8217;ll use an interactive web editor for p5. This is a way to write and execute your p5 code directly on the web.<\/p>\n<p>To open the editor, go to\u00a0<a href=\"https:\/\/alpha.editor.p5js.org\/\" rel=\"nofollow\">https:\/\/alpha.editor.p5js.org\/.<\/a>\u00a0(The &#8220;alpha&#8221; in that URL is meant to suggest that this web editor is still under development, so there could be bugs!)<\/p>\n<p><a href=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/blob\/master\/images\/let-s-play-with-p5-\/open-up-the-web-editor.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/raw\/master\/images\/let-s-play-with-p5-\/open-up-the-web-editor.png\" alt=\"\" \/><\/a><\/p>\n<h2><a id=\"user-content-understanding-the-web-editor\" class=\"anchor\" href=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/blob\/master\/let-s-play-with-p5-.md#understanding-the-web-editor\" aria-hidden=\"true\"><\/a>Understanding the web editor<\/h2>\n<p>You&#8217;ll notice that your screen is divided into two parts. The left side is where you write your code; the right side, where it says\u00a0<strong>Preview<\/strong>, is where you&#8217;ll see your drawing.<\/p>\n<p>The left side of your screen, the editor, is already populated with two JavaScript\u00a0<strong>functions<\/strong>. (Functions are bits of code that do something.) The first function,\u00a0<strong>setup( )<\/strong>\u00a0builds a canvas (a drawing space) that is 400 pixels tall by 400 pixels wide.<\/p>\n<p>The second function,\u00a0<strong>draw( )<\/strong>, colors the\u00a0<strong>background<\/strong>\u00a0of the canvas gray. (The number inside the\u00a0<strong>background( )\u00a0<\/strong>function, 220, refers to a\u00a0<strong>grayscale integer value<\/strong>\u00a0&#8212; a number between 0 (black) and 255 (white)).<\/p>\n<p>But the right side of your screen is white, not gray! What&#8217;s going on? Well, in order to execute the functions in your editor, you have to click the\u00a0<strong>play<\/strong>\u00a0button. Try that and see what happens.<\/p>\n<p>Can you figure out how to make the background black? Try that and press\u00a0<strong>play<\/strong>.<\/p>\n<p><a href=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/blob\/master\/images\/let-s-play-with-p5-\/understanding-the-web-editor.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/raw\/master\/images\/let-s-play-with-p5-\/understanding-the-web-editor.png\" alt=\"\" \/><\/a><\/p>\n<h2><a id=\"user-content-work-through-chapter-three\" class=\"anchor\" href=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/blob\/master\/let-s-play-with-p5-.md#work-through-chapter-three\" aria-hidden=\"true\"><\/a>Work through chapter three<\/h2>\n<p>Under Week 10 of CCLE, I&#8217;ve placed some files for you. They are two different versions of the book\u00a0<em>Getting Started with p5.js,\u00a0by Lauren McCarthy, Casey Reas, and Ben Fry<\/em>. The first version of the book, the one that ends in .epub, will look a lot nicer, so first try to download and work with that. If you can&#8217;t read epubs on your computer, download the second version of the file, the one that ends in .pdf.<\/p>\n<p>When you&#8217;ve downloaded the book, go to\u00a0<strong>chapter three<\/strong>\u00a0and work through the examples. With the knowledge you gain, try to draw a set of images that look like the picture below. Remember, the\u00a0<a href=\"https:\/\/p5js.org\/\" rel=\"nofollow\">p5js.org<\/a>\u00a0website has a\u00a0<strong>Reference\u00a0<\/strong>section that will help you understand the various functions.<\/p>\n<p><a href=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/blob\/master\/images\/let-s-play-with-p5-\/work-through-chapter-three.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/p5_tutorial\/raw\/master\/images\/let-s-play-with-p5-\/work-through-chapter-three.png\" alt=\"\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In class today, we&#8217;re going to do a little bit of drawing with p5.js. As you learned, p5.js is a<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":145,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","footnotes":""},"class_list":["post-3577","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages\/3577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/comments?post=3577"}],"version-history":[{"count":0,"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages\/3577\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages\/145"}],"wp:attachment":[{"href":"https:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/media?parent=3577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}