{"id":614,"date":"2009-11-03T23:48:13","date_gmt":"2009-11-03T15:48:13","guid":{"rendered":"http:\/\/test999.eblhost.com\/blog\/?p=614"},"modified":"2009-11-04T00:28:46","modified_gmt":"2009-11-03T16:28:46","slug":"processing%ef%bc%9a%e6%95%b0%e5%ad%a6%ef%bc%88%e4%b8%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/learn.travelchinawith.me\/?p=614","title":{"rendered":"Processing\uff1a\u6570\u5b66\uff08\u4e0b\uff09"},"content":{"rendered":"<p>14. \u6211\u4eec\u76f4\u89c9\u4e0a\u4e60\u60ef\u4ee5\u5ea6\u6570\u6765\u8003\u8651\u89d2\u3002\u4f46Processing\u5374\u8981\u6c42\u6211\u4eec\u7528\u5f27\u5ea6\u6765\u5236\u4f5c\u4e00\u4e2a\u89d2\u3002<\/p>\n<figure id=\"attachment_629\" aria-describedby=\"caption-attachment-629\" style=\"width: 385px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-1.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-629\" title=\"pr13-1\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-1.gif\" alt=\"\u5f27\u5ea6\" width=\"385\" height=\"269\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-1.gif 385w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-1-300x209.gif 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/a><figcaption id=\"caption-attachment-629\" class=\"wp-caption-text\">\u5f27\u5ea6<\/figcaption><\/figure>\n<p>\u89d2\u5ea6\u3001\u5f27\u5ea6\u8f6c\u6362\u516c\u5f0f\uff1a<br \/>\n<span style=\"text-decoration: underline;\"> \u5f27\u5ea6 \uff1d 2 * PI * (\u89d2\u5ea6\/360)<\/span><br \/>\n\u5e78\u8fd0\u7684\u662f\uff0c\u82e5\u6211\u4eec\u4e60\u60ef\u4e86\u4ee5\u89d2\u5ea6\u6765\u8003\u8651\u89d2\u800c\u53c8\u5fc5\u987b\u4ee5\u5f27\u5ea6\u5199\u4ee3\u7801\uff0cProcessing\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86<em><span style=\"color: #888888;\">radians()<\/span><\/em>\u51fd\u6570\u81ea\u52a8\u5c06\u89d2\u5ea6\u503c\u8f6c\u5316\u4e3a\u5f27\u5ea6\u503c\u3002\u53e6\u5916\uff0c\u5e38\u6570PI\u548cTWO_PI\u4e5f\u53ef\u4ee5\u73b0\u6210\u4f7f\u7528\uff08\u5206\u522b\u7b49\u4e8e180 \u00b0  \u548c 360 \u00b0 \uff09\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c06\u4f7f\u5f62\u72b6\u65cb\u8f6c60 \u00b0  \u3002<br \/>\n<dirtycode:noclick>float angle = radians(60);<br \/>\nrotate(angle);<\/dirtycode><\/p>\n<p>15. \u590d\u4e60\u4e00\u4e0b\uff0c\u6570\u5b66\u5e38\u6570PI (\u6216 \u03c0 )\u662f\u5706\u5468\u4e0e\u5176\u76f4\u5f84\u7684\u6bd4\u7387\uff08\u56f4\u7ed5\u5706\u5468\u7684\u8ddd\u79bb\uff09\u3002\u5b83\u7684\u503c\u7ea6\u7b49\u4e8e3.14159\u3002<\/p>\n<p>16. Sohcahtoa\uff0c\u8c8c\u4f3c\u65e0\u610f\u4e49\u800c\u4e14\u5947\u602a\u7684\u8bcd\uff0c\u786e\u5b9e\u5de8\u5927\u90e8\u5206\u8ba1\u7b97\u673a\u56fe\u5f62\u5de5\u4f5c\u7684\u57fa\u7840\u3002\u5f53\u4f60\u8981\u8ba1\u7b97\u4e00\u4e2a\u89d2\uff0c\u51b3\u5b9a\u70b9\u95f4\u8ddd\uff0c\u9664\u4e86\u5706\u5f62\u6216\u5f27\u5f62\u7b49\u7b49\u7b49\u7b49\u7684\u65f6\u5019\uff0c\u4f60\u4f1a\u53d1\u73b0\u4e09\u89d2\u5b66\u7684\u91cd\u8981\u6027\u3002sohcahtoa\u662f\u8bb0\u5fc6\u4e09\u89d2\u5b66\u57fa\u7840\uff0c\u6b63\u5f26\u3001\u4f59\u5f26\u548c\u6b63\u5207\u7684\u52a9\u8bb0\u7b26\u3002<br \/>\n<span style=\"text-decoration: underline;\"> \u25ce soh : sine \uff1d \u5bf9\u8fb9\/\u659c\u8fb9<br \/>\n\u25ce cah : cosine \uff1d \u90bb\u8fb9\/\u659c\u8fb9<br \/>\n\u25ce toa : tangent \uff1d \u5bf9\u8fb9\/\u90bb\u8fb9<\/span><\/p>\n<p><span style=\"text-decoration: underline;\"> <\/span><\/p>\n<figure id=\"attachment_630\" aria-describedby=\"caption-attachment-630\" style=\"width: 458px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-2.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-630\" title=\"pr13-2\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-2.gif\" alt=\"Sohcahtoa\" width=\"458\" height=\"192\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-2.gif 458w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-2-300x125.gif 300w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/a><figcaption id=\"caption-attachment-630\" class=\"wp-caption-text\">Sohcahtoa<\/figcaption><\/figure>\n<p>17. \u6211\u4eec\u8981\u5728Processing\u5185\u7ed8\u5236\u56fe\u5f62\uff0c\u9700\u8981\u7ed9\u51fa\u5176x\uff0cy\u5750\u6807\u503c\uff0c\u8fd9\u79cd\u5750\u6807\u79f0\u4e3a\u7b1b\u5361\u5c14\u5750\u6807\u3002\u53e6\u5916\u4e00\u79cd\u6709\u7528\u7684\u5750\u6807\u79f0\u4e3a\u6781\u5750\u6807\uff0c\u4ee5\u7a7a\u95f4\u5185\u56f4\u7ed5\u539f\u70b9\u65cb\u8f6c\uff08\u4ee5\u89d2\u5ea6\u8ba1\uff09\u7684\u4ee5\u53ca\u8ddd\u79bb\u539f\u70b9\u7684\u534a\u5f84\u5b9a\u4e49\u7684\u4e00\u4e2a\u70b9\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3ap5\u5185\u4e00\u4e2a\u51fd\u6570\u7684\u5f15\u6570\u3002\u4e09\u89d2\u51fd\u6570\u516c\u5f0f\u5141\u8bb8\u6211\u4eec\u5c06\u8fd9\u4e9b\u5750\u6807\u8f6c\u6362\u4e3a\u7b1b\u5361\u5c14\uff0c\u7136\u540e\u88ab\u7528\u4e8e\u7ed8\u5236\u5f62\u72b6\u3002<\/p>\n<figure id=\"attachment_631\" aria-describedby=\"caption-attachment-631\" style=\"width: 417px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-3.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-631\" title=\"pr13-3\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-3.gif\" alt=\"\u7b1b\u5361\u5c14\u548c\u6781\u5750\u6807\u8f6c\u6362\" width=\"417\" height=\"319\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-3.gif 417w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-3-300x229.gif 300w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/a><figcaption id=\"caption-attachment-631\" class=\"wp-caption-text\">\u7b1b\u5361\u5c14\u548c\u6781\u5750\u6807\u8f6c\u6362<\/figcaption><\/figure>\n<p><span style=\"text-decoration: underline;\">sine(theta) \uff1d y\/r \u2192 y \uff1d r * sine(theta)<br \/>\n<span style=\"-webkit-text-decorations-in-effect: none;\"><span style=\"text-decoration: underline;\">cosine(theta) \uff1d x\/r \u2192 x \uff1d r * cosine(theta)<\/span><\/span><\/span><\/p>\n<p>18. \u6bd4\u5982\uff0c\u5982\u679cr\u4e3a75\uff0c\u89d2\u5ea6\u4e3a45\u00b0  (\u6216 PI\/4 \u5f27\u5ea6)  \uff0c\u6211\u4eec\u53ef\u4ee5\u5982\u4e0b\u8ba1\u7b97x\u548cy\uff1a<br \/>\n<dirtycode:noclick>float r = 75;<br \/>\nfloat theta = PI \/ 4; \/\/ \u6211\u4eec\u540c\u6837\u53ef\u4ee5\u8bf4: float theta = radians(45);<br \/>\nfloat x = r * cos(theta);<br \/>\nfloat y = r * sin(theta);<\/dirtycode><\/p>\n<figure id=\"attachment_632\" aria-describedby=\"caption-attachment-632\" style=\"width: 157px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-4.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-632\" title=\"pr13-4\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-4.gif\" alt=\"\u5706\u5f62\u8f68\u8ff9\" width=\"157\" height=\"155\" \/><\/a><figcaption id=\"caption-attachment-632\" class=\"wp-caption-text\">\u5706\u5f62\u8f68\u8ff9<\/figcaption><\/figure>\n<p>19\u3002 \u8fd9\u6837\u7684\u8f6c\u6362\u5bf9\u6211\u4eec\u6765\u8bf4\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u4f8b\u5982\u8bf4\uff0c\u4f60\u5982\u4f55\u7528\u7b1b\u5361\u5c14\u5750\u6807\u4f7f\u4e00\u4e2a\u5f62\u72b6\u5ef6\u5706\u5f62\u8f68\u8ff9\u8fd0\u52a8\uff1f\u90a3\u5c06\u975e\u5e38\u56f0\u96be\u3002\u4e0d\u8fc7\u4f7f\u7528\u6781\u5750\u6807\u4e5f\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u589e\u52a0\u89d2\u5ea6\u5373\u53ef\uff01<br \/>\n<dirtycode:noclick>\/\/ \u6781\u5750\u6807 (r, theta)\u88ab\u8f6c\u6362\u4e3a\u7b1b\u5361\u5c14\u5750\u6807 (x,y)\u5e76\u5728ellipse()\u51fd\u6570\u5e94\u7528<br \/>\nfloat r = 75;<br \/>\nfloat theta = 0;<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n  background(255);<br \/>\n  smooth();<br \/>\n}<\/p>\n<p>void draw() {<\/p>\n<p>  \/\/ \u6781\u5750\u6807\u5230\u7b1b\u5361\u5c14\u5750\u6807\u7684\u8f6c\u6362<br \/>\n  float x = r * cos(theta);<br \/>\n  float y = r * sin(theta);<\/p>\n<p>  \/\/ \u5728x\uff0cy\u7ed8\u5236\u5706\u5f62<br \/>\n  noStroke();<br \/>\n  fill(0);<br \/>\n  ellipse(x + width\/2, y + height\/2, 16, 16); \/\/ \u4e3a\u7a97\u53e3\u4e2d\u592e\u8fdb\u884c\u8c03\u6574<\/p>\n<p>  \/\/ \u589e\u52a0\u89d2\u5ea6<br \/>\n  theta += 0.01;<br \/>\n}<\/dirtycode><\/p>\n<p>20. Daniel\u51fa\u9898\uff0c\u6765\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u753b\u4e00\u76d8\u4e03\u5f69\u868a\u9999\u5427\u3002\u3002\u6ce8\u610f\uff0c\u53ea\u9700\u5728\u4e0a\u4f8b\u4ee3\u7801\u57fa\u7840\u4e0a\u4fee\u6539\u4e00\u884c\u3001\u589e\u52a0\u4e00\u884c\u5373\u53ef\u3002\u6211\u505a\u51fa\u6765\u4e86\uff0c\u4f60\u5462\uff1f<\/p>\n<figure id=\"attachment_633\" aria-describedby=\"caption-attachment-633\" style=\"width: 199px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-5.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-633\" title=\"pr13-5\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-5.gif\" alt=\"\u4e03\u5f69\u868a\u9999\" width=\"199\" height=\"200\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-5.gif 199w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-5-120x120.gif 120w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/a><figcaption id=\"caption-attachment-633\" class=\"wp-caption-text\">\u4e03\u5f69\u868a\u9999<\/figcaption><\/figure>\n<figure id=\"attachment_634\" aria-describedby=\"caption-attachment-634\" style=\"width: 195px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-8.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-634\" title=\"pr13-8\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-8.gif\" alt=\"\u949f\u6446\" width=\"195\" height=\"190\" \/><\/a><figcaption id=\"caption-attachment-634\" class=\"wp-caption-text\">\u949f\u6446<\/figcaption><\/figure>\n<p>21. \u6b63\u5f26\u66f2\u7ebf\u662f\u5e73\u6ed1\u7684\uff0c\u5e76\u4e14\u603b\u5728\uff0d1\u548c1\u95f4\u53d8\u5316\u3002\u8fd9\u79cd\u884c\u4e3a\u7c7b\u578b\u79f0\u4e3a\u632f\u52a8\uff0c\u5728\u4e24\u70b9\u95f4\u7684\u5468\u671f\u8fd0\u52a8\uff0c\u4f8b\u5982\u949f\u6446\u3002\u5728p5\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u6b63\u5f26\u51fd\u6570\u7684\u503c\u8d4b\u7ed9\u4e00\u4e2a\u5bf9\u8c61\u7684\u4f4d\u7f6e\u6765\u6a21\u62df\u8fd9\u79cd\u632f\u52a8\u3002\u4e0b\u4f8b\u4e3a\u4e00\u4e2a\u6447\u52a8\u7684\u949f\u6446\u7684\u4ee3\u7801\uff1a<br \/>\n<dirtycode:noclick>float theta = 0.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);<\/p>\n<p>  \/\/ sin()\u51fd\u6570\u7684\u8f93\u51fa\u5728-1\u52301\u95f4\u5e73\u6ed1\u632f\u52a8.<br \/>\n  \/\/ \u901a\u8fc7\u52a01\uff0c\u6211\u4eec\u5f97\u52300\uff5e2\u95f4\u7684\u632f\u52a8.<br \/>\n  \/\/ \u901a\u8fc7\u4e58\u4ee5100\uff08width\/2\uff09\uff0c\u6211\u4eec\u5f97\u52300\uff5e200\u7684\u503c\uff0c\u8fd9\u53ef\u4ee5\u7528\u4e8ex\u4f4d\u7f6e\u3002<br \/>\n  float x = (sin(theta) + 1) * width\/2; <\/p>\n<p>  \/\/ \u5bf9\u4e8e\u6bcf\u6b21\u5faa\u73af\uff0c\u589e\u52a0theta\u3002<br \/>\n  theta += 0.05;<\/p>\n<p>  \/\/ \u7528\u6b63\u5f26\u503c\u7ed8\u5236\u5706\u5f62<br \/>\n  fill(0);<br \/>\n  stroke(0);<br \/>\n  line(width\/2,0,x,height\/2);<br \/>\n  ellipse(x,height\/2,16,16);<br \/>\n}<\/dirtycode><\/p>\n<p>22. Daniel\u51fa\u9898\uff1a\u5c06\u4ee5\u4e0a\u529f\u80fd\u5c01\u88c5\u5165Oscillator\u5bf9\u8c61\uff0c\u83b7\u53d6\u4e00\u4e2aOscillators\u6570\u7ec4\uff0c\u6bcf\u4e2a\u90fd\u56f4\u7ed5x\u548cy\u8f74\u4ee5\u4e0d\u540c\u7684\u6bd4\u7387\u8fd0\u52a8\u3002\u54e6\uff0c\u548c\u4f60\u4e00\u6837\uff0c\u6211\u8fd8\u4e0d\u5927\u4f1a\u7528\u7c7b\uff0c\u56e0\u6b64\u6700\u540e\u5728<a href=\"http:\/\/www.learningprocessing.com\/exercises\/chapter-13\/exercise-13-6\/\" target=\"_blank\">\u8fd9\u91cc<\/a>\u770b\u4e00\u4e0b\u7b54\u6848\u3002\u770b\u5b8c\u8fd8\u662f\u5f88\u6709\u5e2e\u52a9\u7684\uff0c\u4e00\u904d\u904d\u7684\u770b\u8fd9\u4e9b\u7c7b\u4f3c\u4ee3\u7801\uff0c\u5dee\u4e0d\u591a\u4e5f\u80fd\u8bb0\u4e2a\u4e03\u516b\u6210\u4e86\u5427\u3002\u3002<\/p>\n<figure id=\"attachment_635\" aria-describedby=\"caption-attachment-635\" style=\"width: 200px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-7.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-635\" title=\"pr13-7\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-7.gif\" alt=\"\u6b63\u5f26\u8def\u5f84\u7403\u7403\" width=\"200\" height=\"199\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-7.gif 200w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-7-120x120.gif 120w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><figcaption id=\"caption-attachment-635\" class=\"wp-caption-text\">\u6b63\u5f26\u8def\u5f84\u7403\u7403<\/figcaption><\/figure>\n<p>23. \u540c\u6837\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6b63\u5f26\u51fd\u6570\u7684\u8def\u5f84\u4e0a\u7ed8\u5236\u4e00\u5e8f\u5217\u5f62\u72b6\u4ee5\u5b9e\u73b0\u6709\u8da3\u7684\u6548\u679c\u3002<br \/>\n<dirtycode:noclick>float theta = 0.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);<\/p>\n<p>  \/\/ \u589e\u52a0theta<br \/>\n  theta += 0.02;<br \/>\n  noStroke();<br \/>\n  fill(0);<br \/>\n  float x = theta;<\/p>\n<p>   \/\/ \u4e00\u4e2afor\u5faa\u73af\u88ab\u7528\u6765\u7ed8\u5236\u4f9d\u9644\u6b63\u5f26\u6ce2\u8def\u5f84\u7684\u6240\u6709\u70b9 (\u4f7f\u5176\u653e\u5927\u5230\u7a97\u53e3\u50cf\u7d20\u5c3a\u5bf8).<br \/>\n  for (int i = 0; i <= 20; i++) {\n    \/\/ \u57fa\u4e8e\u6b63\u5f26\u51fd\u6570\u8ba1\u7b97y\n    float y = sin(x)*height\/2;\n    \/\/ \u7ed8\u5236\u4e00\u4e2a\u5706\n    ellipse(i*10,y + height\/2,16,16);\n    \/\/ \u987ax\u8f74\u79fb\u52a8\n    x += 0.2;\n  }\n}<\/dirtycode><\/p>\n<p>24. 1975\u5e74\uff0cBenoit Mandelbrot\u521b\u9020\u4e86\u5206\u5f62\uff08fractal\uff09\u4f53\u7cfb\u7528\u4ee5\u5f62\u5bb9\u81ea\u7136\u754c\u4e2d\u90a3\u4e9b\u81ea\u76f8\u4f3c\u7684\u5f62\u72b6\u3002\u4ea7\u751f\u8fd9\u4e9b\u5f62\u72b6\u7684\u4e00\u4e2a\u7a0b\u5e8f\u88ab\u79f0\u4e3a\u9012\u5f52\u6216\u5faa\u73af\uff08recursion\uff09\u3002<\/p>\n<p>25. \u6211\u4eec\u77e5\u9053\u5728draw()\u5185\uff0c\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u547c\u53eb\u53e6\u4e00\u4e2a\u51fd\u6570\u3002\u4f46\u5b83\u4eec\u53ef\u4ee5\u547c\u53eb\u5b83\u4eec\u672c\u8eab\u5417\uff1fdraw()\u53ef\u4ee5\u547c\u53ebdraw()\u5417\uff1f\u5b9e\u9645\u4e0a\uff0c\u5b83\u53ef\u4ee5\uff08\u867d\u7136\u8fd9\u4f1a\u9020\u6210\u6b7b\u5faa\u73af\u7684\u60e8\u70c8\u5c40\u9762..\uff09\u3002\u51fd\u6570\u547c\u53eb\u81ea\u8eab\u4fbf\u662f\u9012\u5f52\u3002\u5728\u6570\u5b66\u4e2d\uff0c\u6700\u666e\u904d\u7684\u4f8b\u5b50\u4fbf\u662f\u9636\u4e58\u3002n\u4e2a\u6570\u7684\u9636\u4e58\uff1a<br \/>\n<span style=\"text-decoration: underline;\"> n! \uff1d n  *  n  \u2013 1 * . . . . * 3 * 2 * 1<br \/>\n0! \uff1d 1<\/span><br \/>\n\u5728p5\u5185\u7528for\u5faa\u73af\u5199\uff1a<br \/>\n<dirtycode:noclick>int factorial(int n)  {<br \/>\n    int f = 1;<br \/>\n    for (int i = 0; i < n; i++ ){  \n        f = f * (i + 1);      \n     }    \n    return f; \n}<\/dirtycode><br \/>\n\u518d\u8fdb\u4e00\u6b65\u89c2\u5bdf\u9636\u4e58\uff1a<br \/>\n<span style=\"text-decoration: underline;\"> 4! \uff1d 4 * 3 * 2 * 1<br \/>\n3! \uff1d 3 * 2 * 1<\/span><br \/>\n\u56e0\u6b64. . . <span style=\"text-decoration: underline;\">4! \uff1d 4 * 3!<\/span><br \/>\n\u518d\u63a8\uff1a<br \/>\n<span style=\"text-decoration: underline;\"> n! \uff1d n  * ( n  \u2013 1)!<br \/>\n1! \uff1d 1<\/span><\/p>\n<p>26. \u9636\u4e58\u7684\u5b9a\u4e49\u5305\u62ec\u9636\u4e58\u5417\uff1f\uff01\u8fd9\u6709\u70b9\u50cf\u8bf4\u201c\u75b2\u5026\u201d\u88ab\u5b9a\u4e49\u4e3a\u201c\u5f53\u4f60\u75b2\u5026\u65f6\u7684\u611f\u53d7\u201d\u3002\u8fd9\u79cd\u5728\u51fd\u6570\u5185\u81ea\u53c2\u7167\u7684\u6982\u5ff5\u88ab\u79f0\u4e3a\u9012\u5f52\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u9012\u5f52\u5199\u4e00\u4e2a\u547c\u53eb\u81ea\u8eab\u9636\u4e58\u7684\u51fd\u6570\u3002<br \/>\n<dirtycode:noclick>     int factorial(int n)  {<br \/>\n       if (n  ==  1)  {<br \/>\n         return 1;<br \/>\n        }  else  {<br \/>\n         return n * factorial(n-1);<br \/>\n        }<br \/>\n      }<\/dirtycode><\/p>\n<p>27. \u4e0b\u56fe\u4e3afractorial(4)\u65f6\u7684\u60c5\u51b5<\/p>\n<figure id=\"attachment_636\" aria-describedby=\"caption-attachment-636\" style=\"width: 457px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-6.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-636\" title=\"pr13-6\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-6.gif\" alt=\"fractorial(4)\" width=\"457\" height=\"233\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-6.gif 457w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-6-300x152.gif 300w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/a><figcaption id=\"caption-attachment-636\" class=\"wp-caption-text\">fractorial(4)<\/figcaption><\/figure>\n<p>28. \u540c\u6837\u7684\u539f\u7406\u53ef\u4ee5\u88ab\u7528\u6765\u7ed8\u5236\u6709\u8da3\u7684\u56fe\u5f62\u3002\u770b\u770b\u63a5\u4e0b\u6765\u7684\u9012\u5f52\u51fd\u6570\u3002<br \/>\n<dirtycode:noclick>void drawCircle(int x, int y, float radius) {<br \/>\n   ellipse(x, y, radius, radius);<br \/>\n   if(radius > 2)  {<br \/>\n      radius *= 0.75f;<br \/>\n       drawCircle(x, y, radius);<br \/>\n     }<br \/>\n} <\/dirtycode><br \/>\n<em><span style=\"color: #808080;\"> drawCircle()<\/span><\/em>\u5e72\u4e86\u4ec0\u4e48\uff1f\u5b83\u7ed8\u5236\u4e00\u4e2a\u5706\uff0c\u7136\u540e\u4ee5\u76f8\u540c\u7684\u53c2\u6570\uff08\u5fae\u5fae\u8c03\u6574\uff09\u547c\u53eb\u81ea\u8eab\u3002\u7ed3\u679c\u5c31\u662f\u4e00\u7cfb\u5217\u5728\u81ea\u8eab\u5185\u7ed8\u5236\u7684\u5706\u5f62\u3002\u6ce8\u610f\u4ee5\u4e0a\u51fd\u6570\u4ec5\u5728\u534a\u5f84\u5927\u4e8e2\u65f6\u9012\u5f52\u547c\u53eb\u81ea\u8eab\u3002\u8fd9\u662f\u4e00\u4e2a\u5173\u952e\u70b9\u3002\u6240\u6709\u9012\u5f52\u51fd\u6570\u5fc5\u987b\u62e5\u6709\u4e00\u4e2a\u63a8\u51fa\u7684\u6761\u4ef6\uff08exit condition\uff09\uff01\u50cf<em><span style=\"color: #808080;\">for<\/span><\/em>\u548c<em><span style=\"color: #808080;\">while<\/span><\/em>\u5faa\u73af\u4e00\u6837\uff0c\u5982\u679c\u6ca1\u6709\u505c\u6b62\u7684\u6761\u4ef6\uff0c\u5219\u5f88\u53ef\u80fd\u4f1a\u51fa\u73b0\u6b7b\u5faa\u73af\u6700\u540e\u4f7f\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<figure id=\"attachment_637\" aria-describedby=\"caption-attachment-637\" style=\"width: 199px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-637\" title=\"pr13-9\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-9.png\" alt=\"\u5206\u5f62\u4e00\" width=\"199\" height=\"198\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-9.png 199w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-9-120x120.png 120w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/a><figcaption id=\"caption-attachment-637\" class=\"wp-caption-text\">\u5206\u5f62\u4e00<\/figcaption><\/figure>\n<p>29. \u8ba9\u6211\u4eec\u8bd5\u7740\u5c06<em><span style=\"color: #808080;\">drawCircle()<\/span><\/em>\u641e\u5f97\u66f4\u590d\u6742\u4e00\u70b9\u70b9\u3002\u7ed8\u5236\u4e00\u4e2a\u5706\u5f62\uff0c\u5e76\u5728\u5176\u5de6\u53f3\u5206\u522b\u7ed8\u5236\u4e24\u4e2a\u5927\u5c0f\u4e3a\u5176\u4e00\u534a\u7684\u5706\uff0c\u5982\u6b64\u53cd\u590d\uff1a<br \/>\n<dirtycode:noclick>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  noFill();<br \/>\n  drawCircle(width\/2,height\/2,100);<br \/>\n}<\/p>\n<p>void drawCircle(float x, float y, float radius) {<br \/>\n  ellipse(x, y, radius, radius);<br \/>\n  if(radius > 2) {<br \/>\n    \/\/ drawCircle()\u547c\u53eb\u81ea\u5df1\u4e24\u6b21\uff0c\u5236\u9020\u4e00\u4e2a\u5206\u652f\u6548\u679c<br \/>\n    \/\/ \u5bf9\u6bcf\u4e2a\u5706\u6765\u8bf4\uff0c\u4e24\u4e2a\u66f4\u5c0f\u7684\u5706\u5206\u522b\u5728\u5176\u4e00\u5de6\u4e00\u53f3\u7ed8\u5236.<br \/>\n    drawCircle(x + radius\/2, y, radius\/2);<br \/>\n    drawCircle(x &#8211; radius\/2, y, radius\/2);<br \/>\n  }<br \/>\n}<\/dirtycode><\/p>\n<figure id=\"attachment_638\" aria-describedby=\"caption-attachment-638\" style=\"width: 128px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-10.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-638\" title=\"pr13-10\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-10.gif\" alt=\"\u5206\u5f62\u4e8c\" width=\"128\" height=\"128\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-10.gif 198w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-10-120x120.gif 120w\" sizes=\"auto, (max-width: 128px) 100vw, 128px\" \/><\/a><figcaption id=\"caption-attachment-638\" class=\"wp-caption-text\">\u5206\u5f62\u4e8c<\/figcaption><\/figure>\n<p>30. \u540c\u6837\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e\u4e0a\u4f8b\u5206\u522b\u518d\u5728\u6bcf\u4e2a\u5706\u7684\u4e00\u4e0a\u4e00\u4e0b\u5404\u589e\u52a0\u4e00\u4e2a\u5706\uff0c\u6548\u679c\u5f88\u7f8e\uff1a<br \/>\n<dirtycode:noclick>void drawCircle(float x, float y, float radius) {<br \/>\n    ellipse(x, y, radius, radius);<br \/>\n    if(radius > 8)  {<br \/>\n         drawCircle(x + radius\/2, y, radius\/2);<br \/>\n         drawCircle(x &#8211; radius\/2, y, radius\/2);<br \/>\n         drawCircle(x, y + radius\/2, radius\/2);<br \/>\n         drawCircle(x, y &#8211; radius\/2, radius\/2);<br \/>\n     }<br \/>\n}<\/dirtycode><\/p>\n<p>31. \u8fd9\u9053\u7ec3\u4e60\u641e\u5f97\u6211\u5f88\u7ea0\u7ed3\uff08\u54e6\uff0c\u770b\u6765\u6ce8\u91ca\u771f\u7684\u5f88\u91cd\u8981\uff0chey\uff0cDaniel\uff0c\u522b\u8bf4\u586b\u4f60\u7559\u7ed9\u6211\u7684\u7a7a\u4e86\uff0c\u5149\u770b\u61c2\u4f60\u7b54\u6848\u7684\u4ee3\u7801\u90fd\u5f88\u96be\u554a- -\uff09\uff0c\u8fd8\u662f\u5c5e\u4e8e\u5bf9\u8c61\u6ca1\u5b66\u597d&#8230;\uff1a<br \/>\n<dirtycode:noclick> void setup()  {<br \/>\n  size(400,200);<br \/>\n  smooth();<br \/>\n}   <\/p>\n<p>void draw()  {<br \/>\n  background(255);<br \/>\n  stroke(0);<br \/>\n  branch(width\/2,height,100);<br \/>\n}   <\/p>\n<p>void branch(float x, float y, float h)  {<br \/>\n  line(x,y,x-h,y-h);<br \/>\n  line(x,y,x+h,y-h);<br \/>\n  if (h > 2) {<br \/>\n    branch(x-h,y-h,h\/2);<br \/>\n    branch(x+h,y-h,h\/2);<br \/>\n  }<br \/>\n}<\/dirtycode><br \/>\n\u6069\uff0c\u7ecf\u8fc7\u534a\u5929\u4e00\u591c\u7684\u601d\u8003\u548c\u8349\u7a3f\uff0c\u6211\u7ec8\u4e8e\u5f04\u660e\u767d\u8fd9\u9898\u4e86\u3002\u3002\u8fd8\u6709\u60f3\u4e0d\u660e\u767d\u7684\u53ef\u4ee5\u95ee\u6211\u3002<\/p>\n<figure id=\"attachment_639\" aria-describedby=\"caption-attachment-639\" style=\"width: 399px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-11.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-639\" title=\"pr13-11\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-11.gif\" alt=\"\u5206\u5f62\u4e09\" width=\"399\" height=\"199\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-11.gif 399w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-11-300x149.gif 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><\/a><figcaption id=\"caption-attachment-639\" class=\"wp-caption-text\">\u5206\u5f62\u4e09<\/figcaption><\/figure>\n<p>32. \u4e4b\u524d\u6211\u4eec\u5b66\u4e60\u7684\u6570\u7ec4\u662f\u4e00\u7ef4\u7684\uff0c\u6bd4\u5982\uff1a<br \/>\n<dirtycode:noclick>int[] myArray = { 0,1,2,3};<\/dirtycode><br \/>\n\u5176\u5b9e\u5b83\u4e5f\u53ef\u4ee5\u591a\u7ef4\uff0c\u6bd4\u5982\u4e8c\u7ef4\u7684\u6570\u7ec4\u770b\u8d77\u6765\u5c31\u50cf\u8fd9\u6837\uff1a<br \/>\n<dirtycode:noclick>int[][] myArray = {  { 0,1,2,3},{3,2,1,0},{3,5,6,1},{3,8,3,4} } ;<\/dirtycode><br \/>\n\u53ef\u4ee5\u7406\u89e3\u4e3a\uff0c\u6570\u7ec4\u7684\u6570\u7ec4\u3002\u800c\u4e09\u7ef4\u6570\u7ec4\u4fbf\u53ef\u7406\u89e3\u4e3a\u6570\u7ec4\u7684\u6570\u7ec4\u7684\u6570\u7ec4\u3002<\/p>\n<p>33. \u51fa\u4e8e\u6211\u4eec\u7684\u76ee\u7684\uff0c\u6211\u4eec\u6700\u597d\u5c06\u4e8c\u7ef4\u6570\u7ec4\u770b\u505a\u4e00\u4e2a\u77e9\u9635\uff0c\u5199\u505a\uff1a<br \/>\n<dirtycode:noclick>int[][] myArray = { {0, 1, 2, 3},<br \/>\n                             { 3, 2, 1, 0},<br \/>\n                             { 3, 5, 6, 1},<br \/>\n                             { 3, 8, 3, 4} }; <\/dirtycode><\/p>\n<p>34. \u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u7f16\u7801\u4e00\u4e2a\u56fe\u7247\u7684\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u4e0d\u540c\u989c\u8272\u7684\u7f51\u683c\u53ef\u7531\u5982\u4e0b\u4ee3\u7801\u5b9e\u73b0\uff08\u6bcf\u4e2a\u503c\u4ee3\u8868\u4e00\u4e2a\u989c\u8272\uff09\uff1a<br \/>\n<dirtycode:noclick>int[][] myArray = { { 236, 189, 189, 0},<br \/>\n                             { 236, 80, 189, 189},<br \/>\n                             { 236, 0, 189, 80},<br \/>\n                             { 236, 189, 189, 80} }; <\/dirtycode><\/p>\n<p>35. \u987a\u5e8f\u9605\u904d\u4e00\u7ef4\u6570\u7ec4\uff0c\u6211\u4eec\u7528for\u5faa\u73af\uff1a<br \/>\n<dirtycode:noclick>int[] myArray = new int[10];<br \/>\nfor (int i = 0; i < myArray.length; i++ ) {  \n    myArray[i] = 0;      \n      } <\/dirtycode><br \/>\n\u800c\u5bf9\u4e8e\u4e8c\u7ef4\u6570\u7ec4\uff0c\u5982\u679c\u60f3\u8981\u5173\u7167\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u6211\u4eec\u5fc5\u987b\u8981\u4f7f\u7528\u4e24\u4e2a\u5d4c\u5957\u7684\u5faa\u73af\u3002\u8fd9\u7ed9\u4e86\u6211\u4eec\u4e00\u4e2a\u5bf9\u4e8e\u77e9\u9635\u5185\u6bcf\u4e00\u884c\u6bcf\u4e00\u5217\u7684\u8ba1\u6570\u5668\u53d8\u91cf\u3002<br \/>\n<dirtycode:noclick>int cols = 10;<br \/>\nint rows = 10;<br \/>\nint[][] myArray = new int[cols][rows];<\/p>\n<p>\/\/ \u4e24\u4e2a\u5d4c\u5957\u7684\u5faa\u73af\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u70b9\u3002\u4f7f\u6bcf\u4e2a\u5217i\uff0c\u65b9\u4f4d\u6bcf\u4e2a\u884cj\u3002<br \/>\nfor (int i = 0; i < cols; i++)  {   \n    for (int j = 0; j < rows; j++)  {   \n    myArray[i][j] = 0;    \n     }       \n}<\/dirtycode><\/p>\n<figure id=\"attachment_640\" aria-describedby=\"caption-attachment-640\" style=\"width: 197px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-12.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-640\" title=\"pr13-12\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-12.gif\" alt=\"\u7070\u70b9\u70b9\" width=\"197\" height=\"197\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-12.gif 197w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-12-120x120.gif 120w\" sizes=\"auto, (max-width: 197px) 100vw, 197px\" \/><\/a><figcaption id=\"caption-attachment-640\" class=\"wp-caption-text\">\u7070\u70b9\u70b9<\/figcaption><\/figure>\n<p>36. \u4e00\u4e2a\u4f8b\u5b50\uff1a<br \/>\n<dirtycode:noclick>\/\/ \u5efa\u7acb\u7ef4\u6570<br \/>\nsize(200,200);<br \/>\nint cols = width;<br \/>\nint rows = height;<\/p>\n<p>\/\/ \u7533\u660e2D\u6570\u7ec4<br \/>\nint[][] myArray = new int[cols][rows];<\/p>\n<p>\/\/ \u521d\u59cb\u53162D\u6570\u7ec4\u503c<br \/>\nfor (int i = 0; i < cols; i ++ ) {\n  for (int j = 0; j < rows; j ++ ) {\n    myArray[i][j] = int(random(255));\n  }\n}\n\n\/\/ \u753b\u70b9\nfor (int i = 0; i < cols; i ++ ) {\n  for (int j = 0; j < rows; j ++ ) {\n    stroke(myArray[i][j]);\n    point(i,j);\n  }\n}<\/dirtycode><\/p>\n<figure id=\"attachment_641\" aria-describedby=\"caption-attachment-641\" style=\"width: 200px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-13.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-641\" title=\"pr13-13\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-13.gif\" alt=\"\u6b63\u5f26\u95ea\u683c\" width=\"200\" height=\"200\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-13.gif 200w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pr13-13-120x120.gif 120w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><figcaption id=\"caption-attachment-641\" class=\"wp-caption-text\">\u6b63\u5f26\u95ea\u683c<\/figcaption><\/figure>\n<p>37. \u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u540c\u6837\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u5bf9\u8c61\uff0c\u8fd9\u5c24\u5176\u9002\u7528\u4e8e\u90a3\u4e9b\u5305\u62ec\u67d0\u79cd\u7f51\u683c\u6216\u677f\u5b50\u7684\u7a0b\u5e8f\u3002\u4e0b\u4f8b\u663e\u793a\u7684\u6b63\u662f\u5c06\u4e00\u5806Cell\u5bf9\u8c61\u5b58\u50a8\u4e8e\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002\u6bcf\u4e2acell\u7684\u4eae\u5ea6\u7531\u4e00\u4e2a\u6b63\u5f26\u51fd\u6570\u5f15\u53d1\u75310\uff5e255\u7684\u632f\u52a8\u3002<br \/>\n<dirtycode:noclick>\/\/ \u5bf9\u8c61\u76842D\u6570\u7ec4<br \/>\nCell[][] grid; <\/p>\n<p>\/\/ \u7f51\u683c\u7684\u884c\u6570\u548c\u5217\u6570<br \/>\nint cols = 10;<br \/>\nint rows = 10;<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n  grid = new Cell[cols][rows];<\/p>\n<p>  \/\/ \u8ba1\u6570\u5668\u53d8\u91cfi\u548cj\u540c\u6837\u662f\u884c\u548c\u5217\u7684\u6570\u76ee<br \/>\n  \/\/ \u5728\u672c\u4f8b\u4e2d, \u5b83\u4eec\u88ab\u7528\u4e8e\u683c\u5b50\u5bf9\u8c61\u6784\u9020\u5668\u7684\u5f15\u6570<br \/>\n  for (int i = 0; i < cols; i ++ ) {\n    for (int j = 0; j < rows; j ++ ) {\n      \/\/ Initialize each object\n      grid[i][j] = new Cell(i*20,j*20,20,20,i + j);\n    }\n  }\n}\n\nvoid draw() {\n  background(0);\n  for (int i = 0; i < cols; i ++ ) {     \n    for (int j = 0; j < rows; j ++ ) {\n      \/\/ \u632f\u52a8\u5e76\u663e\u793a\u6bcf\u4e2a\u5bf9\u8c61\n      grid[i][j].oscillate();\n      grid[i][j].display();\n    }\n  }\n}\n\n\/\/ \u4e00\u4e2aCell\u5bf9\u8c61\n\nclass Cell {\n\n  \/\/ \u4e00\u4e2acell\u5bf9\u8c61\u901a\u8fc7\u53d8\u91cfx,y,w,h\u83b7\u53d6\u5176\u5728\u7f51\u683c\u5185\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\n  float x,y;   \/\/ x,y\u4f4d\u7f6e\n  float w,h;   \/\/ \u5bbd\u3001\u9ad8\n  float angle; \/\/ \u632f\u52a8\u4eae\u5ea6\u7684\u89d2\u5ea6\n  \n  \/\/ Cell\u6784\u9020\u5668\n  Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {\n    x = tempX;\n    y = tempY;\n    w = tempW;\n    h = tempH;\n    angle = tempAngle;\n  }\n  \n  \/\/ \u632f\u52a8\u610f\u5473\u7740\u589e\u52a0\u89d2\u5ea6\n  void oscillate() {\n    angle += 0.02;\n  }\n  \n  void display() {\n    stroke(255);\n    \/\/ \u7528\u6b63\u5f26\u6ce2\u8ba1\u7b97\u989c\u8272\n    fill(127 + 127*sin(angle));\n    rect(x,y,w,h);\n  }\n}<\/dirtycode><\/p>\n<p>38. \u6700\u540e\u8fd9\u4e2a<a href=\"http:\/\/www.learningprocessing.com\/exercises\/chapter-13\/exercise-13-10\/\" target=\"_blank\">\u7ec3\u4e60<\/a>\u8c8c\u4f3c\u5f88\u6709\u610f\u601d\u3002\u4f46\u5b66\u5230\u8fd9\u91cc\u6211\u5df2\u7ecf\u5f88\u60f3\u6b7b\u4e86\uff0c\u8840\u69fd\u8fd8\u6709\u8840\u7684\u6162\u6162\u73a9\u5427\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>14. \u6211\u4eec\u76f4\u89c9\u4e0a\u4e60\u60ef\u4ee5\u5ea6\u6570\u6765\u8003\u8651\u89d2\u3002\u4f46Processing\u5374\u8981\u6c42\u6211\u4eec\u7528\u5f27\u5ea6\u6765\u5236\u4f5c\u4e00\u4e2a\u89d2\u3002 \u89d2\u5ea6\u3001\u5f27\u5ea6\u8f6c\u6362\u516c\u5f0f\uff1a \u5f27\u5ea6 \uff1d 2 * PI * (\u89d2\u5ea6\/360) \u5e78\u8fd0\u7684\u662f\uff0c\u82e5\u6211\u4eec\u4e60\u60ef\u4e86\u4ee5\u89d2\u5ea6\u6765\u8003\u8651\u89d2\u800c\u53c8\u5fc5\u987b\u4ee5\u5f27\u5ea6\u5199\u4ee3\u7801\uff0cProcessing\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86radians()\u51fd\u6570\u81ea\u52a8\u5c06\u89d2\u5ea6\u503c\u8f6c\u5316\u4e3a\u5f27\u5ea6\u503c\u3002\u53e6\u5916\uff0c\u5e38\u6570PI\u548cTWO_PI\u4e5f\u53ef\u4ee5\u73b0\u6210\u4f7f\u7528\uff08\u5206\u522b\u7b49\u4e8e180 \u00b0 \u548c 360 \u00b0 \uff09\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c06\u4f7f\u5f62\u72b6\u65cb\u8f6c60 \u00b0 \u3002 float angle = radians(60); rotate(angle); 15. \u590d\u4e60\u4e00\u4e0b\uff0c\u6570\u5b66\u5e38\u6570PI (\u6216 \u03c0 )\u662f\u5706\u5468\u4e0e\u5176\u76f4\u5f84\u7684\u6bd4\u7387\uff08\u56f4\u7ed5\u5706\u5468\u7684\u8ddd\u79bb\uff09\u3002\u5b83\u7684\u503c\u7ea6\u7b49\u4e8e3.14159\u3002 16. Sohcahtoa\uff0c\u8c8c\u4f3c\u65e0\u610f\u4e49\u800c\u4e14\u5947\u602a\u7684\u8bcd\uff0c\u786e\u5b9e\u5de8\u5927\u90e8\u5206\u8ba1\u7b97\u673a\u56fe\u5f62\u5de5\u4f5c\u7684\u57fa\u7840\u3002\u5f53\u4f60\u8981\u8ba1\u7b97\u4e00\u4e2a\u89d2\uff0c\u51b3\u5b9a\u70b9\u95f4\u8ddd\uff0c\u9664\u4e86\u5706\u5f62\u6216\u5f27\u5f62\u7b49\u7b49\u7b49\u7b49\u7684\u65f6\u5019\uff0c\u4f60\u4f1a\u53d1\u73b0\u4e09\u89d2\u5b66\u7684\u91cd\u8981\u6027\u3002sohcahtoa\u662f\u8bb0\u5fc6\u4e09\u89d2\u5b66\u57fa\u7840\uff0c\u6b63\u5f26\u3001\u4f59\u5f26\u548c\u6b63\u5207\u7684\u52a9\u8bb0\u7b26\u3002 \u25ce soh : sine \uff1d \u5bf9\u8fb9\/\u659c\u8fb9 \u25ce cah : cosine \uff1d \u90bb\u8fb9\/\u659c\u8fb9 \u25ce toa : tangent \uff1d \u5bf9\u8fb9\/\u90bb\u8fb9 17. \u6211\u4eec\u8981\u5728Processing\u5185\u7ed8\u5236\u56fe\u5f62\uff0c\u9700\u8981\u7ed9\u51fa\u5176x\uff0cy\u5750\u6807\u503c\uff0c\u8fd9\u79cd\u5750\u6807\u79f0\u4e3a\u7b1b\u5361\u5c14\u5750\u6807\u3002\u53e6\u5916\u4e00\u79cd\u6709\u7528\u7684\u5750\u6807\u79f0\u4e3a\u6781\u5750\u6807\uff0c\u4ee5\u7a7a\u95f4\u5185\u56f4\u7ed5\u539f\u70b9\u65cb\u8f6c\uff08\u4ee5\u89d2\u5ea6\u8ba1\uff09\u7684\u4ee5\u53ca\u8ddd\u79bb\u539f\u70b9\u7684\u534a\u5f84\u5b9a\u4e49\u7684\u4e00\u4e2a\u70b9\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3ap5\u5185\u4e00\u4e2a\u51fd\u6570\u7684\u5f15\u6570\u3002\u4e09\u89d2\u51fd\u6570\u516c\u5f0f\u5141\u8bb8\u6211\u4eec\u5c06\u8fd9\u4e9b\u5750\u6807\u8f6c\u6362\u4e3a\u7b1b\u5361\u5c14\uff0c\u7136\u540e\u88ab\u7528\u4e8e\u7ed8\u5236\u5f62\u72b6\u3002 sine(theta) \uff1d y\/r \u2192 y [&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-614","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\/614","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=614"}],"version-history":[{"count":36,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/614\/revisions"}],"predecessor-version":[{"id":663,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/614\/revisions\/663"}],"wp:attachment":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}