{"id":604,"date":"2009-11-01T22:45:34","date_gmt":"2009-11-01T14:45:34","guid":{"rendered":"http:\/\/test999.eblhost.com\/blog\/?p=604"},"modified":"2009-11-01T22:47:17","modified_gmt":"2009-11-01T14:47:17","slug":"processing%ef%bc%9a%e6%95%b0%e5%ad%a6%ef%bc%88%e4%b8%8a%ef%bc%89","status":"publish","type":"post","link":"https:\/\/learn.travelchinawith.me\/?p=604","title":{"rendered":"Processing\uff1a\u6570\u5b66\uff08\u4e0a\uff09"},"content":{"rendered":"<p>1. \u201c\u5982\u679c\u4f60\u4e0d\u76f8\u4fe1\u6570\u5b66\u6709\u591a\u7b80\u5355\uff0c\u662f\u4f60\u8fd8\u6ca1\u6709\u8ba4\u8bc6\u5230\u751f\u6d3b\u6709\u591a\u590d\u6742\u2014\u2014John von Neumann\u201d<\/p>\n<p>2. \u6a21\u6570\uff08Modulus\uff09\uff1a20 \u6a21\uff08modulo\uff0c\u4e5f\u5c31\u662f\u9664\u4ee5\uff0c\u7528\u767e\u5206\u53f7\u8868\u793a\uff09 6 \u7b49\u4e8e 2 \u6216\u8005\u5199\u4e3a 20 % 6 \uff1d 2\u3002\u5982\u679cA \uff1d B  %  C\uff0c\u90a3\u4e48A\u6c38\u8fdc\u4e0d\u53ef\u80fd\u5927\u4e8eC\uff08\u5f53\u7136\u3002\u3002\uff09\u3002\u56e0\u6b64\uff0c\u6a21 \u53ef\u4ee5\u7528\u5728\u4f60\u9700\u8981\u5c06\u4e00\u4e2a\u8ba1\u6570\u5668\u53d8\u91cf\u5faa\u73af\u81f30\u7684\u60c5\u51b5\u3002\u4e0b\u5217\u4ee3\u7801\uff1a<br \/>\n<em><span style=\"color: #888888;\"> x = x + 1;<br \/>\nif (x &gt;= limit){<br \/>\nx = 0;<br \/>\n}<\/span><\/em><br \/>\n\u53ef\u4ee5\u88ab\u66ff\u6362\u4e3a\uff1a<br \/>\n<em><span style=\"color: #888888;\"> x = (x + 1) % limit;<\/span><\/em><br \/>\n\u8fd9\u5728\u4f60\u60f3\u8981\u6bcf\u6b21\u4e00\u4e2a\u7684\u987a\u6570\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u65f6\u5f88\u6709\u7528\uff0c\u5f53\u4f60\u8fbe\u5230\u6570\u7ec4\u957f\u5ea6\u7684\u65f6\u5019\u603b\u662f\u8fd4\u56de0\u3002\u4e00\u4e2a\u4f8b\u5b50\uff1a<br \/>\n<em><span style=\"color: #888888;\"> \/\/ 4\u4e2a\u968f\u673a\u6570\u5b57<br \/>\nfloat[] randoms = new float[4];<br \/>\nint index = 0;   \/\/ \u6211\u4eec\u6b63\u5728\u4f7f\u7528\u7684\u6570\u5b57<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void setup() {<br \/>\nsize(200,200);<br \/>\n\/\/ \u7528\u968f\u673a\u503c\u586b\u5145\u6570\u7ec4<br \/>\nfor (int i = 0; i &lt; randoms.length; i ++ ) {<br \/>\nrandoms[i] = random(0,256);<br \/>\n}<br \/>\nframeRate(1);<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void draw() {<br \/>\n\/\/ \u6211\u4eec\u6bcf\u5e27\u8c03\u7528\u6570\u7ec4\u7684\u4e00\u4e2a\u5143\u7d20<br \/>\nbackground(randoms[index]);<br \/>\n\/\/ \u7136\u540e\u7ee7\u7eed\u4e0b\u4e00\u4e2a<br \/>\nindex = (index + 1) % randoms.length; \/\/ \u4f7f\u7528\u6a21\u8fd0\u7b97\u7b26\uff08modulo operator\uff09\u5c06\u8ba1\u6570\u5668\u5faa\u73af\u52300\u3002<br \/>\n}<\/span><\/em><\/p>\n<figure id=\"attachment_605\" aria-describedby=\"caption-attachment-605\" style=\"width: 198px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/random-graph.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-605\" title=\"random graph\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/random-graph.gif\" alt=\"\u968f\u673a\u67f1\u72b6\u56fe\" width=\"198\" height=\"198\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/random-graph.gif 198w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/random-graph-120x120.gif 120w\" sizes=\"auto, (max-width: 198px) 100vw, 198px\" \/><\/a><figcaption id=\"caption-attachment-605\" class=\"wp-caption-text\">\u968f\u673a\u67f1\u72b6\u56fe<\/figcaption><\/figure>\n<p>3. random()\u51fd\u6570\u4ea7\u51fa\u7684\u968f\u673a\u503c\u79f0\u4e3a\u201c\u7edf\u4e00\uff08uniform\uff09\u201d\u5206\u90e8\uff0c\u4e3e\u4f8b\u8bf4\u660e\uff1a\u5982\u679c\u6211\u4eec\u8981\u4e00\u4e2a\u57280\uff5e9\u95f4\u7684\u968f\u673a\u503c\uff0c\u6570\u5b570\uff5e9\u51fa\u73b0\u7684\u673a\u7387\u6700\u9ad8\u4e3a10%\u3002\u4e0b\u4f8b\u53ef\u8bc1\u660e\u6b64\u70b9\uff1a<br \/>\n<em><span style=\"color: #888888;\"> \/\/ \u4e00\u4e2a\u8bb0\u5f55\u968f\u673a\u6570\u6458\u53d6\u9891\u7387\u7684\u6570\u7ec4<br \/>\nfloat[] randomCounts;<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void setup() {<br \/>\nsize(200,200);<br \/>\nrandomCounts = new float[20];<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void draw() {<br \/>\nbackground(255);<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u9009\u53d6\u4e00\u4e2a\u968f\u673a\u6570\u5e76\u589e\u52a0\u8ba1\u6570<br \/>\nint index = int(random(randomCounts.length));<br \/>\nrandomCounts[index] ++ ;<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u7ed8\u5236\u76f4\u65b9\u56fe<br \/>\nstroke(0);<br \/>\nfill(175);<br \/>\nfor (int x = 0; x &lt; randomCounts.length; x ++ ) {<br \/>\nrect(x*10,0,9,randomCounts[x]);<br \/>\n}<br \/>\n}<\/span><\/em><br \/>\n\u901a\u8fc7\u4e00\u4e9b\u5c0f\u628a\u620f\uff0c\u6211\u4eec\u53ef\u4ee5\u7528<em><span style=\"color: #888888;\">random()<\/span><\/em>\u4ea7\u51fa\u975e\u7edf\u4e00\u6027\u5206\u90e8\u7684\u968f\u673a\u503c\uff0c\u5e76\u4e14\u4ea7\u51fa\u4f7f\u7279\u5b9a\u4e8b\u4ef6\u53d1\u751f\u7684\u53ef\u80fd\u6027\u3002\u6bd4\u5982\u8bf4\uff0c\u4f7f\u4e00\u4e2asketch\u7684\u80cc\u666f\u8272\u53d8\u9ec4\u7684\u673a\u7387\u4e3a10%\u800c\u53d8\u84dd\u7684\u673a\u7387\u4e3a90\uff05\u3002<\/p>\n<p>4. \u53ef\u80fd\u6027\u662f\u4ec0\u4e48\uff1f\u53ef\u80fd\u6027\u5c31\u662f\u67d0\u4ef6\u4e8b\u53d1\u751f\u7684\u53ef\u80fd\u6027\u3002\u6bd4\u5982\u6295\u63b7\u786c\u5e01\uff0c\u7ed3\u679c\u662f\u6b63\u9762\u4e0e\u53cd\u9762\u671d\u4e0a\u7684\u53ef\u80fd\u6027\u5404\u4e3a50%\u3002\u51fa\u73b0\u4e09\u6b21\u6b63\u9762\u671d\u4e0a\u7684\u53ef\u80fd\u6027\u4e3a\uff1a<br \/>\n<em> (1\/2) * (1\/2) * (1\/2) \uff1d 1\/8 (\u6216\u8005 0.125)<\/em><br \/>\n\u6362\u53e5\u8bdd\u8bf4\uff0c\u6bcf8\u6b21\u6295\u63b7\u786c\u5e01\uff0c\u6b63\u9762\u671d\u4e0a\u7684\u60c5\u51b5\u53ef\u80fd\u4f1a\u67093\u6b21\u3002<\/p>\n<p>5. Daniel\u51fa\u9898\uff0c\u5728\u4e00\u526f\u6251\u514b\u724c\u5185\u62bd\u4e2d\u4e24\u5f20A\u7684\u53ef\u80fd\u6027\u662f\u591a\u5c11\uff1f\u7b54\u6848\u4e3a\uff1a0.00452488688\u3002\u600e\u4e48\u7b97\u51fa\u6765\u7684\uff1f<br \/>\n<em> \u4e00\u526f\u6251\u514b\u724c\u670952\u5f20\u724c\uff0c\u5176\u4e2d\u67094\u5f20A\uff0c\u56e0\u6b64\u62bd\u4e2d\u7b2c\u4e00\u5f20A\u7684\u53ef\u80fd\u6027\u4e3a\uff1a<br \/>\n4 \/ 52 = 0.0769230769<br \/>\n\u62bd\u4e2d\u7b2c\u4e8c\u5f20A\u7684\u53ef\u80fd\u6027\u4e3a\uff1a<br \/>\n3\uff08\u5269\u4e0b\u7684A\uff09 \/ 51\uff08\u5269\u4e0b\u7684\u6251\u514b\u724c\uff09 = 0.0588235294<br \/>\n\u56e0\u6b64\u62bd\u4e2d\u4e24\u5f20A\u7684\u53ef\u80fd\u6027\u4e3a\uff1a<br \/>\n(4\/52)*(3\/51) = 0.00452488688<\/em><\/p>\n<p>6. \u6211\u4eec\u53ef\u4ee5\u7528random()\u73a9\u4e9b\u5c0f\u628a\u620f\uff1a<br \/>\n<em><span style=\"color: #888888;\"> int[] stuff = new int[5]; <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> stuff[0] = 1;<br \/>\nstuff[1] = 1;<br \/>\nstuff[2] = 2;<br \/>\nstuff[3] = 3;<br \/>\nstuff[4] = 3;<br \/>\nint index = int(random(stuff.length));<br \/>\nif (stuff[index] == 1){<br \/>\n\/\/ \u505a\u7231\u505a\u7684\u4e8b<br \/>\n}<\/span><\/em><br \/>\n\u5982\u679c\u8fd0\u884c\u4e0a\u8fb9\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6211\u4eec\u5f97\u52301\u548c3\u7684\u673a\u7387\u90fd\u5c06\u4e3a40%\uff0c\u800c\u5f97\u52302\u7684\u673a\u7387\u5219\u4e3a20%\u3002<\/p>\n<p>7. \u53e6\u4e00\u4e2a\u7b56\u7565\u662f\uff0c\u8981\u4e00\u4e2a\u968f\u673a\u503c\uff0c\u5e76\u4e14\u5728\u6211\u4eec\u6307\u5b9a\u7684\u8303\u56f4\u5185\u624d\u4f7f\u7528\u5b83\uff1a<br \/>\n<em><span style=\"color: #888888;\"> float prob = 0.10;     \/\/ \u53ef\u80fd\u6027\u4e3a10%<br \/>\nfloat r = random(l);  \/\/ 0\uff5e1\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u503c <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> if (r &lt; prob)  { \/\/ \u5982\u679c\u6211\u4eec\u7684\u968f\u673a\u503c\u5c0f\u4e8e0.1<br \/>\n\/*\u5728\u6b64\u8ba9\u4e8b\u4ef6\u53d1\u751f*\/<br \/>\n}<\/span><\/em><\/p>\n<p>8. \u540c\u6837\u7684\u6280\u672f\u540c\u6837\u53ef\u7528\u4e8e\u591a\u4e2a\u8f93\u51fa\uff1a<br \/>\nOutcome A \u2014 60% | Outcome B \u2014 10% | Outcome C \u2014 30%\u3002<br \/>\n\u7528\u4ee3\u7801\u5b9e\u73b0\u8fd9\u4e2a\uff0c\u6211\u4eec\u8fd9\u4e48\u641e\uff1a<br \/>\n\u2022 \u4ecb\u4e8e0.00\uff5e0.60\u95f4 (10%) \u2192 \u8f93\u51fa A.<br \/>\n\u2022 \u4ecb\u4e8e0.60\uff5e0.70\u95f4 (60%) \u2192 \u8f93\u51fa B.<br \/>\n\u2022 \u4ecb\u4e8e0.70\uff5e1.00\u95f4 (30%) \u2192 \u8f93\u51fa C .<\/p>\n<figure id=\"attachment_606\" aria-describedby=\"caption-attachment-606\" style=\"width: 200px\" class=\"wp-caption alignright\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/probability.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-606\" title=\"probability\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/probability.gif\" alt=\"\u4e09\u8272\u53ef\u80fd\u6027\" width=\"200\" height=\"198\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/probability.gif 200w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/probability-120x120.gif 120w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><figcaption id=\"caption-attachment-606\" class=\"wp-caption-text\">\u4e09\u8272\u53ef\u80fd\u6027<\/figcaption><\/figure>\n<p>\u63a5\u4e0b\u6765\u770b\u4f8b\u5b50\uff1a<br \/>\n<em><span style=\"color: #888888;\"> void setup() {<br \/>\nsize(200,200);<br \/>\nbackground(255);<br \/>\nsmooth();<br \/>\nnoStroke();<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\">void draw() {<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ 3\u79cd\u4e0d\u540c\u60c5\u51b5\u7684\u53ef\u80fd\u6027<br \/>\n\/\/ \u5b83\u4eec\u52a0\u8d77\u6765\u5e94\u5f53\u4e3a100%!<br \/>\nfloat red_prob = 0.60;   \/\/ 60%\u7684\u673a\u4f1a\u7ea2\u8272<br \/>\nfloat green_prob = 0.10; \/\/ 10%\u7684\u673a\u4f1a\u7eff\u8272<br \/>\nfloat blue_prob = 0.30;  \/\/ 30%\u7684\u673a\u4f1a\u84dd\u8272<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u9009\u53d6\u4e00\u4e2a0\uff5e1\u95f4\u7684\u968f\u673a\u503c<br \/>\nfloat num = random(1); <\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u5982\u679c\u968f\u673a\u503c\u5c0f\u4e8e0.6<br \/>\nif (num &lt; red_prob) {<br \/>\nfill(255,53,2,150);<br \/>\n\/\/ \u5982\u679c\u968f\u673a\u6570\u57280.6\uff5e0.7\u4e4b\u95f4<br \/>\n} else if (num &lt; green_prob + red_prob) {<br \/>\nfill(156,255,28,150);<br \/>\n\/\/ \u6240\u6709\u5176\u4ed6\u7684\u60c5\u51b5 (\u6bd4\u5982\u4ecb\u4e8e0.7\uff5e1.0)<br \/>\n} else {<br \/>\nfill(10,52,178,150);<br \/>\n}<\/span><\/em><\/p>\n<p><em><span style=\"color: #888888;\"> \/\/ \u7ed8\u5236\u5706\u5f62<br \/>\nellipse(random(width),random(height),64,64);<br \/>\n} <\/span><\/em><\/p>\n<p>9. <a href=\"http:\/\/zh.wikipedia.org\/wiki\/Perlin\u566a\u58f0\" target=\"_blank\">Perlin\u566a\u58f0<\/a>\uff0c\u5527\u5527\u6b6a\u6b6a\u8bf4\u4e86\u4e00\u5806\uff0c\u6211\u53ea\u5173\u6ce8\u5b83\u53ef\u7528\u4e8e\u751f\u6210\u4e00\u7cfb\u5217\u6709\u8da3\u7684\u6548\u679c\uff0c\u5305\u62ec\u4e91\u3001\u5c71\u6c34\u3001\u5927\u7406\u77f3\u7eb9\u7406\u7b49\u7b49\u3002\u4e0b\u56fe\u4e3aPerlin\u566a\u58f0\u56fe\uff08x\u8f74\u4ee3\u8868\u65f6\u95f4\uff1b\u6ce8\u610f\u66f2\u7ebf\u6709\u591a\u4e48\u5149\u6ed1\uff09\u4e0e\u7eaf\u968f\u673a\u6570\u56fe\u7684\u5bf9\u6bd4\uff1a<\/p>\n<figure id=\"attachment_607\" aria-describedby=\"caption-attachment-607\" style=\"width: 582px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pvr.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-607 \" title=\"pvr\" src=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pvr.gif\" alt=\"Perlin\u566a\u97f3  VS. \u968f\u673a(random)\" width=\"582\" height=\"162\" srcset=\"https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pvr.gif 728w, https:\/\/learn.travelchinawith.me\/wp-content\/uploads\/2009\/11\/pvr-300x83.gif 300w\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" \/><\/a><figcaption id=\"caption-attachment-607\" class=\"wp-caption-text\">Perlin\u566a\u97f3  VS. \u968f\u673a(random)<\/figcaption><\/figure>\n<p>10. \u5982\u679c\u4f60\u53c2\u8003P5\u5b98\u7f51\u5173\u4e8e\u566a\u97f3\uff08noise\uff09\u7684\u53c2\u8003\uff0c\u4f60\u4f1a\u53d1\u73b0\u566a\u97f3\u662f\u57fa\u4e8e\u82e5\u5e72\u201c\u516b\u5ea6\uff08octave\uff09\u201d\u8ba1\u7b97\u51fa\u6765\u7684\uff0c\u4f60\u53ef\u4ee5\u547c\u53eb<em><span style=\"color: #888888;\"><a href=\"http:\/\/processing.org\/reference\/noiseDetail_.html\" target=\"_blank\">noiseDetail()<\/a><\/span><\/em>\u6539\u53d8\u516b\u5ea6\u7684\u6570\u91cf\u4ee5\u53ca\u5b83\u4eec\u76f8\u5173\u7684\u91cd\u8981\u6027\u3002\u8fd9\u5c06\u6539\u53d8\u566a\u97f3\u51fd\u6570\u7684\u884c\u4e3a\u3002\u4f60\u53ef\u4ee5\u5728<a href=\"http:\/\/www.noisemachine.com\/talk1\" target=\"_blank\">\u8fd9\u91cc<\/a>\u9605\u8bfb\u66f4\u591aKen Perlin\u4e0e\u566a\u97f3\u534f\u4f5c\u7684\u4e1c\u897f\u3002<\/p>\n<p>11. \u4f60\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570<em><span style=\"color: #888888;\"> noise( )<\/span><\/em>\u5728P5\u5185\u8c03\u7528Perlin\u566a\u97f3\u7b97\u6cd5\u3002\u5f15\u6570\u4e3a\u4e09\u4e2a\uff0c\u5206\u522b\u4ee3\u8868\u4e00\u3001\u4e8c\u3001\u4e09\u7ef4\uff0c\u8fd9\u91cc\u53ea\u8bb2\u4e00\u7ef4\uff0c\u5269\u4e0b\u4e24\u7ef4\u8bf7\u53c2\u9605P5\u5b98\u7f51\u3002\u4e00\u7ef4\u7684Perlin\u566a\u97f3\u53cd\u590d\u5236\u9020\u4e00\u4e2a\u503c\u7684\u7ebf\u6027\u5e8f\u5217\u3002\u4f8b\u5982\uff1a0.364, 0.363, 0.363, 0.364, 0.365<\/p>\n<p>12. Perlin\u566a\u97f3\u5728P5\u4e2d\u7684\u4f7f\u7528\uff1aa. \u547c\u53eb\u51fd\u6570<em><span style=\"color: #888888;\">noise()<\/span><\/em>\uff1bb. \u4f20\u9012\u5f53\u524d\u7684\u201c\u65f6\u95f4\u201d\u4e3a\u5176\u5f15\u6570\uff1a<br \/>\n<em><span style=\"color: #888888;\"> float t = 0.0;<br \/>\nfloat noisevalue = noise(t); \/\/ \u4ece\u65f6\u95f40\u5f00\u59cb\u566a\u97f3<\/span><\/em><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728<em><span style=\"color: #888888;\">draw()<\/span><\/em>\u5185\u4f7f\u5176\u5faa\u73af\uff1a<br \/>\n<em><span style=\"color: #888888;\"> float t = 0.0;<br \/>\nvoid draw()  {<br \/>\nfloat noisevalue  = noise(t);<br \/>\nprintln(noisevalue);<br \/>\n}<\/span><\/em><br \/>\n\u4f46\u4f60\u4e5f\u8bb8\u4f1a\u53d1\u73b0\uff0c\u8f93\u51fa\u7684\u603b\u662f\u540c\u6837\u7684\u503c\uff0c\u90a3\u662f\u56e0\u4e3a\u65f6\u95f4\u6ca1\u6709\u53d8\u5316\uff0c\u5982\u679c\u6211\u4eec\u8ba9\u65f6\u95f4\u589e\u52a0\u7684\u8bdd\uff1a<br \/>\n<em><span style=\"color: #888888;\"> float t = 0.0;<br \/>\nvoid draw()  {<br \/>\nfloat noisevalue = noise(t);<br \/>\nprintln(noisevalue);<br \/>\nt  +  =  0.01;<br \/>\n}<\/span><\/em><br \/>\n\u8f93\u51fa\u7684\u503c\u5c06\u5f00\u59cb\u5e73\u6ed1\u53d8\u5316\u3002\u65f6\u95f4\u53d8\u5316\u7684\u5feb\u6162\u51b3\u5b9a\u4e86\u566a\u58f0\u66f2\u7ebf\u7684\u5e73\u6ed1\u5ea6\uff0c\u8d8a\u5feb\u5219\u8d8a\u4e0d\u5e73\u6ed1\u3002<\/p>\n<p>13. \u4f60\u4e5f\u8bb8\u4f1a\u53d1\u73b0\uff0c<em><span style=\"color: #888888;\">noise()<\/span><\/em>\u8fd4\u56de\u7684\u503c\u603b\u662f\u4ecb\u4e8e0.0\uff5e1.0\u4e4b\u95f4\u7684\u6d6e\u70b9\u503c\uff0c\u8fd9\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u4f46\u5982\u679c\u6211\u4eec\u9700\u8981\u66f4\u5927\u7684\u503c\uff0c\u90a3\u4e48\u7528\u4e58\u6cd5\u5373\u53ef\uff0c<a href=\"http:\/\/www.learningprocessing.com\/examples\/chapter-13\/example-13-4-perlin-noise\/\" target=\"_blank\">\u8fd9\u4e2a\u4f8b\u5b50<\/a>\u9610\u8ff0\u4e86\u8fd9\u4e00\u5173\u70b9\uff0c\u8bf7\u6ce8\u610f\u7403\u7684\u7f29\u653e\u591a\u4e48\u8212\u670d\u548c\u5e73\u6ed1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u201c\u5982\u679c\u4f60\u4e0d\u76f8\u4fe1\u6570\u5b66\u6709\u591a\u7b80\u5355\uff0c\u662f\u4f60\u8fd8\u6ca1\u6709\u8ba4\u8bc6\u5230\u751f\u6d3b\u6709\u591a\u590d\u6742\u2014\u2014John von Neumann\u201d 2. \u6a21\u6570\uff08Modulus\uff09\uff1a20 \u6a21\uff08modulo\uff0c\u4e5f\u5c31\u662f\u9664\u4ee5\uff0c\u7528\u767e\u5206\u53f7\u8868\u793a\uff09 6 \u7b49\u4e8e 2 \u6216\u8005\u5199\u4e3a 20 % 6 \uff1d 2\u3002\u5982\u679cA \uff1d B % C\uff0c\u90a3\u4e48A\u6c38\u8fdc\u4e0d\u53ef\u80fd\u5927\u4e8eC\uff08\u5f53\u7136\u3002\u3002\uff09\u3002\u56e0\u6b64\uff0c\u6a21 \u53ef\u4ee5\u7528\u5728\u4f60\u9700\u8981\u5c06\u4e00\u4e2a\u8ba1\u6570\u5668\u53d8\u91cf\u5faa\u73af\u81f30\u7684\u60c5\u51b5\u3002\u4e0b\u5217\u4ee3\u7801\uff1a x = x + 1; if (x &gt;= limit){ x = 0; } \u53ef\u4ee5\u88ab\u66ff\u6362\u4e3a\uff1a x = (x + 1) % limit; \u8fd9\u5728\u4f60\u60f3\u8981\u6bcf\u6b21\u4e00\u4e2a\u7684\u987a\u6570\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u65f6\u5f88\u6709\u7528\uff0c\u5f53\u4f60\u8fbe\u5230\u6570\u7ec4\u957f\u5ea6\u7684\u65f6\u5019\u603b\u662f\u8fd4\u56de0\u3002\u4e00\u4e2a\u4f8b\u5b50\uff1a \/\/ 4\u4e2a\u968f\u673a\u6570\u5b57 float[] randoms = new float[4]; int index = 0; \/\/ [&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-604","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\/604","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=604"}],"version-history":[{"count":3,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions"}],"predecessor-version":[{"id":610,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions\/610"}],"wp:attachment":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}