{"id":673,"date":"2009-11-11T22:12:37","date_gmt":"2009-11-11T14:12:37","guid":{"rendered":"http:\/\/test999.eblhost.com\/blog\/?p=673"},"modified":"2009-11-11T22:12:37","modified_gmt":"2009-11-11T14:12:37","slug":"processing%ef%bc%9a%e5%b9%b3%e7%a7%bb%e5%92%8c%e6%97%8b%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/learn.travelchinawith.me\/?p=673","title":{"rendered":"Processing\uff1a\u5e73\u79fb\u548c\u65cb\u8f6c"},"content":{"rendered":"<p>1. z\u8f74\u6307\u4efb\u610f\u4e00\u70b9\u7684\u6df1\u5ea6\u3002\u8fd9\u8c8c\u4f3c\u5f88\u62bd\u8c61\uff0c\u8fd9\u4e48\u7406\u89e3\u5427\uff0cx\u8f74\u548cy\u8f74\u5206\u522b\u4ee3\u8868\u8424\u5e55\u7684\u5bbd\u548c\u9ad8\uff0c\u90a3\u4e48z\u8f74\u5c31\u4f4d\u4e8e\u4f60\u8424\u5e55\u7684\u80cc\u540e\uff08\u8d1f\u503c\uff09\u6216\u4e4b\u524d\uff08\u6b63\u503c\uff09\u3002<\/p>\n<p>2. \u7528\u4e8c\u7ef4\u7684\u65b9\u5f0f\u4e5f\u53ef\u4ee5\u505a\u51fa\u4e09\u7ef4\u7684\u6548\u679c\uff0c\u6bd4\u5982\u4e0b\u4f8b\u5c55\u793a\u4e00\u4e2a\u7531\u5c0f\u53d8\u5927\u7684\u77e9\u5f62\uff0c\u770b\u8d77\u6765\u5c31\u50cf\u5b83\u4ece\u8fdc\u5904\u5411\u6211\u4eec\u8d70\u6765\uff1a<br \/>\n<dirtycode>float r = 8;<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<\/p>\n<p>  \/\/ \u5728\u8424\u5e55\u4e2d\u592e\u663e\u793a\u4e00\u4e2a\u77e9\u5f62<br \/>\n  stroke(0);<br \/>\n  fill(175);<br \/>\n  rectMode(CENTER);<br \/>\n  rect(width\/2,height\/2,r,r);<\/p>\n<p>  \/\/ \u589e\u5927\u77e9\u5f62<br \/>\n  r++ ;<\/p>\n<p>  \/\/ \u53cd\u590d\u5f00\u542f\u77e9\u5f62\u7684\u52a8\u6001<br \/>\n  if (r > width) {<br \/>\n    r = 0;<br \/>\n  }<br \/>\n}<\/dirtycode><\/p>\n<p>3. \u5e78\u8fd0\u7684\u662f\uff0cProcessing\u61c2\u5f97\u900f\u89c6\uff0c\u5e76\u9009\u53d6\u9002\u5b9c\u7684\u4e8c\u7ef4\u50cf\u7d20\u6765\u521b\u5efa\u4e09\u7ef4\u6548\u679c\u3002\u6211\u4eec\u5e94\u5f53\u8ba4\u8bc6\u5230\uff0c\u5728\u6211\u4eec\u8fdb\u51653D\u50cf\u7d20\u5750\u6807\u7684\u540c\u65f6\uff0c\u4e00\u90e8\u5206\u7684\u63a7\u5236\u5fc5\u987b\u4ea4\u7531p5\u7684\u6e32\u67d3\u5668\u6765\u5b8c\u6210\u3002\u4f60\u4e0d\u5728\u80fd\u50cf\u63a7\u52362D\u56fe\u5f62\u90a3\u6837\u7cbe\u786e\u7684\u63a7\u5236\u5b83\u4eec\u7684\u50cf\u7d20\u4f4d\u7f6e\uff0c\u56e0\u4e3aXY\u4f4d\u7f6e\u5c06\u88ab\u8c03\u6574\u7528\u6765\u8ba1\u7b973D\u900f\u89c6\u3002<\/p>\n<p>4. \u4e0b\u56fe\u4e3a\u7b1b\u5361\u5c143D\u7cfb\u7edf\u7684\u5750\u6807\u56fe\u793a\uff1a<br \/>\n<figure id=\"attachment_677\" aria-describedby=\"caption-attachment-677\" style=\"width: 376px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-1.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-1.gif\" alt=\"3-D coordinate\" title=\"14-1\" width=\"376\" height=\"256\" class=\"size-full wp-image-677\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-1.gif 376w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-1-300x204.gif 300w\" sizes=\"auto, (max-width: 376px) 100vw, 376px\" \/><\/a><figcaption id=\"caption-attachment-677\" class=\"wp-caption-text\">3-D coordinate<\/figcaption><\/figure><\/p>\n<p>5. \u6ce8\u610f\uff0c\u8fd9\u4e48\u5199\u662f\u9519\u8bef\u7684\uff1a<br \/>\n<dirtycode:noclick>rect(x, y, z, w, h);<\/dirtycode>  <\/p>\n<p>6. \u5728p5\u7684\u4e16\u754c\u4e3a\u5f62\u72b6\u4f7f\u75283D\u5750\u6807\uff0c\u6211\u4eec\u5fc5\u987b\u5b66\u4e60\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\uff0c\u53eb\u505atranslate()\u3002\u51fd\u6570translate()\u79fb\u52a8\u539f\u70b9\u2014(0,0)\u2014\u76f8\u5bf9\u5176\u4e4b\u524d\u72b6\u6001\u3002\u6211\u4eec\u77e5\u9053\u5f53\u4e00\u4e2asketch\u5f00\u59cb\u8fd0\u884c\uff0c\u539f\u70b9\u4f4d\u4e8e\u8424\u5e55\u5de6\u4e0a\u89d2\u3002\u5982\u679c\u6211\u4eec\u5199translate(50,50)\uff0c\u7ed3\u679c\u5c06\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br \/>\n<figure id=\"attachment_679\" aria-describedby=\"caption-attachment-679\" style=\"width: 502px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-2.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-2.gif\" alt=\"translate(50,50);\" title=\"14-2\" width=\"502\" height=\"164\" class=\"size-full wp-image-679\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-2.gif 502w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-2-300x98.gif 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/a><figcaption id=\"caption-attachment-679\" class=\"wp-caption-text\">translate(50,50);<\/figcaption><\/figure><br \/>\n\u53e6\u5916\uff0c\u6bcf\u5f53\u8fd0\u884c\u4e00\u6b21draw()\uff0c\u539f\u70b9\u90fd\u4f1a\u5c06\u5176\u91cd\u7f6e\u56de\u8424\u5e55\u5de6\u4e0a\u89d2\u3002<\/p>\n<p>7. \u770b\u8fd9\u4e2a\u4f8b\u5b50\uff1a<br \/>\n<dirtycode>void setup() {<br \/>\n  size(200,200);<br \/>\n  smooth();<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(0);<br \/>\n  fill(175);<\/p>\n<p>  \/\/ \u6293\u53d6\u9f20\u6807\u4f4d\u7f6e, constrain\u5230\u8424\u5e55\u5c3a\u5bf8<br \/>\n  int mx = constrain(mouseX,0,width);<br \/>\n  int my = constrain(mouseY,0,height);<\/p>\n<p>  \/\/ \u5e73\u79fb\u5230\u9f20\u6807\u4f4d\u7f6e<br \/>\n  translate(mx,my);<br \/>\n  ellipse(0,0,8,8);<\/p>\n<p>  \/\/ \u5411\u53f3\u5e73\u79fb100\u50cf\u7d20<br \/>\n  translate(100,0);<br \/>\n  ellipse(0,0,8,8);<\/p>\n<p>  \/\/ \u5411\u4e0b\u5e73\u79fb100\u50cf\u7d20<br \/>\n  translate(0,100);<br \/>\n  ellipse(0,0,8,8);<\/p>\n<p>  \/\/ \u5411\u5de6\u5e73\u79fb100\u50cf\u7d20<br \/>\n  translate(-100,0);<br \/>\n  ellipse(0,0,8,8);<br \/>\n}<\/dirtycode><br \/>\ntranslate()\u7b2c\u4e00\u4e2a\u5f15\u6570\u63a7\u5236\u5de6\u53f3\u5e73\u79fb\uff0c\u7b2c\u4e8c\u4e2a\u5219\u63a7\u5236\u4e0a\u4e0b\u5e73\u79fb\u3002translate()\u7684\u201c\u76f8\u5bf9\u4e4b\u524d\u72b6\u6001\u201d\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc\u4f53\u73b0\u7684\u6bd4\u8f83\u660e\u663e\uff0c\u76f8\u5bf9\u7684\u4e0d\u6c38\u8fdc\u662fellipse(0,0,8,8)\u8fd9\u4e2a\u7403;\uff0c\u800c\u662ftranslate()\u4e4b\u540e\u7684\u90a3\u4e2a\u201c\u65b0\u7403\u201d<\/p>\n<p>8. translate()\u53ef\u4ee5\u63a5\u53d7\u7b2c\u4e09\u4e2a\u5f15\u6570\u4f5c\u4e3az\u8f74\u503c\u3002<br \/>\n<dirtycode:noclick>\/\/ \u6cbfz\u8f74\u5e73\u79fb<br \/>\ntranslate(0,0,50);<br \/>\nrectMode(CENTER);<br \/>\nrect(100,100,8,8); <\/dirtycode><br \/>\n\u4ee5\u4e0a\u4ee3\u7801\u6cbfz\u8f74\u5e73\u79fb50\u50cf\u7d20\uff0c\u7136\u540e\u5728\u4f4d\u7f6e(100,100)\u7ed8\u5236\u4e00\u4e2a\u77e9\u5f62\u3002\u8fd9\u5728\u6280\u672f\u4e0a\u662f\u6b63\u786e\u7684\uff0c\u4f46\u5f53\u6211\u4eec\u4f7f\u7528translate()\u65f6\uff0c\u4e00\u4e2a\u597d\u4e60\u60ef\u662f\u5c06\u4f4d\u7f6e(x,y)\u6307\u5b9a\u4e3a\u5e73\u79fb\u7684\u4e00\u90e8\u5206\uff0c\u5982\u4e0b\uff1a<br \/>\n<dirtycode:noclick>\/\/ \u5f53\u4f7f\u7528translate()\u65f6\uff0c\u77e9\u5f62\u7684\u4f4d\u7f6e\u65f6(0,0)\uff0c\u56e0\u4e3atranslate()\u5c06\u5e26\u6211\u4eec\u5230\u77e9\u5f62\u7684\u4f4d\u7f6e<br \/>\ntranslate(100,100,50);<br \/>\nrectMode(CENTER);<br \/>\nrect(0,0,8,8);<\/dirtycode><br \/>\n\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u7167\u505a\u4e00\u5f00\u59cb\u90a3\u4e2a\u77e9\u5f62\u53d8\u5927\u7684\u4f8b\u5b50\uff1a<br \/>\n<dirtycode>\/\/ \u4e00\u4e2aZ\uff08\u6df1\u5ea6\uff09\u5750\u6807\u7684\u53d8\u91cf<br \/>\nfloat z = 0;<\/p>\n<p>void setup() {<br \/>\n  \/\/ \u5f53\u65f6\u7528 (x,y,z) \u5750\u6807\u65f6, \u6211\u4eec\u5fc5\u987b\u544a\u8bc9p5\u6211\u4eec\u9700\u8981\u4e00\u4e2a3D sketch.<br \/>\n  \/\/ \u6211\u4eec\u4e3a\u6b64\u4e3asize()\u51fd\u6570\u589e\u52a0\u7b2c\u4e09\u4e2a\u5f15\u6570, P3D (\u6216 OPENGL)<br \/>\n  size(200,200,P3D);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(0);<br \/>\n  fill(175);<\/p>\n<p>  \/\/ \u5728\u4e00\u4e2a\u5f62\u72b6\u663e\u793a\u524d\u5e73\u79fb\u4e00\u4e2a\u70b9<br \/>\n  translate(width\/2,height\/2,z);<br \/>\n  rectMode(CENTER);<br \/>\n  rect(0,0,8,8); <\/p>\n<p>  \/\/ \u589e\u5927z<br \/>\n  z++ ;<\/p>\n<p>  \/\/ \u91cd\u542f\u77e9\u5f62<br \/>\n  if (z > 200) {<br \/>\n    z = 0;<br \/>\n  }<br \/>\n} <\/dirtycode><\/p>\n<p><figure id=\"attachment_680\" aria-describedby=\"caption-attachment-680\" style=\"width: 200px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-3.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-3.gif\" alt=\"14-3\" title=\"14-3\" width=\"200\" height=\"199\" class=\"size-full wp-image-680\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-3.gif 200w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-3-120x120.gif 120w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><figcaption id=\"caption-attachment-680\" class=\"wp-caption-text\">14-3<\/figcaption><\/figure><br \/>\n9. \u8fd9\u4e2a\u9898\u53c8\u628a\u6211\u6253\u8d25\u4e86\uff0c\uff0c\u6298\u817e\u597d\u4e45\u624d\u641e\u51fa\u6765\uff0c\u4e0d\u8fc7\u7ec8\u4e8e\u7b97\u662f\u5bf9\u5404\u79cd\u5f62\u72b6\u540c\u65f6translate()\u7684\u60c5\u51b5\u6709\u70b9\u5fc3\u5f97\u4e86\uff08\u518d\u6b21\u6ce8\u610f\uff0c\u5b83\u7684\u5e73\u79fb\u662f\u57fa\u4e8e\u4e0a\u4e00\u4e2a\u70b9\u7684\u4f4d\u7f6e\uff0c\u8fd9\u662f\u7406\u89e3\u8fd9\u4e2a\u51fd\u6570\u81f3\u5173\u91cd\u8981\u7684\u4e00\u70b9\uff09\uff1a<br \/>\n<dirtycode:noclick>size(200,200);<br \/>\nbackground(255);<br \/>\nstroke(0);<br \/>\nfill(0,100);<br \/>\nrectMode(CENTER);<br \/>\ntranslate(width\/2,height\/2);<br \/>\nrect(0,0,100,100);<br \/>\ntranslate(50,-50);<br \/>\nrect(0,0,100,100);<br \/>\ntranslate(-100,100);<br \/>\nline(0,0,-50,50); <\/dirtycode><\/p>\n<p>10. translate()\u51fd\u6570\u5bf9\u76f8\u5bf9\u4e00\u4e2a\u7ed9\u51fa\u7684\u4e2d\u70b9\u7ed8\u5236\u7684\u4e00\u7cfb\u5217\u5f62\u72b6\u5f88\u6709\u7528\u3002<br \/>\n<dirtycode>void display()  {<br \/>\n    \/\/ \u753bZoog\u7684\u8eab\u4f53<br \/>\n    fill(150);<br \/>\n    rect(x, y,w\/6,h*2); <\/p>\n<p>    \/\/ \u753bZoog\u7684\u5934<br \/>\n   fill(255);<br \/>\n       ellipse(  x,y-h\/2   ,w,h);<br \/>\n     }<br \/>\n\u4f7f\u7528translate()\u53ef\u4ee5\u5c06\u4ee3\u7801\u7b80\u5316\u4e3a\uff1a<br \/>\nvoid display()  {<br \/>\n       \/\/ \u5c06\u539f\u70b9(0,0)\u79fb\u81f3(x,y)<br \/>\n        translate(x,y);<br \/>\n       \/\/ \u753bZoog\u7684\u8eab\u4f53<br \/>\n       fill(150);<br \/>\n       rect(0,0,w\/6,h*2);<br \/>\n       \/\/ \u753bZoog\u7684\u5934<br \/>\n       fill(255);<br \/>\n       ellipse(0,-h\/2,w,h);<br \/>\n     }<\/dirtycode><\/p>\n<p>11. \u89c2\u5bdf\u4e4b\u524d\u7684\u4f8b\u5b50\uff0c\u4f60\u4f1a\u53d1\u73b0\u6211\u4eec\u8d4b\u4e88\u4e86<em>size()<\/em>\u51fd\u6570\u7b2c\u4e09\u4e2a\u5f15\u6570\uff0c\u8fd9\u4ee3\u8868\u7ed8\u5236\u6a21\u5f0f\u3002\u9ed8\u8ba4\uff08\u4e0d\u5199\uff09\u4e3aJAVA2D\uff0c\u662f\u7684\uff0c\u987e\u540d\u601d\u4e49\uff0c\u8fd9\u662f\u4e00\u4e2a\u7ed8\u52362D\u56fe\u50cf\u7684\u6a21\u5f0f\u3002\u8981\u7ed8\u52363D\u56fe\u5f62\uff0c\u6709\u4ee5\u4e0b\u4e24\u4e2a\u65b9\u5f0f\uff1a<br \/>\n\u25ce P3D\u2014\u2014Processing\u5f00\u53d1\u8005\u521b\u9020\u7684\u4e00\u4e2a3D\u6e32\u67d3\u5668\u3002\u6709\u4e00\u70b9\u9700\u8981\u6ce8\u610f\uff0cP3D\u4e0d\u652f\u6301\u5e73\u6ed1\u6548\u679c\uff08\u901a\u8fc7<em>smooth()<\/em>\u51fd\u6570\u5b9e\u73b0\uff09\u3002<br \/>\n\u25ce OPENGL\u2014\u2014\u501f\u52a9\u786c\u4ef6\u52a0\u901f\u76843D\u6e32\u67d3\u5668\u3002\u5982\u679c\u4f60\u7684\u673a\u5668\u6709\u652f\u6301OPENGL\u7684\u663e\u5361\u88c5\u8f7d\uff0c\u4f60\u4fbf\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u6a21\u5f0f\u3002\u56e0\u4e3a\u5728\u6e32\u67d3\u901f\u5ea6\u4e0a\u7684\u4f18\u52bf\uff0c\u5b83\u5728\u5728\u9ad8\u5206\u8fa8\u7387\u7a97\u53e3\u5c55\u793a\u5927\u91cf\u5f62\u72b6\u65f6\u88ab\u63a8\u8350\u4f7f\u7528\u3002\u800c\u4e14\u7ecf\u8fc7\u5bf9\u6bd4\uff0c\u6211\u53d1\u89c9OPENGL\u6a21\u5f0f\u7684\u786e\u6bd4P3D\u6a21\u5f0f\u7684\u663e\u50cf\u66f4\u5e73\u6ed1\u3002<\/p>\n<p>12. \u8981\u4f7f\u7528OPENGL\u6a21\u5f0f\uff0c\u4f60\u8fd8\u9700\u5b9e\u73b0\u5bfc\u5165OPENGL\u5e93\u3002Sketch -> Import Library -> OpenGL \u6216 \u624b\u5199 import processing.opengl.*; \u5747\u53ef\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002<\/p>\n<p>13. \u9664\u4e86\u4e4b\u524d\u6559\u8fc7\u7684\u7ed8\u5236\u77e9\u5f62\u3001\u5706\u5f62\u3001\u70b9\u3001\u7ebf\u7b49\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528<br \/>\n<em>beginShape()<\/em>, <em>endShape()<\/em>, \u548c<em>vertex()<\/em>\u51fd\u6570\u521b\u5efa\u6211\u4eec\u81ea\u5df1\u60f3\u8981\u7684\u5f62\u72b6\u3002<br \/>\n\u77e9\u5f62\uff1a<br \/>\n<dirtycode:noclick>rect(50,50,100,100);<\/dirtycode><br \/>\n\u7b49\u540c\u4e8e\uff1a<br \/>\n<dirtycode:noclick>beginShape();<br \/>\nvertex(50,50);<br \/>\nvertex(150,50);<br \/>\nvertex(150,150);<br \/>\nvertex(50,150);<br \/>\nendShape(CLOSE);<\/dirtycode><br \/>\n\u662f\u7684\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc\u663e\u5f97\u6bd4\u539f\u5148\u66f4\u52a0\u590d\u6742\uff0c\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u5728\u7ed8\u5236\u4e0d\u89c4\u5219\u56fe\u5f62\u6216\u591a\u8fb9\u5f62\u7684\u65f6\u5019\u662f\u5fc5\u5907\u7684\u3002<\/p>\n<p>14. <em>beginShape()<\/em>\u8868\u793a\u6211\u4eec\u5c06\u5f00\u59cb\u7528\u6570\u4e2a\u9876\u70b9\uff08vertex\uff09\u7ed8\u5236\u6211\u4eec\u7684\u81ea\u5b9a\u4e49\u5f62\u72b6\uff0c<em>vertex()<\/em>\u5f53\u7136\u662f\u7528\u6765\u6807\u6ce8\u6211\u4eec\u591a\u8fb9\u5f62\u5185\u5404\u4e2a\u9876\u70b9\u7684\u4f4d\u7f6e\uff0c<em>endShape()<\/em>\u8868\u660e\u6211\u4eec\u5df2\u5b8c\u6210\u4e86\u9876\u70b9\u6dfb\u52a0\uff0c\u5176\u5f15\u6570CLOSE\u8868\u660e\u8fd9\u4e2a\u5f62\u72b6\u5e94\u5f53\u88ab\u5173\u95ed\uff0c\u5373\uff0c\u6700\u540e\u4e00\u4e2a\u9876\u70b9\u5c06\u4e0e\u7b2c\u4e00\u4e2a\u9876\u70b9\u76f8\u8fde\u3002\u53c2\u9605Processing\u7ad9\u70b9\u53c2\u8003\u83b7\u53d6\u66f4\u591a\u5173\u4e8e\u8fd9\u4e09\u4e2a\u51fd\u6570\u7684\u8c03\u7528\u65b9\u6cd5\u3002<\/p>\n<p>15. \u4f60\u53ef\u4ee5\u4f7f\u7528\u5f15\u6570\u9650\u5236<em>beginShape()<\/em>\u7ed8\u5236\u7684\u56fe\u50cf\uff0c\u6bd4\u5982LINES\uff0cTRIANGLES\u7b49\u7b49\u3002<\/p>\n<p>16. \u53e6\u5916\uff0c\u4f60\u53ef\u4ee5\u7528<em>curveVertex()<\/em>\u66ff\u4ee3<em>vertex()<\/em>\uff0c\u8fd9\u5c06\u7528\u66f2\u7ebf\u66ff\u4ee3\u76f4\u7ebf\u3002\u6ce8\u610f\uff0c\u4f7f\u7528curveVertex()\u65f6\uff0c\u7b2c\u4e00\u4e2a\u9876\u70b9\u548c\u6700\u540e\u4e00\u4e2a\u9876\u70b9\u5c06\u4e0d\u4f1a\u88ab\u663e\u793a\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8fd9\u4e24\u70b9\u8981\u88ab\u7528\u6765\u5b9a\u4e49\u5f2f\u66f2\u7387\u3002<\/p>\n<p>17. \u8ba9\u6211\u4eec\u7528<em>beginShape() ,  endShape() ,  \u548cvertex()<\/em>\u753b\u4e00\u4e2a\u7acb\u4f53\u7684\u91d1\u5b57\u5854\uff0c\u5171\u4e94\u9762\uff0c\u56db\u9762\u4e09\u89d2\u5f62\uff0c\u5e95\u5ea7\u4e00\u4e2a\u77e9\u5f62\u3002<br \/>\n<figure id=\"attachment_683\" aria-describedby=\"caption-attachment-683\" style=\"width: 577px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-41.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-41.gif\" alt=\"\u867d\u7136\u9ebb\u70e6\uff0c\u4f46\u6211\u5efa\u8bae\u4f60\u5728\u8349\u7a3f\u7eb8\u4e0a\u753b\u51fa\u4e0a\u8ff0\u8bf8\u70b9\uff0c\u4ee5\u5e2e\u52a9\u4f60\u7406\u89e3\u5b83\u4eec\u7684\u7a7a\u95f4\u4f4d\u7f6e\u5173\u7cfb\" title=\"14-4\" width=\"577\" height=\"269\" class=\"size-full wp-image-683\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-41.gif 577w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-41-300x139.gif 300w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/a><figcaption id=\"caption-attachment-683\" class=\"wp-caption-text\">\u867d\u7136\u9ebb\u70e6\uff0c\u4f46\u6211\u5efa\u8bae\u4f60\u5728\u8349\u7a3f\u7eb8\u4e0a\u753b\u51fa\u4e0a\u8ff0\u8bf8\u70b9\uff0c\u4ee5\u5e2e\u52a9\u4f60\u7406\u89e3\u5b83\u4eec\u7684\u7a7a\u95f4\u4f4d\u7f6e\u5173\u7cfb<\/figcaption><\/figure><br \/>\n<dirtycode>void setup() {<br \/>\n  size(200,200,P3D);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<\/p>\n<p>  \/\/ \u91d1\u5b57\u5854\u7684\u9876\u70b9\u76f8\u5bf9\u4e8e\u4e00\u4e2a\u4e2d\u70b9\u7ed8\u5236<br \/>\n  \/\/ \u56e0\u6b64\uff0c\u6211\u4eec\u547c\u53ebtranslate()\u6765\u5c06\u91d1\u5b57\u5854\u653e\u5728\u7a97\u53e3\u9002\u5b9c\u4f4d\u7f6e.<br \/>\n  \/\/ \u4e00\u4e2a\u7a0d\u597d\u4e00\u70b9\u7684\u9009\u62e9\u4e5f\u8bb8\u662f\u5c06\u4f4d\u79fb\u653e\u5165drawPyramid()\u51fd\u6570\u5e76\u5c06x,y,z\u4f20\u9012\u4e3a\u5f15\u6570<br \/>\n  translate(100,100,0);<br \/>\n  drawPyramid(150);<br \/>\n}<\/p>\n<p>\/\/ \u8fd9\u4e2a\u51fd\u6570\u5728\u4e2d\u70b9\u5468\u56f4\u7684\u5f39\u6027\u8ddd\u79bb\u5185\u8bbe\u7f6e\u91d1\u5b57\u5854\u7684\u9876\u70b9,<br \/>\n\/\/ \u8fd9\u4e2a\u5f39\u6027\u8ddd\u79bb\u53d6\u51b3\u4e8e\u4f20\u9012\u7ed9\u5b83\u7684\u5f15\u6570\u7684\u503c.<br \/>\nvoid drawPyramid(int t) {<br \/>\n  stroke(0);<\/p>\n<p>  \/\/ \u8fd9\u4e2a\u91d1\u5b57\u5854\u6709\u56db\u9762\uff0c\u6bcf\u9762\u88ab\u7ed8\u5236\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684\u4e09\u89d2\u5f62<br \/>\n  \/\/ \u6bcf\u9762\u6709\u4e09\u4e2a\u9876\u70b9\uff0c\u5f62\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\u7684\u5f62\u72b6<br \/>\n  \/\/ \u53c2\u6570&#8221; t &#8221; \u51b3\u5b9a\u4e86\u4e09\u89d2\u5f62\u7684\u5927\u5c0f\u3002<\/p>\n<p>  beginShape(TRIANGLES);<br \/>\n  fill(255,150); \/\/ \u6ce8\u610f\u6bcf\u4e2a\u591a\u8fb9\u5f62\u90fd\u53ef\u4ee5\u5177\u6709\u81ea\u5df1\u7684\u989c\u8272.<br \/>\n  vertex(-t,-t,-t);<br \/>\n  vertex( t,-t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  fill(150,150);<br \/>\n  vertex( t,-t,-t);<br \/>\n  vertex( t, t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  fill(255,150);<br \/>\n  vertex( t, t,-t);<br \/>\n  vertex(-t, t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  fill(150,150);<br \/>\n  vertex(-t, t,-t);<br \/>\n  vertex(-t,-t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  endShape();<br \/>\n}<\/dirtycode><\/p>\n<p>18. \u662f\u7684\uff0c\u4e0a\u4f8b\u7ed3\u679c\u4f60\u62ff\u7ed9\u5176\u4ed6\u4efb\u4f55\u4eba\u770b\uff0c\u4ee5\u90a3\u4e2a\u89c6\u89d2\u4eba\u4eba\u90fd\u4e0d\u4f1a\u89c9\u5f97\u90a3\u662f\u4e00\u4e2a\u7acb\u4f53\u7684\u91d1\u5b57\u5854\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5b83\u8f6c\u52a8\u4e00\u4e0b\u3002\u7136\u540e\u5728\u540e\u8fb9\u7684\u5b66\u4e60\u4e2d\uff0c\u6211\u4eec\u8981\u6a21\u62df\u4e00\u4e2a\u65e5\u5730\u6708\u65cb\u8f6c\u7cfb\u7edf\u3002\u5148\u8bb0\u4e0b\u4e09\u6761\u89c4\u5219\uff1a<br \/>\n\u25ce \u5f62\u72b6\u5728p5\u5185\u88ab<em>rotate()<\/em>\u51fd\u6570\u8f6c\u52a8\u3002<br \/>\n\u25ce <em>rotate()<\/em>\u51fd\u6570\u4f7f\u7528\u4e00\u4e2a\u5f15\u6570\uff0c\u4ee5\u5f27\u5ea6\u6765\u8861\u91cf\u7684\u89d2\u5ea6<br \/>\n\u25ce <em>rotate()<\/em>\u51fd\u6570\u4ee5\u987a\u65f6\u9488\u65b9\u5411\u8f6c\u52a8\u5f62\u72b6\u3002<\/p>\n<p><figure id=\"attachment_681\" aria-describedby=\"caption-attachment-681\" style=\"width: 377px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-5.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-5.gif\" alt=\"14-5\" title=\"14-5\" width=\"377\" height=\"289\" class=\"size-full wp-image-681\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-5.gif 377w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-5-300x229.gif 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/a><figcaption id=\"caption-attachment-681\" class=\"wp-caption-text\">14-5<\/figcaption><\/figure><br \/>\n19. \u5982\u679c\u6211\u4eec\u60f3\u8981\u5c06\u4e00\u4e2a\u77e9\u5f62\u65cb\u8f6c45\u00b0\uff0c\u8fd9\u4e48\u5199\uff1a<br \/>\n<dirtycode:noclick>rotate(radians(45));<br \/>\nrectMode(CENTER);<br \/>\nrect(width\/2,height\/2,100,100); <\/dirtycode><br \/>\n\u7ed3\u679c\u5c06\u662f\u9519\u8bef\u7684\u3002\u4e3a\u4ec0\u4e48\uff1f\u8fd9\u91cc\u6211\u4eec\u8981\u8bb0\u4f4f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7279\u6027\uff0cp5\u5185\u7684\u65cb\u8f6c\u662f\u2014\u2014\u5f62\u72b6\u6c38\u8fdc\u56f4\u7ed5\u539f\u70b9\u65cb\u8f6c\u3002\u4e0a\u4f8b\u5185\u7684\u539f\u70b9\u5728\u54ea\u91cc\uff1f\u5de6\u4e0a\u89d2\uff01\u539f\u70b9\u6ca1\u6709\u7ecf\u8fc7\u4f4d\u79fb\uff0c\u56e0\u6b64\u77e9\u5f62\u5e76\u4e0d\u56f4\u7ed5\u5b83\u7684\u4e2d\u5fc3\u65cb\u8f6c\uff0c\u800c\u662f\u56f4\u7ed5\u5de6\u4e0a\u89d2\u65cb\u8f6c\u3002<\/p>\n<p>20. \u5f53\u7136\uff0c\u4e5f\u8bb8\u6709\u4e00\u5929\u4f60\u4f1a\u505a\u90a3\u79cd\u9700\u8981\u5c06\u56fe\u5f62\u56f4\u7ed5\u5de6\u4e0a\u89d2\u65cb\u8f6c\u7684\u9879\u76ee\uff0c\u4f46\u662f\u5728\u90a3\u4e00\u5929\u5230\u6765\u4e4b\u524d\uff0c\u4f60\u5c06\u59cb\u7ec8\u9700\u8981\u5728\u65cb\u8f6c\u524d\u5c06\u539f\u70b9\u79fb\u5230\u5408\u9002\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u518d\u663e\u793a\u77e9\u5f62\u3002\u662f\u7684\uff0c<br \/>\n<em>translate()<\/em>\u5c06\u5728\u6b64\u523b\u62ef\u6551\u4f60\u3002<br \/>\n<dirtycode:noclick>translate(width\/2,height\/2);<br \/>\nrotate(radians(45));<br \/>\nrectMode(CENTER);<br \/>\nrect(0,0,100,100);<\/dirtycode><br \/>\n\u54e6\uff01\u662f\u7684\uff01\u6211\u4eec\u60f3\u505a\u7684\u6b63\u662f\u8fd9\u6837\uff01<br \/>\n\u6211\u4eec\u8fd8\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u4ee3\u7801\u6269\u5c55\u4e00\u4e0b\uff0c\u7528mouseX\uff08\u5f53\u7136\u4e5f\u53ef\u4ee5\u662fmouseY\uff09\u7684\u503c\u6765\u8ba1\u7b97\u4e00\u4e2a\u65cb\u8f6c\u7684\u89d2\u5ea6\u51fa\u6765\u3002<br \/>\n<dirtycode>void setup() {<br \/>\n  size(200,200);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(0);<br \/>\n  fill(175);<\/p>\n<p>  \/\/ \u5c06\u539f\u70b9\u4f4d\u79fb\u5230\u7a97\u53e3\u4e2d\u5fc3<br \/>\n  translate(width\/2,height\/2);<\/p>\n<p>  \/\/ \u57fa\u4e8e\u9f20\u6807X\u8f74\u7684\u4f4d\u7f6e\u548c\u7a97\u53e3\u5bbd\u5ea6\uff0c\u89d2\u7684\u8303\u56f4\u4ece0\u5230PI<br \/>\n  float theta = PI*mouseX \/ width; <\/p>\n<p>  \/\/ \u4f9d\u89d2theta\u7684\u503c\u65cb\u8f6c<br \/>\n  rotate(theta);<\/p>\n<p>  \/\/ \u7528CENTER\u6a21\u5f0f\u663e\u793a\u77e9\u5f62<br \/>\n  rectMode(CENTER);<br \/>\n  rect(0,0,100,100);<br \/>\n}<\/dirtycode><\/p>\n<figure id=\"attachment_684\" aria-describedby=\"caption-attachment-684\" style=\"width: 197px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-6.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-6.gif\" alt=\"\u4ee5\u76f4\u7ebf\u4e2d\u5fc3\u4e3a\u4e2d\u5fc3\u987a\u65f6\u9488\u65cb\u8f6c\" title=\"14-6\" width=\"197\" height=\"196\" class=\"size-full wp-image-684\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-6.gif 197w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-6-120x120.gif 120w\" sizes=\"auto, (max-width: 197px) 100vw, 197px\" \/><\/a><figcaption id=\"caption-attachment-684\" class=\"wp-caption-text\">\u4ee5\u76f4\u7ebf\u4e2d\u5fc3\u4e3a\u4e2d\u5fc3\u987a\u65f6\u9488\u65cb\u8f6c<\/figcaption><\/figure>\n<p>21. Daniel\u51fa\u9898\uff0c\u753b\u53f3\u8fb9\u8fd9\u6837\u7684\u56fe\uff0c\u8ba9\u56fe\u5f62\u4e00\u8d77\u56f4\u7ed5\u76f4\u7ebf\u4e2d\u5fc3\u65cb\u8f6c\uff0c\u6069\uff0c\u7ec8\u4e8e\u987a\u5229\u505a\u51fa\u6765\u4e86\u3002\u3002\u6700\u5927\u4f53\u4f1a\u8fd8\u662f\uff1a\u8981\u6df1\u523b\u9886\u4f1atranslate()\u7cbe\u795e\u554a\u3002<br \/>\n<dirtycode:noclick>float theta = 0.0;<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  theta += 0.01;<\/p>\n<p>  \/\/ \u5c06\u539f\u70b9\u4f4d\u79fb\u5230\u4e2d\u5fc3<br \/>\n  translate(width\/2,height\/2);<\/p>\n<p>  rotate(theta);<\/p>\n<p>  drawLine(80);<br \/>\n  drawCircle(80);<\/p>\n<p>  \/\/ \u57fa\u4e8e\u7b2c\u4e00\u4e2a\u5706\u7684\u4f4d\u7f6e\u7ee7\u7eed\u4f4d\u79fb\u7b2c\u4e8c\u4e2a\u5706<br \/>\n  translate (160, 0);<br \/>\n  drawCircle(80);<br \/>\n}<\/p>\n<p>void drawLine (int t) {<br \/>\n  stroke(0);<br \/>\n  fill(175);<\/p>\n<p>  beginShape (LINES);<br \/>\n  vertex (-t, 0);<br \/>\n  vertex (t, 0);<br \/>\n  endShape();<br \/>\n}<\/p>\n<p>void drawCircle (int t) {<br \/>\n  stroke(0);<br \/>\n  fill(175);<\/p>\n<p>ellipse(-t, 0, 10, 10);<br \/>\n}<\/dirtycode><\/p>\n<p>22. \u4ee5\u4e0a\u4e8c\u7ef4\u65cb\u8f6c\u5c5e\u4e8e\u56f4\u7ed5Z\u8f74\u65cb\u8f6c\uff0c\u53e6\u5916\u4e3a\u56f4\u7ed5X\u548cY\u8f74\u65cb\u8f6c\u7684\u60c5\u51b5\uff0cp5\u8fd8\u63d0\u4f9b\u7ed9\u6211\u4eec<em>rotateX()<\/em>\u548c<em>rotateY()<\/em>\u4e24\u4e2a\u51fd\u6570\u652f\u6301\uff0c\u7136\u540e\u51fd\u6570<em>rotateZ()<\/em>\u540c\u6837\u5b58\u5728\u5e76\u7b49\u540c\u4e8e<em>rotate()<\/em> \u3002<br \/>\n\u25ce <a href=\"http:\/\/www.learningprocessing.com\/examples\/chapter-14\/example-14-6-rotatez\/\">\u7ed5Z\u8f74\u65cb\u8f6c<\/a><br \/>\n\u25ce <a href=\"http:\/\/www.learningprocessing.com\/examples\/chapter-14\/example-14-7-rotatex\/\">\u7ed5X\u8f74\u65cb\u8f6c<\/a><br \/>\n\u25ce <a href=\"http:\/\/www.learningprocessing.com\/examples\/chapter-14\/example-14-8-rotatey\/\">\u7ed5Y\u8f74\u65cb\u8f6c<\/a><\/p>\n<p>23.  \u662f\u7684\uff0c\u6211\u4eec\u5f53\u7136\u53ef\u4ee5\u5c06\u5404\u79cd\u65cb\u8f6c\u7ed3\u5408\u8fd0\u7528\uff1a<br \/>\n<dirtycode:noclick>void setup() {<br \/>\n  size(200,200,P3D);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(0);<br \/>\n  fill(175);<br \/>\n  translate(width\/2,height\/2);<br \/>\n  rotateX(PI*mouseY\/height);<br \/>\n  rotateY(PI*mouseX\/width);<br \/>\n  rectMode(CENTER);<br \/>\n  rect(0,0,100,100);<br \/>\n}<\/dirtycode><\/p>\n<p>24. OK\uff0c\u73b0\u5728\u56de\u5230\u91d1\u5b57\u5854\u7684\u4f8b\u5b50\uff0c\u4e00\u8d77\u89c1\u8bc13D\u7684\u6548\u679c\u5427\u3002\u672c\u4f8b\u8fd8\u5305\u542b\u53e6\u4e00\u4e2a\u57fa\u4e8e\u5927\u91d1\u5b57\u5854\u504f\u79fb\u7684\u5c0f\u91d1\u5b57\u5854\u3002\u6ce8\u610f\uff0c\u5b83\u4ecd\u7136\u548c\u5927\u91d1\u5b57\u5854\u56f4\u7ed5\u540c\u4e00\u4e2a\u539f\u70b9\u65cb\u8f6c\uff08\u56e0\u4e3a<em>rotateX()<\/em>\u548c<em>rotateY(<\/em>)\u5148\u4e8e\u7b2c\u4e8c\u4e2a<em>translate()<\/em>\u88ab\u547c\u53eb\uff0c\u54e6\u54e6\u54e6\uff0c\u539f\u6765p5\u662f\u8fd9\u4e48\u4e2a\u7531\u4e0a\u800c\u4e0b\u7684\u4ee3\u7801\u6267\u884c\u987a\u5e8f\u5440\uff09<br \/>\n<dirtycode>float theta = 0.0;<\/p>\n<p>void setup() {<br \/>\n  size(200,200,P3D);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  theta += 0.01;<\/p>\n<p>  translate(100,100,0);<br \/>\n  rotateX(theta);<br \/>\n  rotateY(theta);<br \/>\n  drawPyramid(50);<\/p>\n<p>  \/\/ translate the scene again<br \/>\n  translate(50,50,20);<br \/>\n  \/\/ call the pyramid drawing function<br \/>\n  drawPyramid(10);<br \/>\n}<\/p>\n<p>void drawPyramid(int t) {<br \/>\n  stroke(0);<\/p>\n<p>  \/\/ this pyramid has 4 sides, each drawn as a separate triangle<br \/>\n  \/\/ each side has 3 vertices, making up a triangle shape<br \/>\n  \/\/ the parameter &#8221; t &#8221; determines the size of the pyramid<br \/>\n  beginShape(TRIANGLES);<\/p>\n<p>  fill(150,0,0,127);<br \/>\n  vertex(-t,-t,-t);<br \/>\n  vertex( t,-t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  fill(0,150,0,127);<br \/>\n  vertex( t,-t,-t);<br \/>\n  vertex( t, t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  fill(0,0,150,127);<br \/>\n  vertex( t, t,-t);<br \/>\n  vertex(-t, t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  fill(150,0,150,127);<br \/>\n  vertex(-t, t,-t);<br \/>\n  vertex(-t,-t,-t);<br \/>\n  vertex( 0, 0, t);<\/p>\n<p>  endShape();<br \/>\n}<\/dirtycode><\/p>\n<p>25. \u8fd9\u672c\u4e66\u7684\u7f51\u7ad9\u4e0b\u6709\u4e2a\u7559\u8a00\uff0c\u57fa\u4e8e\u8fd9\u4e2a\u4f8b\u5b50\u505a\u51fa\u4e86\u5f88\u7279\u6b8a\u7684\u6548\u679c\uff0c\u89c1<a href=\"http:\/\/www.learningprocessing.com\/examples\/chapter-14\/example-14-10-pyramid\/\">\u8fd9\u4e2a\u9875\u9762<\/a>\u7684\u8bc4\u8bba\u90e8\u5206\u3002<\/p>\n<p>26. \u5728 translate()\u548crotate()\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u51fd\u6570\u53eb\u505ascale() \uff0c\u5b83\u7528\u4e8e\u653e\u5927\u6216\u7f29\u5c0f\u8424\u5e55\u4e0a\u5bf9\u8c61\u7684\u5927\u5c0f\u3002\u548crotate()\u4e00\u6837\uff0c\u6bd4\u4f8b\u6548\u679c\u4e5f\u662f\u57fa\u4e8e\u539f\u4f4d\u7f6e\u3002\u5f15\u6570\uff1a1.0\u5373100%\u3002\u4f8b\u5982\uff1ascale(0.5)  \u4ee5\u539f\u5c3a\u5bf8\u4e00\u534a\u7684\u5927\u5c0f\u7ed8\u5236\u5bf9\u8c61\uff1bscale(3.0)\u5c06\u5bf9\u50cf\u5927\u5c0f\u589e\u52a0\u5230300%\u3002\u4e0b\u4f8b\u5c55\u793a\u4e86\u4e00\u4e2a\u7528scale()\u5b9e\u73b0\u7684\u77e9\u5f62\u589e\u5927\u5b9e\u9a8c\uff1a<br \/>\n<dirtycode>   float r = 0.0;<br \/>\n   void setup()  {<br \/>\n        size(200,200);<br \/>\n    }<br \/>\n   void draw()  {<br \/>\n        background(0);<br \/>\n        \/\/ \u79fb\u4f4d\u5230\u7a97\u53e3\u6b63\u4e2d<br \/>\n        translate(width\/2,height\/2);<br \/>\n        \/\/ \u57fa\u4e8er\u91cd\u6bd4\u4f8b\u5f62\u72b6\u5927\u5c0f<br \/>\n        scale(r);   <\/p>\n<p>        stroke(255);<br \/>\n        fill(100);<br \/>\n        rectMode(CENTER);<br \/>\n        rect(0,0,10,10);  <\/p>\n<p>        r  +=  0.02;<br \/>\n    } <\/dirtycode><br \/>\n\u6ce8\u610f\u4e0a\u4f8b\u4e2d\uff0c<em>scale()<\/em>\u5728\u4f7f\u77e9\u5f62\u53d8\u5927\u7684\u540c\u65f6\u4f7f\u5f97\u8fb9\u6846\u4f34\u968f\u53d8\u7c97\u3002<em>scale()<\/em>\u540c\u6837\u652f\u6301\u4e8c\u4e2a\u6216\u4e09\u4e2a\u5f15\u6570\uff08\u5206\u522b\u4ee3\u8868x,y,z\uff09\u3002<\/p>\n<p>27. \u77e9\u9635\uff08Matrix\uff09\u52a8\u6001\u4fdd\u5b58\u5f53\u524d\u72b6\u6001\u5e76\u968f\u65f6\u53ef\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u8fd9\u6700\u7ec8\u5c06\u4f7f\u5f97\u6211\u4eec\u5728\u4e0d\u5f71\u54cd\u4ed6\u7269\u7684\u60c5\u51b5\u4e0b\u81ea\u7531\u79fb\u52a8\u6216\u65cb\u8f6c\u6211\u4eec\u7684\u5f62\u72b6\u3002\u4f60\u53ef\u4ee5\u547c\u53eb<em>printMatrix()<\/em>\u67e5\u770b\u4efb\u610f\u65f6\u523b\u7684\u77e9\u9635\u3002<\/p>\n<p>28. \u4e00\u4e2a\u6700\u597d\u7684\u8bc1\u660e\u8fd9\u4e2a\u6982\u5ff5\u7684\u4f8b\u5b50\uff0c\u521b\u9020\u4e24\u4e2a\u4ee5\u4e0d\u540c\u901f\u5ea6\u548c\u65b9\u5411\u56f4\u7ed5\u5404\u81ea\u4e2d\u5fc3\u65cb\u8f6c\u7684\u77e9\u5f62\u3002\u5728\u8fdb\u884c\u4e2d\uff0c\u6211\u4eec\u5c06\u53d1\u73b0\u9519\u8bef\uff0c\u7136\u540e\u5f15\u5165pushMatrix()\u548cpopMatrix()\u51fd\u6570\u7684\u4ecb\u7ecd\u3002\u5148\u5728\u5de6\u4e0a\u89d2\u753b\u4e00\u4e2a\u7ed5Y\u8f74\u8f6c\u7684\u77e9\u5f62\uff0c\u518d\u5728\u53f3\u4e0b\u89d2\u753b\u4e00\u4e2a \u7ed5Y\u8f74\u8f6c\u7684\u77e9\u5f62\uff0c\u662f\u7684\uff0c\u72ec\u5904\u7684\u65f6\u5019\uff0c\u4e8c\u8005\u90fd\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u662f\u4e00\u65e6\u653e\u5230\u4e00\u5757\uff1a<br \/>\n<dirtycode>    float theta1 = 0;<br \/>\n    float theta2 = 0; <\/p>\n<p>    void setup()  {<br \/>\n    size(200,200,P3D);<br \/>\n     }    <\/p>\n<p>    void draw()  {<br \/>\n    background(255);<br \/>\n    stroke(0);<br \/>\n    fill(175);<br \/>\n    rectMode(CENTER);   <\/p>\n<p>    translate(50,50);<br \/>\n    rotateZ(theta1);<br \/>\n    rect(0,0,60,60); <\/p>\n<p>    theta1  +  =  0.02;   <\/p>\n<p>    translate(100,100);<br \/>\n    rotateY(theta2);<br \/>\n    rect(0,0,60,60);   <\/p>\n<p>    theta2  +  =  0.02;<br \/>\n     } <\/dirtycode><br \/>\n\u8bd5\u8fd0\u884c\u4e00\u4e0b\uff0c\u95ee\u9898\u51fa\u73b0\uff0c\u53f3\u4e0b\u89d2\u7684\u77e9\u5f62\u4e5f\u5f00\u59cb\u56f4\u7ed5\u5de6\u4e0a\u89d2\u7684\u77e9\u5f62\u65cb\u8f6c\uff08\u800c\u4e0d\u662f\u72ec\u81ea\u5728\u53f3\u4e0b\u89d2\u7ed5Y\u8f74\u65cb\u8f6c\uff09\u3002\u8981\u8bb0\u4f4f\uff0c\u6240\u6709\u4f4d\u79fb\u548c\u65cb\u88c5\u90fd\u662f\u57fa\u4e8e\u524d\u4e00\u4e2a\u5750\u6807\u7cfb\u7edf\u7684\u72b6\u6001\u3002\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u80fd\u591f\u8fd8\u539f\u4e4b\u524d\u72b6\u6001\u7684\u77e9\u9635\u7cfb\u7edf\u4ee5\u4f7f\u5f97\u5404\u4e2a\u5f62\u72b6\u53ef\u4ee5\u72ec\u7acb\u8fd0\u52a8\u3002<\/p>\n<p>29. \u4fdd\u5b58\u548c\u8fd8\u539f\u65cb\u8f6c\/\u4f4d\u79fb\u72b6\u6001\u53ef\u4ee5\u88ab<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em> \u5b8c\u6210\u3002push\uff1d\u4fdd\u5b58\uff0cpop\uff1d\u8fd8\u539f\u3002<\/p>\n<p>30. \u4e3a\u4f7f\u5404\u4e2a\u77e9\u5f62\u72ec\u7acb\u65cb\u8f6c\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u4e0b\u5982\u4e0b\u7b97\u6cd5\uff1a<br \/>\n1\uff09\u4fdd\u5b58\u5f53\u524d\u53d8\u5f62\u77e9\u9635\u3002\u8fd9\u662f\u6211\u4eec\u7684\u8d77\u70b9\uff0c\u4ece\uff080,0\uff09\u5e76\u4e14\u6ca1\u6709\u65cb\u8f6c\u5f00\u59cb\u3002<br \/>\n2\uff09\u79fb\u52a8\u5e76\u65cb\u8f6c\u7b2c\u4e00\u4e2a\u77e9\u5f62\u3002<br \/>\n3\uff09\u663e\u793a\u7b2c\u4e00\u4e2a\u77e9\u5f62\u3002<br \/>\n4\uff09\u4ece\u7b2c\u4e00\u6b65\u8fd8\u539f\u77e9\u9635\uff0c\u4f7f\u5176\u4e0d\u53d7\u7b2c\u4e8c\u3001\u4e09\u6b65\u7684\u5f71\u54cd\u3002<br \/>\n5\uff09\u79fb\u52a8\u5e76\u65cb\u8f6c\u7b2c\u4e8c\u4e2a\u77e9\u5f62\u3002<br \/>\n6\uff09\u663e\u793a\u7b2c\u4e8c\u4e2a\u77e9\u5f62\u3002<br \/>\n\u7528\u4ee5\u4e0a\u601d\u8def\u91cd\u5199\u4e0a\u4f8b\uff1a<br \/>\n<dirtycode> float theta1 = 0;<br \/>\n   float theta2 = 0;<br \/>\n   void setup()  {<br \/>\n        size(200,200,P3D);<br \/>\n    }  <\/p>\n<p>   void draw()  {<br \/>\n        background(255);<br \/>\n        stroke(0);<br \/>\n        fill(175);<br \/>\n        rectMode(CENTER);<br \/>\n         pushMatrix(); <\/p>\n<p>        translate(50,50);<br \/>\n        rotateZ(theta1);<br \/>\n        rect(0,0,60,60);<br \/>\n         popMatrix(); <\/p>\n<p>        pushMatrix();<br \/>\n        translate(150,150);<br \/>\n        rotateY(theta2);<br \/>\n        rect(0,0,60,60);<br \/>\n        popMatrix();<br \/>\n        theta1 +=  0.02;<br \/>\n        theta2  +=  0.02;<br \/>\n   }<\/dirtycode><br \/>\n\u5c3d\u7ba1\u6280\u672f\u4e0a\u5e76\u4e0d\u9700\u8981\uff0c\u5728\u7b2c\u4e8c\u4e2a\u77e9\u5f62\u524d\u540e\u52a0<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\uff08\u6bd4\u5982\u5982\u679c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u66f4\u591a\u7684\u5f62\u72b6\uff09\uff0c\u540c\u65f6\u4e5f\u66f4\u5bb9\u6613\u5c06\u5404\u4e2a\u90e8\u5206\u5f53\u4f5c\u4e0d\u540c\u7684\u4e2a\u4f53\u6765\u5bf9\u5f85\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e2a\u4f8b\u5b50\u771f\u7684\u5e94\u5f53\u4ee5\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u6765\u505a\uff0c\u7136\u540e\u662f\u7684\u6bcf\u4e2a\u5bf9\u8c61\u547c\u53eb\u81ea\u5df1\u5404\u81ea\u7684<em>pushMatrix(), translate(), rotate()\u548cpopMatrix()<\/em>\u3002 <\/p>\n<p>31. \u63a5\u4e0b\u6765\u6211\u4eec\u5982\u6cd5\u70ae\u5236\u7528\u6570\u7ec4\u505a\u4e00\u5806\u65cb\u8f6c\u7684\u77e9\u5f62\uff1a<br \/>\n<dirtycode>\/\/ Rotater\u5bf9\u8c61\u6570\u7ec4<br \/>\nRotater[] rotaters;<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<\/p>\n<p>  rotaters = new Rotater[20];<\/p>\n<p>  \/\/ \u968f\u673a\u51b3\u5b9aRotaters\u5404\u5c5e\u6027<br \/>\n  for (int i = 0; i < rotaters.length; i++ ) {\n    rotaters[i] = new Rotater(random(width),random(height),random(-0.1,0.1),random(48));\n  }\n}\n\nvoid draw() {\n  background(255);\n  \n  \/\/ All Rotaters spin and are displayed\n  for (int i = 0; i < rotaters.length; i++ ) {\n    rotaters[i].spin();\n    rotaters[i].display();\n  }\n}\n\n\/\/ \u4e00\u4e2aRotater\u7c7b\nclass Rotater {\n  \n  float x,y;   \/\/ x,y\u4f4d\u7f6e\n  float theta; \/\/ \u65cb\u8f6c\u89d2\u5ea6\n  float speed; \/\/ \u65cb\u8f6c\u901f\u5ea6\n  float w;     \/\/ \u77e9\u5f62\u5927\u5c0f\n  \n  Rotater(float tempX, float tempY, float tempSpeed, float tempW) {\n    x = tempX;\n    y = tempY;\n    \/\/ \u89d2\u5ea6\u603b\u662f\u521d\u59cb\u5316\u4e3a0\n    theta = 0; \n    speed = tempSpeed;\n    w = tempW;\n  }\n  \n  \/\/ \u589e\u5927\u89d2\u5ea6\n  void spin() {\n    theta += speed;\n  }\n  \n  \/\/ \u663e\u793a\u77e9\u5f62\n  void display() {\n    rectMode(CENTER);\n    stroke(0);\n    fill(0,100);\n    \/\/ pushMatrix()\u548cpopMatrix()\u5728\u7c7b\u7684display()\u65b9\u6cd5\u4e2d\u88ab\u547c\u53eb. \n    \/\/ \u8fd9\u6837\uff0c\u6bcf\u4e2aRotater\u5bf9\u8c61\u90fd\u5c06\u5728\u5404\u81ea\u7684\u4f4d\u79fb\u548c\u65cb\u8f6c\u4e0a\u88ab\u6e32\u67d3\u51fa\u6765!\n    pushMatrix(); \n    translate(x,y);\n    rotate(theta);\n    rect(0,0,w,w);\n    popMatrix();\n  }\n}<\/dirtycode><\/p>\n<p>32. \u5d4c\u5957\u4f7f\u7528<em>pushMatrix(<\/em>)\u548c<em>popMatrix()<\/em>\u4f1a\u4ea7\u751f\u6709\u8da3\u7684\u6548\u679c\u3002\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u9886\u57dfpush\uff08\u63a8\uff09\u548cpop\uff08\u9001\uff09\u5e38\u88ab\u7406\u89e3\u4e3a\u201c\u5806\u53e0\uff08stack\uff09\u201d\u3002stack\u662f\u4ec0\u4e48\u5462\uff1f\u8bbe\u60f3\u4e00\u4f4d\u8001\u5e08\u5728\u591c\u665a\u9605\u5377\uff0c\u5c06\u5377\u5b50\u6574\u7406\u4e3a\u4e00\u53e0\uff0c\u90a3\u4e48\u5979\u653e\u5728\u684c\u9762\u4e0a\u7684\u7b2c\u4e00\u5f20\u8bd5\u5377\u5c06\u88ab\u5979\u6700\u540e\u9605\u8bfb\uff0c\u800c\u6700\u540e\u4e00\u5f20\u653e\u4e0a\u7684\u8bd5\u5377\u5c06\u88ab\u5979\u6700\u5148\u9605\u8bfb\u3002\u5728\u5bf9\u5217\u91cc\u8fd9\u6070\u6070\u662f\u53cd\u8fc7\u6765\u7684\u3002\u4e0d\u50cf\u6392\u961f\u4e70\u7535\u5f71\u7968\uff0c\u6392\u5728\u7b2c\u4e00\u4f4d\u7684\u603b\u662f\u7b2c\u4e00\u4e2a\u4e70\u5230\u7968\uff0c\u800c\u6392\u5728\u6700\u540e\u7684\u603b\u662f\u6700\u540e\u4e70\u5230\u7968\u3002push\u610f\u5473\u7740\u5c06\u4e00\u4e9b\u4e1c\u897f\u653e\u5165\u5806\u53e0\u4e2d\u7684\u8fc7\u7a0b\uff0cpop\u53d6\u51fa\u4e00\u4e9b\u4e1c\u897f\u3002\u56e0\u6b64\uff0c\u5728\u7a0b\u5e8f\u4e2d\uff0c<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u7684\u6570\u91cf\u6c38\u8fdc\u662f\u60f3\u7b49\u7684\u3002\u4ee5\u65cb\u8f6c\u7684\u77e9\u5f62\u4e3a\u57fa\u7840\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5d4c\u5957<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u662f\u5982\u4f55\u7684\u6709\u7528\uff0c\u4e0b\u4f8b\u4e3a\u4e00\u4e2a\u884c\u661f\u7cfb\u7edf\u7684\u6a21\u62df\uff1a<br \/>\n<dirtycode>\/\/ \u56f4\u7ed5\u592a\u9633\u53ca\u884c\u661f\u65cb\u8f6c\u7684\u89d2\u5ea6<br \/>\nfloat theta = 0;<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n  smooth();<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(0);<\/p>\n<p>  \/\/ \u4f4d\u79fb\u5230\u7a97\u53e3\u6b63\u4e2d\u7ed8\u5236\u592a\u9633<br \/>\n  translate(width\/2,height\/2);<br \/>\n  fill(255,200,50);<br \/>\n  ellipse(0,0,20,20);<\/p>\n<p>  \/\/ \u5730\u7403\u56f4\u7ed5\u592a\u9633\u65cb\u8f6c<br \/>\n  pushMatrix();<br \/>\n  rotate(theta);<br \/>\n  translate(50,0);<br \/>\n  fill(50,200,255);<br \/>\n  ellipse(0,0,10,10);<\/p>\n<p>  \/\/ \u6708\u4eae#1\u56f4\u7ed5\u5730\u7403\u4f20<br \/>\n  \/\/ \u5728\u7ed8\u5236\u6708\u4eae#1\u524d\u547c\u53eb\u4ee5\u4fdd\u6301\u5176\u4f4d\u79fb\u72b6\u6001<br \/>\n  \/\/<br \/>\n\u8fd9\u6837\uff0c\u6211\u4eec\u4fbf\u80fd\u5728\u7ed8\u5236\u6708\u4eae#2\u524dpop\u5e76\u8fd4\u56de\u5730\u7403\u3002<br \/>\n  \/\/ \u6240\u6709\u6708\u4eae\u90fd\u56f4\u7ed5\u5730\u7403\u65cb\u8f6c (\u5730\u7403\u81ea\u8eab\u540c\u65f6\u56f4\u7ed5\u592a\u9633\u8f6c).<br \/>\n  pushMatrix();<br \/>\n  rotate(-theta*4); \/\/ \u89d2\u5ea6\u4e3a\u8d1f\u5219\u9006\u65f6\u9488\u65cb\u8f6c<br \/>\n  translate(15,0);<br \/>\n  fill(50,255,200);<br \/>\n  ellipse(0,0,6,6);<br \/>\n  popMatrix();<\/p>\n<p>  \/\/ \u6708\u4eae#2\u540c\u6837\u56f4\u7ed5\u5730\u7403\u8f6c<br \/>\n  pushMatrix();<br \/>\n  rotate(theta*2);<br \/>\n  translate(25,0);<br \/>\n  fill(50,255,200);<br \/>\n  ellipse(0,0,6,6);<br \/>\n  popMatrix();<\/p>\n<p>  popMatrix();<\/p>\n<p>  theta += 0.01;<br \/>\n}<\/dirtycode><br \/>\n\u6211\u8bd5\u4e86\u4e00\u4e0b\uff0c\u5c06\u6700\u540e\u4e00\u4e2a<em>popMatrix();<\/em>\u79fb\u5230\u5730\u7403\u4e4b\u540e\u8fd0\u884c\uff0c\u5219\u6240\u6709\u7403\u90fd\u56f4\u7ed5\u7740\u592a\u9633\u65cb\u8f6c\uff0c\u8fd9\u7ed9\u6211\u4eec\u4e00\u4e2a\u542f\u793a\uff0c\u5728\u5d4c\u5957<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u4e2d\uff0c\u65e0\u8bba\u6709\u591a\u5c11\u7ec4<em>pushMatrix(<\/em>)\u548c<em>popMatrix()<\/em>\uff0c\u5b83\u4eec\u7684<em>translate()<\/em>\u90fd\u662f\u57fa\u4e8e\u9996\u5148\u51fa\u73b0\u5728<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u91cc\u8fb9\u7684\u90a3\u4e2a\u5bf9\u8c61\u7684\u4f4d\u7f6e\u3002\u4f60\u53ef\u4ee5\u57fa\u4e8e\u8fd9\u4e00\u70b9\uff0c\u6539\u5199\u4ee3\u7801\uff0c\u4f7f\u5f97\u5728\u5176\u4ed6\u65cb\u8f6c\u90fd\u4e0d\u6539\u53d8\u7684\u60c5\u51b5\u4e0b\u6708\u4eae#1\uff08\u5c06\u5176\u6539\u4e3a\u5176\u4ed6\u989c\u8272\u5e76\u5c06\u65cb\u8f6c\u89d2\u5ea6\u52a0\u5927\u5c06\u80fd\u66f4\u597d\u7684\u770b\u5230\u6548\u679c\uff09\u56f4\u7ed5\u6708\u4eae#2\u65cb\u8f6c\u3002\u662f\u7684\uff0c\u53c8\u662f\u4e00\u4e2a\u5bb9\u6613\u8ba9\u4eba\u5934\u6655\u6df7\u6dc6\u7684\u6982\u5ff5\uff0c\u4f46\u662f\u4f60\u5fc5\u987b\u5f04\u6e05\u695a\u8fd9\u4e9b\u57fa\u7840\u6027\u7684\u4e1c\u897f\u3002<\/p>\n<figure id=\"attachment_685\" aria-describedby=\"caption-attachment-685\" style=\"width: 199px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-8.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-8.gif\" alt=\"\u4ee4\u4eba\u6655\u7729\u7684\u52a8\u6001\u7279\u6548\" title=\"14-8\" width=\"199\" height=\"199\" class=\"size-full wp-image-685\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-8.gif 199w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/14-8-120x120.gif 120w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/a><figcaption id=\"caption-attachment-685\" class=\"wp-caption-text\">\u4ee4\u4eba\u6655\u7729\u7684\u52a8\u6001\u7279\u6548<\/figcaption><\/figure>\n<p>33. <em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u540c\u6837\u53ef\u4ee5\u5728for\u548cwhile\u5faa\u73af\u4e2d\u88ab\u5d4c\u5957\uff0c\u5236\u9020\u725b\u903c\u7684\u7279\u6548\uff0c\u89c1\u4e0b\u4f8b\uff1a<br \/>\n<dirtycode:noclick>float theta = 0;<\/p>\n<p>void setup() {<br \/>\n  size(200, 200);<br \/>\n  smooth();<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(0);<\/p>\n<p>  translate(width\/2,height\/2);<\/p>\n<p>  \/\/ \u75310\u5ea6\u5faa\u73af\u5230360\u5ea6 (2*PI\u5f27\u5ea6)<br \/>\n  for(float i = 0; i < TWO_PI; i += 0.2) {\n    \n    \/\/ Push, \u65cb\u8f6c\u5e76\u753b\u4e00\u6761\u7ebf!\n    \/\/ \u53d8\u5f62\u72b6\u6001\u901a\u8fc7for\u5faa\u73af\u5728\u6bcf\u4e2a\u5faa\u73af\u5f00\u59cb\u4e4b\u521d\u88ab\u4fdd\u5b58\u80cc\u5728\u7ed3\u5c3e\u88ab\u8fd8\u539f\u3002\n    \/\/ \u8bd5\u7740\u5c06\u6240\u6709pushMatrix()\u548cpopMatrix()\u6ce8\u91ca\u6389\u770b\u4e0d\u540c!\n    pushMatrix(); \n    rotate(theta + i);\n    line(0,0,100,0);\n    \n    \/\/ \u75310\u5ea6\u5faa\u73af\u5230360\u5ea6 (2*PI\u5f27\u5ea6)\n    for(float j = 0; j < TWO_PI; j += 0.5) {\n      \/\/ Push, \u65cb\u8f6c\u5e76\u753b\u4e00\u6761\u7ebf!\n      pushMatrix();\n      translate(100,0);\n      rotate(-theta-j);\n      line(0,0,50,0);\n      \/\/ \u5982\u679c\u6211\u4eec\u5b8c\u6210\u4e86\u5185\u90e8\u5faa\u73af, \u5219pop\u6389!\n      popMatrix();\n    }\n    \n    \/\/ \u5982\u679c\u6211\u4eec\u5b8c\u6210\u4e86\u5916\u90e8\u5faa\u73af, \u5219pop\u6389!\n    popMatrix();\n  }\n  \n  theta += 0.01;\n}<\/dirtycode><\/p>\n<p>34. Daniel\u51fa\u9898\uff1a\u628a\u4f60\u7684\u65e0\u8bba\u662f\u91d1\u5b57\u5854\u8fd8\u662f\u7acb\u65b9\u4f53\u505a\u5165\u4e00\u4e2a\u7c7b\uff0c\u8ba9\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u547c\u53eb\u5b83\u4eec\u5404\u81ea\u7684<em>pushMatrix()<\/em>\u548c<em>popMatrix()<\/em>\u3002\u4f60\u80fd\u505a\u4e00\u4e2a\u57283D\u91cc\u5404\u81ea\u72ec\u7acb\u65cb\u8f6c\u7684\u5bf9\u8c61\u7684\u6570\u7ec4\u5417\uff1f<\/p>\n<p>35. \u4e0b\u8fb9\u6211\u4eec\u628a\u672c\u8bfe\u5b66\u5230\u7684\u6240\u6709\u77e5\u8bc6\u6c47\u603b\uff0c\u505a\u4e00\u4e2a\u5fae\u7f29\u592a\u9633\u7cfb\uff0c\u662f\u4e0a\u8fb9\u5730\u6708\u7cfb\u7684\u5347\u7ea7\u7248\uff0c\u5e76\u6709\u4e24\u5927\u6539\u53d8\uff1a<br \/>\n\u25ce \u6bcf\u4e2a\u884c\u661f\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u662fPlanet\u7c7b\u7684\u4e00\u5458<br \/>\n\u25ce \u4e00\u4e2a\u884c\u661f\u6570\u7ec4\u5c06\u56f4\u7ed5\u592a\u9633\u65cb\u8f6c<br \/>\n<dirtycode>\/\/ \u4e00\u4e2a\u75318\u4e2a\u884c\u661f\u5bf9\u8c61\u7ec4\u6210\u7684\u6570\u7ec4<br \/>\nPlanet[] planets = new Planet[8];<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n  smooth();<\/p>\n<p>  \/\/ \u884c\u661f\u5bf9\u8c61\u7528\u8ba1\u6570\u5668\u53d8\u91cf\u521d\u59cb\u5316<br \/>\n  for (int i = 0; i < planets.length; i++ ) {\n    planets[i] = new Planet(20 + i*10,i + 8);\n  }\n}\n\nvoid draw() {\n  background(255);\n  \n  \/\/ \u7ed8\u5236\u592a\u9633\n  pushMatrix();\n  translate(width\/2,height\/2);\n  stroke(0);\n  fill(255);\n  ellipse(0,0,20,20);\n  \n  \/\/ \u7ed8\u5236\u6240\u6709\u884c\u661f\n  for (int i = 0; i < planets.length; i++ ) {\n    planets[i].update();\n    planets[i].display();\n  }\n  popMatrix();\n}\n\nclass Planet {\n  \/\/ \u6bcf\u4e2a\u884c\u661f\u5bf9\u8c61\u90fd\u6301\u7eed\u8bb0\u5f55\u5176\u65cb\u8f6c\u89d2\u5ea6.\n  float theta;      \/\/ \u7ed5\u65e5\u65cb\u8f6c\n  float diameter;   \/\/ \u884c\u661f\u5927\u5c0f\n  float distance;   \/\/ \u8ddd\u592a\u9633\u8ddd\u79bb\n  float orbitspeed; \/\/ \u65cb\u8f6c\u901f\u5ea6\n  \n  Planet(float distance_, float diameter_) {\n    distance = distance_;\n    diameter = diameter_;\n    theta = 0;\n    orbitspeed = random(0.01,0.03);\n  }\n  \n  void update() {\n    \/\/ \u52a0\u5feb\u65cb\u8f6c\u89d2\u5ea6\n    theta += orbitspeed;\n  }\n  \n  void display() {\n    \/\/ \u5728\u65cb\u8f6c\u548c\u4f4d\u79fb\u524d, \u77e9\u9635\u7684\u72b6\u6001\u88abpushMatrix()\u4fdd\u5b58\u4e0b\u6765.\n    pushMatrix(); \n    \/\/ \u65cb\u8f6c\n    rotate(theta); \n    \/\/ \u4f4d\u79fbdistance\n    translate(distance,0); \n    stroke(0);\n    fill(175);\n    ellipse(0,0,diameter,diameter);\n    \/\/ \u884c\u661f\u4e00\u65e6\u88ab\u7ed8\u5236, \u77e9\u9635\u88abpopMatrix()\u8fd8\u539f\uff0c\u56e0\u6b64\u5176\u4ed6\u884c\u661f\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd.\n    popMatrix(); \n  }\n}<\/dirtycode><\/p>\n<p>36. Daniel\u51fa\u9898\uff1a\u4e3a\u4ee5\u4e0a\u884c\u661f\u5206\u522b\u5236\u4f5c\u4e00\u9897\u536b\u661f\uff0c\u7b54\u6848\u89c1<a href=\"http:\/\/www.learningprocessing.com\/exercises\/chapter-14\/exercise-14-10\/\">\u6b64<\/a>\u3002<\/p>\n<p>37. Daniel\u51fa\u9898\uff1a\u7528<em>sphere()<\/em>\u548c<em>box()<\/em>\u66ff\u4ee3<em>ellipse()<\/em>\uff0c\u4ece\u800c\u4f7f\u5f97\u592a\u9633\u7cfb\u8fdb\u5165\u4e09\u7ef4\u7a7a\u95f4\u3002\u54e6\uff0c\u4ed6\u5f00\u59cb\u8ba9\u6211\u4eec\u5b66\u7740\u53bb\u770bp5\u7684\u5b98\u65b9reference\u4e86\u3002<\/p>\n<p>38. \u8d8a\u6765\u8d8a\u7ed5\u4e86\u3002\u600e\u4e48\u529e \ud83d\ude41<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. z\u8f74\u6307\u4efb\u610f\u4e00\u70b9\u7684\u6df1\u5ea6\u3002\u8fd9\u8c8c\u4f3c\u5f88\u62bd\u8c61\uff0c\u8fd9\u4e48\u7406\u89e3\u5427\uff0cx\u8f74\u548cy\u8f74\u5206\u522b\u4ee3\u8868\u8424\u5e55\u7684\u5bbd\u548c\u9ad8\uff0c\u90a3\u4e48z\u8f74\u5c31\u4f4d\u4e8e\u4f60\u8424\u5e55\u7684\u80cc\u540e\uff08\u8d1f\u503c\uff09\u6216\u4e4b\u524d\uff08\u6b63\u503c\uff09\u3002 2. \u7528\u4e8c\u7ef4\u7684\u65b9\u5f0f\u4e5f\u53ef\u4ee5\u505a\u51fa\u4e09\u7ef4\u7684\u6548\u679c\uff0c\u6bd4\u5982\u4e0b\u4f8b\u5c55\u793a\u4e00\u4e2a\u7531\u5c0f\u53d8\u5927\u7684\u77e9\u5f62\uff0c\u770b\u8d77\u6765\u5c31\u50cf\u5b83\u4ece\u8fdc\u5904\u5411\u6211\u4eec\u8d70\u6765\uff1a float r = 8; void setup() { size(200,200); } void draw() { background(255); \/\/ \u5728\u8424\u5e55\u4e2d\u592e\u663e\u793a\u4e00\u4e2a\u77e9\u5f62 stroke(0); fill(175); rectMode(CENTER); rect(width\/2,height\/2,r,r); \/\/ \u589e\u5927\u77e9\u5f62 r++ ; \/\/ \u53cd\u590d\u5f00\u542f\u77e9\u5f62\u7684\u52a8\u6001 if (r > width) { r = 0; } } 3. \u5e78\u8fd0\u7684\u662f\uff0cProcessing\u61c2\u5f97\u900f\u89c6\uff0c\u5e76\u9009\u53d6\u9002\u5b9c\u7684\u4e8c\u7ef4\u50cf\u7d20\u6765\u521b\u5efa\u4e09\u7ef4\u6548\u679c\u3002\u6211\u4eec\u5e94\u5f53\u8ba4\u8bc6\u5230\uff0c\u5728\u6211\u4eec\u8fdb\u51653D\u50cf\u7d20\u5750\u6807\u7684\u540c\u65f6\uff0c\u4e00\u90e8\u5206\u7684\u63a7\u5236\u5fc5\u987b\u4ea4\u7531p5\u7684\u6e32\u67d3\u5668\u6765\u5b8c\u6210\u3002\u4f60\u4e0d\u5728\u80fd\u50cf\u63a7\u52362D\u56fe\u5f62\u90a3\u6837\u7cbe\u786e\u7684\u63a7\u5236\u5b83\u4eec\u7684\u50cf\u7d20\u4f4d\u7f6e\uff0c\u56e0\u4e3aXY\u4f4d\u7f6e\u5c06\u88ab\u8c03\u6574\u7528\u6765\u8ba1\u7b973D\u900f\u89c6\u3002 4. \u4e0b\u56fe\u4e3a\u7b1b\u5361\u5c143D\u7cfb\u7edf\u7684\u5750\u6807\u56fe\u793a\uff1a 5. \u6ce8\u610f\uff0c\u8fd9\u4e48\u5199\u662f\u9519\u8bef\u7684\uff1a rect(x, y, z, w, h); 6. \u5728p5\u7684\u4e16\u754c\u4e3a\u5f62\u72b6\u4f7f\u75283D\u5750\u6807\uff0c\u6211\u4eec\u5fc5\u987b\u5b66\u4e60\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\uff0c\u53eb\u505atranslate()\u3002\u51fd\u6570translate()\u79fb\u52a8\u539f\u70b9\u2014(0,0)\u2014\u76f8\u5bf9\u5176\u4e4b\u524d\u72b6\u6001\u3002\u6211\u4eec\u77e5\u9053\u5f53\u4e00\u4e2asketch\u5f00\u59cb\u8fd0\u884c\uff0c\u539f\u70b9\u4f4d\u4e8e\u8424\u5e55\u5de6\u4e0a\u89d2\u3002\u5982\u679c\u6211\u4eec\u5199translate(50,50)\uff0c\u7ed3\u679c\u5c06\u5982\u4e0b\u56fe\u6240\u793a\uff1a \u53e6\u5916\uff0c\u6bcf\u5f53\u8fd0\u884c\u4e00\u6b21draw()\uff0c\u539f\u70b9\u90fd\u4f1a\u5c06\u5176\u91cd\u7f6e\u56de\u8424\u5e55\u5de6\u4e0a\u89d2\u3002 7. \u770b\u8fd9\u4e2a\u4f8b\u5b50\uff1a [&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-673","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\/673","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=673"}],"version-history":[{"count":7,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/673\/revisions"}],"predecessor-version":[{"id":688,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/673\/revisions\/688"}],"wp:attachment":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}