{"id":389,"date":"2013-02-07T11:17:20","date_gmt":"2013-02-07T11:17:20","guid":{"rendered":"http:\/\/lg.yusemo.com\/?p=389"},"modified":"2016-09-23T09:10:16","modified_gmt":"2016-09-23T09:10:16","slug":"the-magic-1k-size-of-js","status":"publish","type":"post","link":"https:\/\/lg.yusemo.com\/?p=389","title":{"rendered":"1k\u5927\u5c0f\u7684\u795e\u5947\u7684js"},"content":{"rendered":"<pre>\u4ee3\u7801\u662f\u4e00\u4e2a\u795e\u5947\u7684\u5de5\u5177\uff0c\u5979\u4e0d\u4ec5\u4ec5\u662f\u50cf\u8bd7\u6b4c\u4e00\u6837\u4f18\u96c5\uff0c\u8fd8\u5c0f\u5de7\u800c\u5f3a\u58ee\u3002\r\n\u4e0b\u9762\u662f\u4e00\u6bb5\u5927\u5c0f\u7ea6\u4e3a1k\u7684js\u4ee3\u7801\uff0c\u4f46\u662f\u5c55\u73b0\u51fa\u6765\u7684\u56fe\u50cf\u662f\u975e\u5e38\u5947\u7279\u7684\u3002\r\n[code lang=\"js\"]with(m=Math)C=cos,S=sin,P=pow,R=random;c.width=c.height=f=500;h=-250;function p(a,b,c){if(c&gt;60)return[S(a*7)*(13+5\/(.2+P(b*4,4)))-S(b)*50,b*f+50,625+C(a*7)*(13+5\/(.2+P(b*4,4)))+b*400,a*1-b\/2,a];A=a*2-1;B=b*2-1;if(A*A+B*B37){n=(j=c&amp;1)?6:4;o=.5\/(a+.01)+C(b*125)*3-a*300;w=b*h;return[o*C(n)+w*S(n)+j*610-390,o*S(n)-w*C(n)+550-j*350,1180+C(B+A)*99-j*300,.4-a*.1+P(1-B*B,-h*6)*.15-a*b*.4+C(a+b)\/5+P(C((o*(a+1)+(B&gt;0?w:-w))\/25),30)*.1*(1-B*B),o\/1e3+.7-o*w*3e-6]}if(c&gt;32){c=c*1.16-.15;o=a*45-20;w=b*b*h;z=o*S(c)+w*C(c)+620;return[o*C(c)-w*S(c),28+C(B*.5)*99-b*b*b*60-z\/2-h,z,(b*b*.3+P((1-(A*A)),7)*.15+.3)*b,b*.7]}o=A*(2-b)*(80-c*2);w=99-C(A)*120-C(b)*(-h-c*4.9)+C(P(1-b,7))*50+c*2;z=o*S(c)+w*C(c)+700;return[o*C(c)-w*S(c),B*99-C(P(b, 7))*50-c\/3-z\/1.35+450,z,(1-b\/1.2)*.9+a*.1, P((1-b),20)\/4+.05]}}setInterval('for(i=0;i&lt;1e4;i++)if(s=p(R(),R(),i%46\/.74)){z=s[2];x=~~(s[0]*f\/z-h);y=~~(s[1]*f\/z-h);if(!m[q=y*f+x]|m[q]&gt;z)m[q]=z,a.fillStyle=&quot;rgb(&quot;+~(s[3]*h)+&quot;,&quot;+~(s[4]*h)+&quot;,&quot;+~(s[3]*s[3]*-80)+&quot;)&quot;,a.fillRect(x,y,1,1)}',0)[\/code]\r\n\r\n\u4e0a\u9762\u8fd9\u6bb5JavaScript\u4ee3\u7801\u4e00\u5171\u67091018\u4e2a\u5b57\u7b26\uff0c\u6bcf\u4e2a\u5b57\u7b26\u5360\u4e00\u4e2a\u5b57\u8282\uff0c\u4e00\u51711018B\uff0c\u7ea6\u7b49\u4e8e1K\u3002\u8fd91K\u5927\u5c0f\u7684js\u80fd\u505a\u4ec0\u4e48\uff0c\u70b9\u4e00\u4e0b\u8fd9\u9762\u8fd9\u4e2a\u6309\u94ae\u5c31\u77e5\u9053\u4e86\uff08\u9700\u8981\u4f7f\u7528\u6700\u65b0\u7248\u7684\u8c37\u6b4c\u6d4f\u89c8\u5668\u6216\u706b\u72d0\u6d4f\u89c8\u5668\u7b49\u652f\u6301html5\u7684\u6d4f\u89c8\u5668\u624d\u80fd\u770b\u5230\u6548\u679c\uff09\u3002\r\n<canvas id=\"c\" style='width:500px;height:500px;'><\/canvas>\r\n<script type=\"text\/javascript\">\r\nvar b = document.body;\r\nvar c = document.getElementsByTagName('canvas')[0];\r\nvar a = c.getContext('2d');\r\ndocument.body.clientWidth;\r\nwith(m = Math) C = cos,\r\nS = sin,\r\nP = pow,\r\nR = random;\r\nc.width = c.height = f = 500;\r\nh = -250;\r\nfunction p(a, b, c) {\r\n\tif (c > 60) return [S(a * 7) * (13 + 5 \/ (.2 + P(b * 4, 4))) - S(b) * 50, b * f + 50, 625 + C(a * 7) * (13 + 5 \/ (.2 + P(b * 4, 4))) + b * 400, a * 1 - b \/ 2, a];\r\n\tA = a * 2 - 1;\r\n\tB = b * 2 - 1;\r\n\tif (A * A + B * B< 1) {\r\n\t\tif (c > 37) {\r\n\t\t\tn = (j=c&1) ? 6: 4;\r\n\t\t\to = .5 \/ (a + .01) + C(b * 125) * 3 - a * 300;\r\n\t\t\tw = b * h;\r\n\t\t\treturn [o * C(n) + w * S(n) + j * 610 - 390, o * S(n) - w * C(n) + 550 - j * 350, 1180 + C(B + A) * 99 - j * 300, .4 - a * .1 + P(1 - B * B, -h * 6) * .15 - a * b * .4 + C(a + b) \/ 5 + P(C((o * (a + 1) + (B > 0 ? w: -w)) \/ 25), 30) * .1 * (1 - B * B), o \/ 1e3 + .7 - o * w * 3e-6]\r\n\t\t}\r\n\t\tif (c > 32) {\r\n\t\t\tc = c * 1.16 - .15;\r\n\t\t\to = a * 45 - 20;\r\n\t\t\tw = b * b * h;\r\n\t\t\tz = o * S(c) + w * C(c) + 620;\r\n\t\t\treturn [o * C(c) - w * S(c), 28 + C(B * .5) * 99 - b * b * b * 60 - z \/ 2 - h, z, (b * b * .3 + P((1 - (A * A)), 7) * .15 + .3) * b, b * .7]\r\n\t\t}\r\n\t\to = A * (2 - b) * (80 - c * 2);\r\n\t\tw = 99 - C(A) * 120 - C(b) * ( - h - c * 4.9) + C(P(1 - b, 7)) * 50 + c * 2;\r\n\t\tz = o * S(c) + w * C(c) + 700;\r\n\t\treturn [o * C(c) - w * S(c), B * 99 - C(P(b, 7)) * 50 - c \/ 3 - z \/ 1.35 + 450, z, (1 - b \/ 1.2) * .9 + a * .1, P((1 - b), 20) \/ 4 + .05]\r\n\t}\r\n}\r\nZ = 'for(i=0;i&lt;1e4;i++)if(s=p(R(),R(),i%46\/.74)){z=s[2];x=~~(s[0]*f\/z-h);y=~~(s[1]*f\/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle=\"rgb(\"+~(s[3]*h)+\",\"+~(s[4]*h)+\",\"+~(s[3]*s[3]*-80)+\")\",a.fillRect(x,y,1,1)}';\r\n<\/script>\r\n\r\n<button onclick=\"javascript:setInterval(Z,0);\">\u6f14\u793a<\/button>\r\n\u662f\u4e0d\u662f\u5f88\u7eda\u4e3d\u3002\u6211\u60f3\uff0c\u5199\u51fa\u8fd9\u4e2a1K\u5927\u5c0f\u7684js\uff0c\u4f60\u81f3\u5c11\u9700\u8981\u6709\u7ed8\u753b\u77e5\u8bc6(\u753b\u51fa\u73ab\u7470)\uff0c\u8272\u5f69\u539f\u7406\u77e5\u8bc6(\u73ab\u7470\u7ea2\u989c\u8272\u6e10\u53d8)\uff0c\u6570\u5b66\u7b97\u6cd5\u77e5\u8bc6(\u8ba1\u7b97\u5404\u50cf\u7d20\u70b9)\uff0c\u8ba1\u7b97\u673a\u52a8\u753b\u77e5\u8bc6(\u73ab\u7470\u51fa\u73b0\u6548\u679c)\uff0c\u7f16\u7a0b\u77e5\u8bc6(\u4f1a\u7528javascript)\u3002\r\n\r\n\u60f3\u4e86\u89e3\u8fd9\u6bb5\u4ee3\u7801\u7684\u5de5\u4f5c\u539f\u7406\u7684\u670b\u53cb\u8bf7\u8bbf\u95ee<a href=\"http:\/\/js1k.com\/\">\u8fd9\u91cc<\/a>\r\n\r\n\u4ece\u672a\u89c1\u8fc7\u7684js\u3002<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801\u662f\u4e00\u4e2a\u795e\u5947\u7684\u5de5\u5177\uff0c\u5979\u4e0d\u4ec5\u4ec5\u662f\u50cf\u8bd7\u6b4c\u4e00\u6837\u4f18\u96c5\uff0c\u8fd8\u5c0f\u5de7\u800c\u5f3a\u58ee\u3002 \u4e0b\u9762\u662f\u4e00\u6bb5\u5927\u5c0f\u7ea6\u4e3a1k\u7684js\u4ee3\u7801\uff0c\u4f46\u662f\u5c55\u73b0\u51fa\u6765\u7684\u56fe\u50cf\u662f\u975e\u5e38\u5947\u7279\u7684\u3002 [code lang=&#8221;js&#8221;]with(m=Math)C=cos,S=sin,P=pow,R=random;c.width=c.height=f=500;h=-250&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[4],"_links":{"self":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/389"}],"collection":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389"}],"version-history":[{"count":11,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":433,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions\/433"}],"wp:attachment":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}