{"id":536,"date":"2009-10-14T00:11:40","date_gmt":"2009-10-13T16:11:40","guid":{"rendered":"http:\/\/test999.eblhost.com\/blog\/?p=536"},"modified":"2009-11-17T11:00:12","modified_gmt":"2009-11-17T03:00:12","slug":"processing%ef%bc%9a%e6%95%b0%e7%bb%84%ef%bc%88%e4%b8%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/learn.travelchinawith.me\/?p=536","title":{"rendered":"Processing\uff1a\u6570\u7ec4\uff08\u4e0b\uff09"},"content":{"rendered":"<p>12. ok\uff0c\u73b0\u5728\u6765\u505a100\u8f86\u8f66\u5427\uff1a<br \/>\n<em><span style=\"color: #888888;\"> <\/span><\/em><\/p>\n<figure id=\"attachment_537\" aria-describedby=\"caption-attachment-537\" style=\"width: 197px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-3.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-537\" title=\"pr9-3\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-3.gif\" alt=\"pr9-3\" width=\"197\" height=\"198\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-3.gif 197w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-3-120x120.gif 120w\" sizes=\"auto, (max-width: 197px) 100vw, 197px\" \/><\/a><figcaption id=\"caption-attachment-537\" class=\"wp-caption-text\">pr9-3<\/figcaption><\/figure>\n<p><em><span style=\"color: #888888;\">Car[] cars = new Car[100]; \/\/ \u7531100\u4e2acars\u5bf9\u8c61\u7ec4\u6210\u7684\u6570\u7ec4!<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void setup() {<br \/>\nsize(200,200);<br \/>\nsmooth();<br \/>\nfor (int i = 0; i &lt; cars.length; i ++ ) { \/\/ \u7528for\u5faa\u73af\u521d\u59cb\u5316100\u8f86\u8f66.<br \/>\ncars[i] = new Car(color(i*2),0,i*2,i\/20.0);<br \/>\n}<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void draw() {<br \/>\nbackground(255);<br \/>\nfor (int i = 0; i &lt; cars.length; i ++ ) { \/\/ \u7528for\u5faa\u73af\u8dd1\u6bcf\u4e00\u8f86\u8f66.<br \/>\ncars[i].move();<br \/>\ncars[i].display();<br \/>\n}<br \/>\n}<\/span><\/em><br \/>\n\u5f53\u7136\uff0c\u4f60\u7684Car\u7c7b\u8fd8\u662f\u653e\u5728\u4e00\u8fb9\uff0c\u4e0d\u9700\u8981\u6539\u52a8\u4efb\u4f55\u53c2\u6570\uff0c\u65e0\u8bba\u6211\u4eec\u53ea\u8dd11\u8f86\u8f66\uff0c\u8fd8\u662f\u540c\u65f6\u8dd1100\u8f86\uff0c\u751a\u81f31000\u8f86\u8f66\u3002<\/p>\n<p>13. \u5f53\u4f60\u8bbe\u8ba1\u4f60\u7684\u7c7b\u7684\u65f6\u5019\uff0c\u8fd0\u7528\u5e03\u5c14\u53d8\u91cf\u6765\u53d8\u6362\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u662f\u5f88\u65b9\u4fbf\u7684\u3002\u4f8b\u5982\uff0c\u4e00\u4e2aCar\u5bf9\u8c61\u662f\u8dd1\u8fd8\u662f\u4e0d\u8dd1\uff0cZoog\u53ef\u80fd\u9ad8\u5174\u6216\u4e0d\u9ad8\u5174\u3002<\/p>\n<figure id=\"attachment_538\" aria-describedby=\"caption-attachment-538\" style=\"width: 200px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-4.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-538\" title=\"pr9-4\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-4.gif\" alt=\"pr9-4\" width=\"200\" height=\"199\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-4.gif 200w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-4-120x120.gif 120w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><figcaption id=\"caption-attachment-538\" class=\"wp-caption-text\">pr9-4<\/figcaption><\/figure>\n<p>14. \u597d\u7684\uff0c\u6765\u8fd0\u7528\u4e0a\u8fb9\u8bf4\u7684\uff0c\u7ee7\u7eed\u6765\u770b\u8d85\u957f\u6655\u7729\u4ee3\u7801\u3002\u3002\u3002<br \/>\n<em><span style=\"color: #888888;\"> \/\/ \u4e00\u4e2astripes\u7684\u6570\u7ec4<br \/>\nStripe[] stripes = new Stripe[70];<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void setup() {<br \/>\nsize(200,200);<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ Initialize all Stripe objects<br \/>\nfor (int i = 0; i &lt; stripes.length; i ++ ) {<br \/>\nstripes[i] = new Stripe();<br \/>\n}<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void draw() {<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> background(30);<br \/>\n\/\/ \u79fb\u52a8\u5e76\u663e\u793a\u6240\u6709stripes\u6570\u7ec4<br \/>\nfor (int i = 0; i &lt; stripes.length; i ++ ) {     \/\/ \u68c0\u67e5\u9f20\u6807\u662f\u5426\u4f4d\u4e8e\u6761\u7eb9\u4e0a     stripes[i].rollover(mouseX,mouseY); \/\/ \u5c06\u9f20\u6807\u5750\u6807\u4f20\u9012\u8fdb\u5165\u4e00\u4e2a\u5bf9\u8c61<br \/>\nstripes[i].move();     stripes[i].display();<br \/>\n}<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> class Stripe {<br \/>\nfloat x;     \/\/ \u6761\u7eb9\u7684\u6c34\u5e73\u5750\u6807\u503c<br \/>\nfloat speed; \/\/ \u6761\u7eb9\u7684\u79fb\u52a8\u901f\u5ea6<br \/>\nfloat w;     \/\/ \u6761\u7eb9\u7684\u5bbd\u5ea6<br \/>\n\/\/ \u4e00\u4e2a\u5e03\u5c14\u53d8\u91cf\u6301\u7eed\u6355\u6349\u5bf9\u8c61\u7684\u72b6\u6001.<br \/>\nboolean mouse; \/\/ \u6761\u7eb9\u7684\u72b6\u6001\uff08\u9f20\u6807\u662f\u5426\u4f4d\u4e8e\u6761\u7eb9\u4e0a\uff1f\uff09 <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> Stripe() {<br \/>\n\/\/ \u6240\u6709\u6761\u7eb9\u59cb\u4e8e0<br \/>\nx = 0;<br \/>\n\/\/ \u6240\u6709\u6761\u7eb9\u90fd\u6709\u4e00\u4e2a\u968f\u673a\u7684\u6b63\u5411\u79fb\u52a8\u901f\u5ea6<br \/>\nspeed = random(1);<br \/>\nw = random(10,30);<br \/>\nmouse = false;<br \/>\n} <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u7ed8\u5236\u6761\u7eb9<br \/>\nvoid display() {<br \/>\n\/\/ \u5e03\u5c14\u53d8\u91cf\u51b3\u5b9a\u6761\u7eb9\u989c\u8272<br \/>\nif (mouse) {<br \/>\nfill(255);<br \/>\n} else {<br \/>\nfill(255-x,100+w,x);<br \/>\n} <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> noStroke();<br \/>\nrect(x,0,w,height);<br \/>\n} <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u79fb\u52a8\u6761\u7eb9<br \/>\nvoid move() {<br \/>\nx += speed;<br \/>\nif (x &gt; width + 20)<br \/>\nx = -20;<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">\/\/ \u68c0\u67e5\u70b9(mx,my)\u662f\u5426\u4f4d\u4e8e\u6761\u7eb9\u5185.<br \/>\nvoid rollover(int mx, int my) {<br \/>\n\/\/ \u6761\u7eb9\u5de6\u6cbf\u662fx, \u53f3\u6cbf\u662fx + w<br \/>\nif (mx &gt; x &amp;&amp; mx &lt; x + w) {<br \/>\nmouse = true;<br \/>\n} else {<br \/>\nmouse = false;<br \/>\n}<br \/>\n}<br \/>\n}<\/span><\/em><\/p>\n<figure id=\"attachment_539\" aria-describedby=\"caption-attachment-539\" style=\"width: 198px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-5.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-539\" title=\"pr9-5\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-5.gif\" alt=\"pr9-5\" width=\"198\" height=\"198\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-5.gif 198w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/10\/pr9-5-120x120.gif 120w\" sizes=\"auto, (max-width: 198px) 100vw, 198px\" \/><\/a><figcaption id=\"caption-attachment-539\" class=\"wp-caption-text\">pr9-5<\/figcaption><\/figure>\n<p>15. \u6570\u7ec4\u6709\u4e00\u4e9b\u51fd\u6570\u53ef\u7528\u4e8e\u63a7\u5236\u5b83\u7684\u5927\u5c0f\uff0c\u5b83\u4eec\u662f\uff1a<em><span style=\"color: #888888;\">horten( )<\/span>, <span style=\"color: #888888;\">concat( )<\/span>, <span style=\"color: #888888;\">subset( )<\/span>, <span style=\"color: #888888;\">append( <\/span><span style=\"color: #888888;\">)<\/span>, <span style=\"color: #888888;\">splice( )<\/span>, <\/em>\u548c<em><span style=\"color: #888888;\">expand( ) <\/span><\/em> \u3002\u6b64\u5916\u8fd8\u6709\u53ef\u4ee5\u6539\u53d8\u6570\u7ec4\u987a\u5e8f\u7684\u51fd\u6570\uff0c\u6bd4\u5982<em><span style=\"color: #888888;\">sort( )<\/span><\/em>\u548c <em><span style=\"color: #888888;\">reverse( ) <\/span><\/em>\u3002Daniel\u8fd9\u91cc\u5077\u61d2\u4e86\uff0c\u544a\u8bc9\u6211\u4eec\u8fd9\u4e9b\u6240\u6709\u7684\u51fd\u6570\u90fd\u80fd\u5728pr\u7684\u53c2\u8003\u91cc\u627e\u5230\uff08\u5e9f\u8bdd\u3002\u3002\uff09\uff0c\u7136\u540e\u4e3e\u4e86\u8fd9\u4e48\u4e00\u4e2a\u4f8b\u5b50\uff08\u4f7f\u7528<span style=\"color: #888888;\"><em>append( )<\/em><\/span>\u589e\u5927\u6570\u7ec4\uff09\uff1a<br \/>\n<span style=\"color: #888888;\"><em> Ball[] balls = new Ball[1]; \/\/ \u6211\u4eec\u4ece\u4ec5\u6709\u4e00\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\u5f00\u59cb.<br \/>\nfloat gravity = 0.1;<\/em><\/span><\/p>\n<p><span style=\"color: #888888;\"><em>void setup() {<br \/>\nsize(200,200);<br \/>\nsmooth();<\/em><\/span><\/p>\n<p><span style=\"color: #888888;\"><em> \/\/ \u521d\u59cb\u53160\u53f7\u7403<br \/>\nballs[0] = new Ball(50,0,16);<br \/>\n}<\/em><\/span><\/p>\n<p><span style=\"color: #888888;\"><em>void draw() {<br \/>\nbackground(255);<\/em><\/span><\/p>\n<p><span style=\"color: #888888;\"><em> \/\/ \u66f4\u65b0\u5e76\u663e\u793a\u6240\u6709\u7684\u7403<br \/>\nfor (int i = 0; i &lt; balls.length; i ++ ) {<br \/>\n\/\/ \u65e0\u8bba\u6570\u7ec4\u6709\u591a\u957f\uff0c\u66f4\u65b0\u5e76\u663e\u793a\u6240\u6709\u7684\u5143\u7d20.<br \/>\nballs[i].gravity();<br \/>\nballs[i].move();<br \/>\nballs[i].display();<br \/>\n}<br \/>\n}<\/em><\/span><\/p>\n<p><span style=\"color: #888888;\"><em> void mousePressed() {<br \/>\n\/\/ \u4e00\u4e2a\u65b0\u7684ball\u5bf9\u8c61<br \/>\nBall b = new Ball(mouseX,mouseY,random(10,30)); \/\/ \u5728\u9f20\u6807\u4f4d\u7f6e\u5236\u9020\u4e00\u4e2a\u65b0\u5bf9\u8c61.<br \/>\n<strong> balls = (Ball[]) append(balls,b);<\/strong><\/em><em> \/\/ <strong>\u8fd9\u91cc\uff0c\u51fd\u6570append() \u5728\u6570\u7ec4\u7684\u672b\u5c3e\u589e\u52a0\u4e86\u4e00\u4e2a\u5143\u7d20<\/strong>.<br \/>\n\/\/ append() \u4f7f\u7528\u4e86\u4e24\u4e2a\u5f15\u6570. \u7b2c\u4e00\u4e2a\u662f\u4f60\u5e0c\u671b\u9644\u52a0\u7684\u6570\u7ec4, \u7b2c\u4e8c\u662f\u4f60\u5e0c\u671b\u9644\u52a0\u7684\u4e1c\u897f.<br \/>\n\/\/ \u4f60\u9700\u8981\u5c06append() \u5f97\u5230\u7684\u7ed3\u679c\u91cd\u65b0\u5206\u914d\u7ed9\u6700\u521d\u7684\u6570\u7ec4.<br \/>\n\/\/ \u53e6\u5916, append()\u51fd\u6570\u8981\u6c42\u4f60\u901a\u8fc7\u5411\u5706\u62ec\u53f7\u5185\u586b\u5165\u6570\u7ec4\u6570\u636e\u7c7b\u578b\uff08(Ball[])\uff09\u7684\u65b9\u5f0f\u518d\u6b21\u6e05\u695a\u7684\u8868\u8ff0\u6570\u7ec4\u91cc\u7684\u6570\u636e\u7c7b\u578b\u3002<br \/>\n\/\/\u8fd9\u4e00\u8fc7\u7a0b\u53eb\u505a\u6295\u63b7\uff08casting\uff09<br \/>\n} <\/em><\/span><\/p>\n<p><em><span style=\"color: #888888;\">class Ball {<br \/>\nfloat x;<br \/>\nfloat y;<br \/>\nfloat speed;<br \/>\nfloat w;<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> Ball(float tempX, float tempY, float tempW) {<br \/>\nx = tempX;<br \/>\ny = tempY;<br \/>\nw = tempW;<br \/>\nspeed = 0;<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> void gravity() {<br \/>\n\/\/ \u91cd\u529b\u52a0\u901f\u5ea6<br \/>\nspeed = speed + gravity;<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> void move() {<br \/>\n\/\/ \u5c06\u901f\u5ea6\u52a0\u5230y\u8f74<br \/>\ny = y + speed;<br \/>\n\/\/ \u5982\u679c\u5c0f\u7403\u5230\u5e95<br \/>\n\/\/ \u5c06\u901f\u5ea6\u53cd\u5411<br \/>\nif (y &gt; height) {<br \/>\nspeed = speed * -0.95;<br \/>\ny = height;<br \/>\n}<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> void display() {<br \/>\n\/\/ \u663e\u793a\u7403<br \/>\nfill(random(255));<br \/>\nstroke(0);<br \/>\nellipse(x,y,w,w);<br \/>\n}<br \/>\n}<\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>12. ok\uff0c\u73b0\u5728\u6765\u505a100\u8f86\u8f66\u5427\uff1a Car[] cars = new Car[100]; \/\/ \u7531100\u4e2acars\u5bf9\u8c61\u7ec4\u6210\u7684\u6570\u7ec4! void setup() { size(200,200); smooth(); for (int i = 0; i &lt; cars.length; i ++ ) { \/\/ \u7528for\u5faa\u73af\u521d\u59cb\u5316100\u8f86\u8f66. cars[i] = new Car(color(i*2),0,i*2,i\/20.0); } } void draw() { background(255); for (int i = 0; i &lt; cars.length; i ++ ) { \/\/ \u7528for\u5faa\u73af\u8dd1\u6bcf\u4e00\u8f86\u8f66. cars[i].move(); cars[i].display(); } [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[58],"class_list":["post-536","post","type-post","status-publish","format-standard","hentry","category-processing","tag-processing"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=536"}],"version-history":[{"count":6,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/536\/revisions"}],"predecessor-version":[{"id":761,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/536\/revisions\/761"}],"wp:attachment":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}