{"id":3179,"date":"2021-04-21T11:20:12","date_gmt":"2021-04-21T03:20:12","guid":{"rendered":"https:\/\/www.rotor.com.tw\/?p=3179"},"modified":"2021-04-21T11:22:54","modified_gmt":"2021-04-21T03:22:54","slug":"07-processing%e4%ba%92%e5%8b%95%e8%a8%ad%e8%a8%88-hello-world","status":"publish","type":"post","link":"https:\/\/www.rotor.com.tw\/?p=3179","title":{"rendered":"#07 Processing\u4e92\u52d5\u8a2d\u8a08-Hello World!"},"content":{"rendered":"\n<p>Processing\u7684\u74b0\u5883\u67b6\u69cb\u4e86\u89e3\u5f8c\u958b\u59cb\u5617\u8a66\u7b2c\u4e00\u652f\u7a0b\u5f0fHello\u554f\u5019\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Hello World\u7a0b\u5f0f\u67b6\u69cb<\/h2>\n\n\n\n<p>\u6211\u5011\u5229\u7528Porcessing\u5efa\u7acb\u4e00\u500b\u756b\u5e03\uff0c\u756b\u5e03\u5167\u5bb9\u7522\u751f\u6587\u5b57\uff0c\u529f\u80fd\u5340\u584a\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>\u5efa\u7acb300&#215;200\u8996\u7a97<\/li><li>\u6307\u5b9a\u6587\u5b57\u5b57\u578b\u3001\u5927\u5c0f<\/li><li>\u4f7f\u7528text()\u8f38\u51fa\u6587\u5b57\u5167\u5bb9<\/li><li>text(\u6587\u5b57, x\u4f4d\u7f6e, y\u4f4d\u7f6e)<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nPFont f; \/\/\u5ba3\u544a\u5b57\u9ad4\u578b\u614b\u8b8a\u6578\n\nvoid setup() {\n  size(300,200); \/\/\u5efa\u7acb300x200\u8996\u7a97\n  f = createFont(&quot;\u7d30\u660e\u9ad4&quot;,16,true); \/\/\u6307\u5b9a\u6587\u5b57\u5b57\u578b\u3001\u5927\u5c0f\n}\n\nvoid draw() {\n  textFont(f);\n  fill(255,0,0);\n  text(&quot;Hello World!!&quot;, 25, 40); \/\/\u4f7f\u7528text()\u8f38\u51fa\u6587\u5b57\u5167\u5bb9\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/www.rotor.com.tw\/wp-content\/uploads\/2021\/04\/2021042101.jpg?ssl=1\"><img decoding=\"async\" loading=\"lazy\" width=\"302\" height=\"227\" src=\"https:\/\/i0.wp.com\/www.rotor.com.tw\/wp-content\/uploads\/2021\/04\/2021042101.jpg?resize=302%2C227&#038;ssl=1\" alt=\"\" class=\"wp-image-3185\" srcset=\"https:\/\/i0.wp.com\/www.rotor.com.tw\/wp-content\/uploads\/2021\/04\/2021042101.jpg?w=302&amp;ssl=1 302w, https:\/\/i0.wp.com\/www.rotor.com.tw\/wp-content\/uploads\/2021\/04\/2021042101.jpg?resize=300%2C225&amp;ssl=1 300w\" sizes=\"(max-width: 302px) 100vw, 302px\" data-recalc-dims=\"1\" \/><\/a><figcaption>Hello World! \u7b2c\u4e00\u652f\u7a0b\u5f0f\u986f\u793a\u7d50\u679c<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u9375\u76e4\u4e8b\u4ef6\u8655\u7406\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u900f\u904e\u9375\u76e4\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u79fb\u52d5\u6587\u5b57\u986f\u793a\u7684\u4f4d\u7f6e\uff0c\u5275\u4f5c\u4e00\u500b\u7c21\u55ae\u7684\u4e92\u52d5\u6548\u679c\u3002\u9375\u76e4\u7684\u4e8b\u4ef6\u8655\u7406\u65b9\u6cd5\u53ef\u4ee5\u900f\u904e\u8b8a\u6578 &#8220;KeyPressed&#8221; \u6216\u662f\u4e8b\u4ef6\u526f\u7a0b\u5f0f &#8220;KeyPress()&#8221; \u7684\u547c\u53eb\u9032\u884c\u8655\u7406\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u7bc4\u4f8b\u9375\u76e4\u63a7\u5236\u65b9\u584a\u79fb\u52d5\u7a0b\u5f0f\uff0c\u958b\u555f\u4e00\u500b\u756b\u5e03 size(400,400)\uff0c\u4e26\u5efa\u7acb\u4e00\u500b\u65b9\u584arect(xPos-25, yPos-25, 50, 50);\uff0c\u5229\u7528\u9375\u76e4\u7684w, s, a, d \u6539\u8b8a xPos\u3001yPos\u7684\u5ea7\u6a19\u5167\u5bb9\uff0c\u63a7\u5236\u65b9\u584a\u7684\u79fb\u52d5\u3002<\/p>\n\n\n\n<p><strong>Example 1. \u900f\u904e\u9375\u76e4\u7684\u8b8a\u6578\u53d6\u56de\u9375\u76e4\u4e8b\u4ef6<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nint xPos=200, yPos=200;\n\nvoid setup() {\n  size(400, 400);\n  smooth();\n}\n\nvoid draw() {\n  background(204); \n  \n  \/\/\u6bd4\u5c0dkeyPressed\u7684\u8b8a\u6578\u5167\u662f\u5426\u70ba w, s, a, d\n  if (keyPressed) {\n    if (key == &#039;w&#039;) { \/\/\u7576w\u9375\u76e4\u89f8\u767c\uff0cY\u5ea7\u6a19-5\n      yPos -= 5;\n    }\n    if (key == &#039;s&#039;) {  \/\/\u7576s\u9375\u76e4\u89f8\u767c\uff0cY\u5ea7\u6a19+5\n      yPos += 5;\n    }\n    if (key == &#039;a&#039;) { \/\/\u7576a\u9375\u76e4\u89f8\u767c\uff0cX\u5ea7\u6a19-5\n      xPos -= 5;\n    }\n    if (key == &#039;d&#039;) { \/\/\u7576w\u9375\u76e4\u89f8\u767c\uff0cX\u5ea7\u6a19+5\n      xPos += 5;\n    }\n  }\n  rect(xPos-25, yPos-25, 50, 50); \n  delay(100);\n}\n<\/pre><\/div>\n\n\n<p><strong>Example 2. \u900f\u904e\u9375\u76e4\u4e8b\u4ef6\u7684\u526f\u7a0b\u5f0f\u8b8a\u66f4 X\u3001Y\u5ea7\u6a19<\/strong><\/p>\n\n\n\n<p>\u6539\u5beb example 1. \u9375\u76e4\u6309\u4e0b\u6642\uff0cCPU\u6703\u4e3b\u52d5\u9032\u5165 keyPressed()\u526f\u7a0b\u5f0f\uff0c\u56e0\u6b64\u5c07X\u5ea7\u6a19\u3001Y\u5ea7\u6a19\u7684\u8655\u7406\u65b9\u5f0f\u8b8a\u66f4\u81f3\u526f\u7a0b\u5f0f keyPressed()\u5167\u8655\u7406\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nint xPos=200, yPos=200;\n\nvoid setup() {\n  size(400, 400);\n  smooth();\n}\n\nvoid draw() {\n  background(204); \n  \n  rect(xPos-25, yPos-25, 50, 50); \n}\n\n\/\/\u7576\u9375\u76e4\u6309\u4e0b\u6642\uff0c\u9375\u76e4\u4e8b\u4ef6\u4e3b\u52d5\u9032\u5165\u526f\u7a0b\u5f0f keyPressed()\nvoid keyPressed(){\n    if (key == &#039;w&#039;) { \/\/\u7576w\u9375\u76e4\u89f8\u767c\uff0cY\u5ea7\u6a19-5\n      yPos -= 5;\n    }\n    if (key == &#039;s&#039;) { \/\/\u7576s\u9375\u76e4\u89f8\u767c\uff0cY\u5ea7\u6a19+5\n      yPos += 5;\n    }\n    if (key == &#039;a&#039;) { \/\/\u7576a\u9375\u76e4\u89f8\u767c\uff0cX\u5ea7\u6a19-5\n      xPos -= 5;\n    }\n    if (key == &#039;d&#039;) { \/\/\u7576w\u9375\u76e4\u89f8\u767c\uff0cX\u5ea7\u6a19+5\n      xPos += 5;\n    }\n}\n<\/pre><\/div>\n\n\n<p>example 1. \u8207 example 2.\u57f7\u884c\u7d50\u679c\u5982\u4e0b\u756b\u9762\uff0c\u900f\u904e\u9375\u76e4\u89f8\u767c\u6539\u8b8a\u65b9\u584a\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/www.rotor.com.tw\/wp-content\/uploads\/2021\/04\/2021042101.mp4\"><\/video><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Processing\u7684\u74b0\u5883\u67b6\u69cb\u4e86\u89e3\u5f8c\u958b\u59cb\u5617\u8a66\u7b2c\u4e00\u652f\u7a0b\u5f0fHello\u554f\u5019\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false},"categories":[57],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/3179"}],"collection":[{"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3179"}],"version-history":[{"count":16,"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/3179\/revisions"}],"predecessor-version":[{"id":3197,"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/3179\/revisions\/3197"}],"wp:attachment":[{"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rotor.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}