{"id":173773,"date":"2013-03-25T13:19:03","date_gmt":"2013-03-25T09:19:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=173773"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=173773","title":{"rendered":"<span class=\"post_title\">canvas \u0432 gif<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/8bd\/2c3\/1f2\/8bd2c31f23fbe5125e76734e0abd2b9c.png\"\/><br \/>  \u0420\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u0445 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437 canvas \u0432 gif.<br \/>  \u0422\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043c\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 javascript \u043a\u043e\u0434 \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0442\u043e \u0435\u0441\u0442\u044c \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0434\u043e 256 \u0446\u0432\u0435\u0442\u043e\u0432). \u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 javascript \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e \u0442\u043e\u043c, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440<\/h4>\n<p>  \u0427\u0435\u0441\u0442\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Javascript. \u0421 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 PHP, C#, JAVA. \u041d\u043e \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c Javascript \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 canvas, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0432 jpg \u0438 png \u0444\u043e\u0440\u0430\u0442\u0430\u0445, \u0442\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043d\u0435\u043a\u0440\u0430\u0441\u0438\u0432\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c. \u0418\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044f \u0438 \u0437\u0430\u043d\u044f\u043b\u0441\u044f \u044d\u0442\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c. \u042f \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0430 javasript.<\/p>\n<h4>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0438\u0440\u043f\u0438\u0447\u0438\u043a\u0438<\/h4>\n<p>  \u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c canvas \u0432 JPEG \u0438\u043b\u0438 \u0432 PNG \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">canvas.toDataURL(mime) <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0439 \u0444\u0430\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 base64 DatURL, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 src \u0442\u0435\u0433\u0430 img.<br \/>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 mime \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e \u00abimage\/png\u00bb \u043b\u0438\u0431\u043e \u00abimage\/jpeg\u00bb.<br \/>  \u0415\u0441\u043b\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 mime \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u00abimage\/gif\u00bb \u0438\u043b\u0438 \u00abimage\/bmp\u00bb, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 PNG.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u043f\u043b\u0430\u043d\u0435\u0442\u0435 \u043d\u0435 \u043c\u0430\u043b\u043e, \u044f \u0440\u0435\u0448\u0438\u043b \u0443\u0437\u043d\u0430\u0442\u044c \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0441 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0438 \u0434\u043e\u0448\u043b\u0438 \u043b\u0438 \u0443 \u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u0443\u043a\u0438 \u0434\u043e \u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f.<br \/>  \u041c\u043d\u0435 \u043f\u043e\u0432\u0435\u0437\u043b\u043e, \u044f \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0448\u0435\u043b \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 canvas \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 BMP: <a href=\"http:\/\/www.nihilogic.dk\/labs\/canvas2image\">www.nihilogic.dk\/labs\/canvas2image<\/a><br \/>  \u0412\u044b\u0434\u0440\u0430\u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043c\u043d\u0435 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u044f \u043f\u0440\u0438\u043d\u044f\u043b\u0441\u044f \u0437\u0430 GIF.<\/p>\n<p>  \u041d\u043e \u0441 gif \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e. <br \/>  \u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043f\u043e\u0438\u0441\u043a\u0438 \u043d\u0430 \u0442\u0435\u043c\u0443 \u00abcanvas to gif\u00bb \u0432\u0435\u0434\u0443\u0442 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 antimatter15: <a href=\"http:\/\/github.com\/antimatter15\/jsgif\">github.com\/antimatter15\/jsgif<\/a><br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0435 \u0442\u043e \u044f \u043f\u0435\u0440\u0432\u0443\u044e \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b. \u041f\u043b\u044e\u0441 \u0443 \u043d\u0435\u0435 \u043e\u0434\u0438\u043d: \u043e\u043d\u0430 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u0432\u044b\u0434\u0430\u0435\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 GIF, \u043a\u043e\u0442\u043e\u0440\u0443\u044e, \u043a\u0440\u043e\u043c\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439. \u0412\u0438\u0434\u0438\u043c\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0438 \u0434\u0435\u043b\u0430\u043b\u0441\u044f \u0443\u043f\u043e\u0440, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a \u044f \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u043b \u043d\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043d\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  antimatter15 (GIF \u0432 GIF, 100x16px, 56ms):<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/ab9\/763\/dba\/ab9763dbaa990fcf479780beb9bfd327.png\"\/><\/p>\n<p>  antimatter15 (JPEG \u0432 GIF, 604x377px, 4564ms):<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/96b\/497\/02b\/96b49702b8e4b84f19fa52007506bfab.png\"\/><\/p>\n<p>  antimatter15 (\u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 PNG \u0432 GIF, 256x256px, 1052ms):<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/11c\/25b\/b42\/11c25bb427cee1036487ed7aade06281.png\"\/><\/p>\n<p>  \u041e\u0431\u044a\u044f\u0441\u043d\u044e \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u043e\u0439. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0431\u044b\u043b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 PNG \u0441 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c\u0438 \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u043c\u0438. \u041a\u0430\u043d\u0432\u0430\u0441 \u0432\u044b\u0434\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 RGBA, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0446\u0432\u0435\u0442\u0430 \u0438 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438. \u041d\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e\u0442 antimatter15 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>  \u0421\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0430\u0434\u0438 \u0437\u0430\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 canvas2image \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438. <br \/>  canvas2image (\u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 PNG \u0432 BMP, 256x256px):<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/6c5\/3c4\/1f4\/6c53c41f46861d81eea0e2e8c036c0f1.png\"\/><\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0437\u044b\u0432\u0430\u044e \u0432\u0441\u0435\u0445 \u043d\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c alpha \u0431\u0430\u0439\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441anvas.<\/p>\n<p>  \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u043c\u0435\u043d\u044f \u043a omggif (javascript \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f GIF 89a \u043a\u043e\u0434\u0435\u0440\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0438 \u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u044e): <a href=\"https:\/\/github.com\/deanm\/omggif\">github.com\/deanm\/omggif<\/a><br \/>  \u0423\u0432\u0438\u0434\u0435\u0432 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c, \u044f \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0443\u0432\u0430\u0436\u0430\u043b \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<pre><code class=\"javascript\">\/\/ 1x1 transparent 43 bytes. function gen_empty_trans() {   var gf = new omggif.GifWriter(buf, 1, 1, {palette: [0x000000, 0x000000]});   gf.addFrame(0, 0, 1, 1, [0], {transparent: 0});   return buf.slice(0, gf.end()); } <\/code><\/pre>\n<p>  \u041d\u043e \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u043d \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 canvas. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u043f\u0430\u043b\u0438\u0442\u0440\u0443 (\u0441\u043f\u0438\u0441\u043e\u043a \u0446\u0432\u0435\u0442\u043e\u0432), \u0430 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u0430\u0434\u0440\u0430 \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435.<br \/>  \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0435\u0441\u0442\u044c \u043d\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435 \u043a\u0430\u043a \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u044f (quantization). \u0412 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043e\u0442 antimatter15 \u0437\u0430 \u044d\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b NeuQuant.js. \u0412 omggif \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0435\u0442. <br \/>  \u042f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f javascript, \u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c\u044e.<br \/>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 omggif \u043c\u043d\u0435 \u0443\u0436\u0435 \u043d\u0435 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 GIF \u0444\u0430\u0439\u043b\u0430, \u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043d\u0435 \u0442\u0430\u043a\u043e\u0439 \u0443\u0436 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0438 \u0434\u0430\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u043f\u0438\u043b\u0438\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0441\u0430\u043c\u043e\u043c\u0443.<\/p>\n<h4>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/h4>\n<p>  \u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u043d\u0430 4 \u044d\u0442\u0430\u043f\u0430:  <\/p>\n<ol>\n<li>\u041f\u043e\u0438\u0441\u043a \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0443.<\/li>\n<li>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0446\u0432\u0435\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0443.<\/li>\n<li>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u043e\u043f\u0430\u043b \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0443, \u043f\u043e\u0438\u0441\u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0438\u0437 \u043f\u0430\u043b\u0438\u0442\u0440\u044b<\/li>\n<li>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0446\u0432\u0435\u0442\u0430 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435.<\/li>\n<\/ol>\n<p>  <\/p>\n<h5>\u042d\u0442\u0430\u043f 1<\/h5>\n<p>  \u0421\u0430\u043c\u044b\u043c \u0432\u0430\u0436\u043d\u044b\u0439 \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f. \u041e\u0442 \u043d\u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u0442\u0430\u043f\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439, \u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e. \u041d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e \u043a\u0430\u043a\u0438\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0446\u0432\u0435\u0442\u043e\u0432 \u0432\u0430\u0436\u043d\u0435\u0435 \u0434\u0440\u0443\u0433\u043e\u0433\u043e. <\/p>\n<p>  \u0422\u0443\u0442 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c canvas \u043f\u043e\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0432\u0435\u0442\u043e\u0432 \u0432 \u043d\u0435\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 255 (\u043e\u0434\u0438\u043d \u0446\u0432\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c, \u0442\u043e \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0441\u0430\u043c\u0430\u044f \u0431\u044b\u0441\u0442\u0440\u0430\u044f. \u0412\u0441\u0435\u0433\u043e 20ms \u0434\u043b\u044f jpg \u0444\u0430\u0439\u043b\u0430 \u0441 \u0441\u043e\u0431\u0430\u0447\u043a\u043e\u0439 (\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u044b\u0448\u0435) \u0438\u0437 1500ms \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. <\/p>\n<p>  \u041e\u043f\u044b\u0442\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u043c \u044f \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u0440\u043e\u0432\u043d\u043e \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. \u0418\u043d\u0430\u0447\u0435 \u0438\u0441\u043a\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u0446\u0432\u0435\u0442\u0430.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0431\u0430\u0439\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b \u0442\u0430\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f:<\/p>\n<pre>red=0xFF-alpha*(1-red\/0xFF) green=0xFF-alpha*(1-green\/0xFF) blue=0xFF-alpha*(1-blue\/0xFF)<\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0441\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0446\u0432\u0435\u0442\u0430 \u044f \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u043d\u0430 \u0431\u0435\u043b\u044b\u0439 \u0444\u043e\u043d. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 alpha \u0440\u0430\u0432\u0435\u043d 0, \u0437\u043d\u0430\u0447\u0438\u0442 \u044d\u0442\u043e\u0442 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 \u0438 \u043e\u043d \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f.<\/p>\n<h5>\u042d\u0442\u0430\u043f\u044b 2 \u0438 3<\/h5>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438 \u0437\u0430\u043d\u043e\u0432\u043e \u0432\u0441\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 (\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430) \u0442\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043f\u0430\u043b\u0438\u0442\u0440\u0443. <br \/>  \u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0446\u0432\u0435\u0442 \u0438\u0437 \u043f\u0430\u043b\u0438\u0442\u0440\u044b. \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0440\u0430\u0441\u043d\u044b\u0439, \u0441\u0438\u043d\u0438\u0439 \u0438 \u0437\u0435\u043b\u0435\u043d\u044b\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0446\u0432\u0435\u0442\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u0432 \u0442\u0440\u0435\u0445\u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0442\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0434\u0432\u0443\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430c\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438. \u0410 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u041f\u0438\u0444\u0430\u0433\u043e\u0440\u0430: <\/p>\n<pre>d=sqrt((x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2)<\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430 \u2014 \u0446\u0432\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043f\u0430\u043b\u0438\u0442\u0440\u0443. \u0418 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0435\u0441\u0442\u044c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0446\u0432\u0435\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435.<br \/>  \u0422\u0443\u0442 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f. \u0418\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u043b\u043e\u0441\u044c \u0430\u0436 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430, \u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430 \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e 255 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e 100 \u0438\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0446\u0432\u0435\u0442\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043f\u0430\u043b\u0438\u0442\u0440\u0443.<\/p>\n<h5>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u0442\u0430\u043f<\/h5>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0446\u0432\u0435\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0446\u0432\u0435\u0442\u043e\u0432 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435. \u041f\u0440\u0438 \u0447\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430. \u0418 \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 255 \u0446\u0432\u0435\u0442\u043e\u0432 \u043b\u0438\u0431\u043e \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u044d\u0442\u0430\u043f\u0443.<\/p>\n<h5>\u042d\u0442\u0430\u043f 4<\/h5>\n<p>  \u0422\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0438 \u043f\u043e \u0446\u0432\u0435\u0442\u0443 \u043f\u0438\u043a\u0441\u0435\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0446\u0432\u0435\u0442\u0430 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435.<\/p>\n<h4>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f \u044f\u0437\u044b\u043a\u0430 Javascript<\/h4>\n<p>  \u0412 \u0445\u043e\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 Javascrpt \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u044d\u0442\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u043b\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c.<\/p>\n<h5>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0434\u0432\u0443\u0445 \u0446\u0432\u0435\u0442\u043e\u0432<\/h5>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0446\u0432\u0435\u0442\u0430\u043c\u0438. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u041f\u0438\u0444\u0430\u0433\u043e\u0440\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Javascript. \u041a\u0430\u043a \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043a\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439?<\/p>\n<pre><code class=\"javascript\">\/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1 Math.sqrt(Math.pow(red1-red2,2)+Math.pow(green1-green2,2)+Math.pow(blue1-blue2,2))  \/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2 var mypow = function(a){     return a*a;  }; Math.sqrt(mypow(red1-red2)+mypow(green1-green2)+mypow(blue1-blue2))  \/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3 Math.sqrt((red1-red2)*(red1-red2)+(green1-green2)*(green1-green2)+(blue1-blue2)*(blue1-blue2))  \/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 4 var distance = function(a,b,c){ \treturn Math.sqrt(a*a+b*b+c*c);  }; distance(red1-red2, green1-green2,blue2-blue2) <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u043d\u0443 \u0445\u0438\u0442 \u043f\u0430\u0440\u0430\u0434 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u2014 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 2. \u0421\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432 2,5 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f Math.pow. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f 3-\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c, \u0442\u043e \u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0432 \u0431\u043e\u043b\u0435\u0435 10 \u0440\u0430\u0437 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439. \u041e\u0442\u0441\u044e\u0434\u0430 \u044f \u0434\u0435\u043b\u0430\u044e \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u0432 javascript \u043e\u0447\u0435\u043d\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0418 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u044d\u0442\u043e, \u0440\u0430\u0431\u043e\u0442\u0430\u044f \u0432 10 \u0440\u0430\u0437 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e.<br \/>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0449\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c. \u041f\u043e \u0441\u0443\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0446\u0432\u0435\u0442\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043d\u044f. <\/p>\n<pre><code class=\"javascript\">\/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 5 (red1-red2)*(red1-red2)+(green1-green2)*(green1-green2)+(blue1-blue2)*(blue1-blue2) <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0435\u0449\u0435 \u0432 1.5 \u0440\u0430\u0437\u0430. <br \/>  \u041f\u0440\u0438 \u0447\u0435\u043c, \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u043b\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"javascript\">\/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 6 (red=red1-red2)*red+(green=green1-green2)*green+(blue=blue1-blue2)*blue <\/code><\/pre>\n<p>  \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u044d\u0442\u0430\u043f\u043e\u0432 \u0441 \u0442\u0440\u0435\u043c\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u043c\u0438:  <\/p>\n<table>\n<tr>\n<th><\/th>\n<th>\u0421\u043e\u0431\u0430\u043a\u0430<\/th>\n<th>Alpha Romeo<\/th>\n<th>\u0418\u043a\u043e\u043d\u043a\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432<\/th>\n<\/tr>\n<tr>\n<td>Math.sqrt(Math.pow(r1-r2,2)+Math.pow(g1-g2,2)+Math.pow(b1-b2,2))<\/td>\n<td>17211ms<\/td>\n<td>1762ms<\/td>\n<td>117ms<\/td>\n<\/tr>\n<tr>\n<td>Math.sqrt(mypow(r1-r2)+mypow(g1-g2)+mypow(b1-b2))<\/td>\n<td>40790ms<\/td>\n<td>3875ms<\/td>\n<td>255ms<\/td>\n<\/tr>\n<tr>\n<td>Math.sqrt((r1-r2)*(r1-r2)+(g1-g2)*(g1-g2)+(b1-b2)*(b1-b2))<\/td>\n<td>1250ms<\/td>\n<td>149ms<\/td>\n<td>14ms<\/td>\n<\/tr>\n<tr>\n<td>distance(r1-r2, g1-g2,b2-b2)<\/td>\n<td>15006ms<\/td>\n<td>1556ms<\/td>\n<td>99ms<\/td>\n<\/tr>\n<tr>\n<td>(r1-r2)*(r1-r2)+(g1-g2)*(g1-g2)+(b1-b2)*(b1-b2)<\/td>\n<td>779ms<\/td>\n<td>104ms<\/td>\n<td>12ms<\/td>\n<\/tr>\n<tr>\n<td>(r=r1-r2)*r+(g=g1-g2)*g+(b=b1-b2)*b<\/td>\n<td>740ms<\/td>\n<td>100ms<\/td>\n<td>10ms<\/td>\n<\/tr>\n<\/table>\n<p>  <\/p>\n<h5>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0430\u043b\u0438\u0442\u0440\u044b<\/h5>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0432\u0435\u0442\u043e\u0432. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">if(palette.indexOf(color) == -1)     palette.push(color); <\/code><\/pre>\n<p>  \u041d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 indexOf \u2014 \u043e\u0447\u0435\u043d\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u0438\u0441\u043a\u043e\u043c\u044b\u043c.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u043c\u0435\u043d\u044f\u043b \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439:<\/p>\n<pre><code class=\"javascript\">if(!palette[color))     palette[color]=true; <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0430 \u043f\u0440\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u044b\u043b\u0430 \u0432 2 \u043f\u043e\u0440\u044f\u0434\u043a\u0430. \u0427\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0446\u0432\u0435\u0442\u0430 \u044f \u0440\u0435\u0448\u0438\u043b \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435:<\/p>\n<pre><code class=\"javascript\">if(!palette[color))     palette[color]={r:red, g:green, b:blue}; <\/code><\/pre>\n<p>  \u041d\u043e \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u043e\u0432 \u043f\u0440\u043e\u0445\u043e\u0434\u0430:<\/p>\n<pre><code class=\"javascript\">for(var color in palette){     var rgb=palette[color]; } <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">for(var i=0, n=palette.length; i&lt;n; i++){     var pal=palette[i]; } <\/code><\/pre>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 (palette), \u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0435\u0441\u0442\u044c \u043b\u0438 \u0446\u0432\u0435\u0442 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 (exists):<\/p>\n<pre><code class=\"javascript\">if(!exists[color)){     exists[color]=true;     palette.push({c:color, r:red, g:green, b:blue}); } for(var i=0, n=palette.length; i&lt;n; i++){     var pal=palette[i]; } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0446\u0438\u043a\u043b\u043e\u0432<\/h5>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u0438\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u0440\u043e\u0445\u043e\u0434\u0430 \u0446\u0438\u043a\u043b\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1 for(var i=0, n=palette.length; i&lt;n; i++){     var pal=palette[i]; }  \/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2 for(var i=0; i&lt;palette.length; i++){     var pal=palette[i]; }  \/\/\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3 for(var i=0, pal; pal=palette[i]; i++){ } <\/code><\/pre>\n<p>  \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u043d \u0441\u0430\u043c\u044b\u0439 \u0443\u0434\u043e\u0431\u043d\u044b\u0439. \u041d\u043e \u0435\u0441\u043b\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0442\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u0430\u044f. \u0420\u0430\u0437\u043d\u0438\u0446\u044b \u043f\u043e\u0447\u0442\u0438 \u043d\u0435\u0442. \u0421\u0443\u0434\u0438\u0442\u0435 \u0441\u0430\u043c\u0438:  <\/p>\n<table>\n<tr>\n<th><\/th>\n<th>\u0421\u043e\u0431\u0430\u043a\u0430<\/th>\n<th>Alpha Romeo<\/th>\n<th>\u0418\u043a\u043e\u043d\u043a\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432<\/th>\n<\/tr>\n<tr>\n<td>for(var i=0, n=palette.length; i&lt;n; i++)<\/td>\n<td>238ms<\/td>\n<td>51ms<\/td>\n<td>3,5ms<\/td>\n<\/tr>\n<tr>\n<td>for(var i=0; i&lt;palette.length; i++)<\/td>\n<td>244ms<\/td>\n<td>55ms<\/td>\n<td>3,5ms<\/td>\n<\/tr>\n<tr>\n<td>for(var i=0, pal; pal=palette[i]; i++)<\/td>\n<td>230ms<\/td>\n<td>54ms<\/td>\n<td>3,5ms<\/td>\n<\/tr>\n<\/table>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h4>\n<p>  GIF \u0432 GIF, 100x16px, 35ms:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/aa9\/570\/b25\/aa9570b2573dc014056d6bdb7ae7d6e5.png\"\/><\/p>\n<p>  JPEG \u0432 GIF, 604x377px, 1338ms:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/8bd\/2c3\/1f2\/8bd2c31f23fbe5125e76734e0abd2b9c.png\"\/><\/p>\n<p>  \u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 PNG \u0432 GIF, 256x256px, 268ms:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/50e\/e12\/767\/50ee12767ec1b420eaf708715ee3bb26.png\"\/><\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044f \u0434\u043e\u0432\u043e\u043b\u0435\u043d. \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u043c \u0434\u0430\u0432\u0430\u043b\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e\u0442 antimatter15. \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0439. \u041d\u0443 \u0438 \u0431\u0430\u0439\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438 \u0443\u0447\u0442\u0435\u043d. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442 \u043c\u043e\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">(\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 canvasToGIFDataURL \u0438 canvasPalette)  <\/p>\n<pre><code class=\"javascript\"> \t\t\/\/ base64 encodes either a string or an array of charcodes \t\tvar encodeData = function(data) { \t\t\tvar strData = &quot;&quot;; \t\t\tif (typeof data == &quot;string&quot;) { \t\t\t\tstrData = data; \t\t\t} else { \t\t\t\tvar aData = data; \t\t\t\tfor (var i=0;i&lt;aData.length;i++) { \t\t\t\t\tstrData += String.fromCharCode(aData[i]); \t\t\t\t} \t\t\t} \t\t\treturn btoa(strData); \t\t}; \t\tvar readCanvasData = function(oCanvas) { \t\t\tvar iWidth = parseInt(oCanvas.width); \t\t\tvar iHeight = parseInt(oCanvas.height); \t\t\treturn oCanvas.getContext(&quot;2d&quot;).getImageData(0,0,iWidth,iHeight); \t\t}; \t\tvar makeDataURI = function(strData, strMime) { \t\t\treturn &quot;data:&quot; + strMime + &quot;;base64,&quot; + strData; \t\t};  \t\tvar cW=0xff;\t  \t\tvar canvasPalette=function(canvas){ \t\t\tvar oData = readCanvasData(canvas), \t\t\t\tdata=oData.data, \t\t\t\texists={}, \t\t\t\tpalette=[]; \t\t\t \t\t\tfor(var i = 0, n=data.length; i &lt; n; i+=4){ \t\t\t\tvar a=data[i+3]; \t\t\t\tif(a==0) \t\t\t\t\tcontinue; \t\t\t\tvar\tr=(cW-a*(1-data[i]\/cW))|0, \t\t\t\t\tg=(cW-a*(1-data[i+1]\/cW))|0, \t\t\t\t\tb=(cW-a*(1-data[i+2]\/cW))|0, \t\t\t\t\tcol=b+(g&lt;&lt;8)+(r&lt;&lt;16); \t\t\t\t\t \t\t\t\tif(!exists[col]){ \t\t\t\t\tif(palette.length&gt;=255){ \t\t\t\t\t\tvar subcanvas=document.createElement('canvas'), \t\t\t\t\t\t\twidth=oData.width&gt;&gt;1, \t\t\t\t\t\t\theight=oData.height&gt;&gt;1; \t\t\t\t\t\tsubcanvas.width=width; \t\t\t\t\t\tsubcanvas.height=height; \t\t\t\t\t\tsubcanvas.getContext('2d').drawImage(canvas, 0, 0,width,height); \t\t\t\t\t\treturn canvasPalette(subcanvas); \t\t\t\t\t} \t\t\t\t\telse{ \t\t\t\t\t\texists[col]=true; \t\t\t\t\t\tpalette.push({c:col,r:r,g:g,b:b}); \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t\treturn {exists:exists, palette:palette}; \t\t} \t\tvar canvasToGIFDataURL = function(canvas,mime){ \t\t\t\t\t\tvar dr,dg,db; \t\t\t\t\t\tvar oData = readCanvasData(canvas); \t\t\t\t\t\t \t\t\t\t\t\tvar data=oData.data; \t\t\t\t\t\t \t\t\t\t\t\tvar palette=canvasPalette(canvas); \t\t\t\t\t\tvar exists=palette.exists; \t\t\t\t\t\tpalette=palette.palette; \t\t\t\t\t\t \t\t\t\t\t\tvar outpalette=[]; \t\t\t\t\t\tvar pixels=[]; \t\t\t\t\t\t \t\t\t\t\t\tvar maxdDifI=null; \t\t\t\t\t\tvar maxdDif=0; \t\t\t\t\t\tfor(var i = 0,pi=0,l=data.length; i &lt; l; i+=4, pi++){ \t\t\t\t\t\t\tvar a=data[i+3]; \t\t\t\t\t\t\tif(a==0){ \t\t\t\t\t\t\t\tpixels[pi]=-1; \t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t} \t\t\t\t\t\t\tvar\tr=(cW-a*(1-data[i]\/cW))|0, \t\t\t\t\t\t\t\tg=(cW-a*(1-data[i+1]\/cW))|0, \t\t\t\t\t\t\t\tb=(cW-a*(1-data[i+2]\/cW))|0, \t\t\t\t\t\t\t\tcol=b+(g&lt;&lt;8)+(r&lt;&lt;16); \t\t\t\t\t\t\tpixels[pi]=col; \t\t\t\t\t\t\tif(!exists[col]){ \t\t\t\t\t\t\t\texists[col]=true; \t\t\t\t\t\t\t\tvar minDif=0xffffff, \t\t\t\t\t\t\t\t\tminDifColIndex=null; \t\t\t\t\t\t\t \t\t\t\t\t\t\t\tfor(var j=0, nj=palette.length; j&lt;nj; j++){ \t\t\t\t\t\t\t\t\tvar pal=palette[j], \t\t\t\t\t\t\t\t\t\td=(dr=pal.r-r)*dr+(dg=pal.g-g)*dg+(db=pal.b-b)*db; \t\t\t\t\t\t\t\t\tif(d&lt;minDif){ \t\t\t\t\t\t\t\t\t\tminDif=d; \t\t\t\t\t\t\t\t\t\tminDifColIndex=j; \t\t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\tif(minDif &gt; maxdDif) { \t\t\t\t\t\t\t\t\tmaxdDif=minDif; \t\t\t\t\t\t\t\t\tmaxDifI=outpalette.length; \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\toutpalette.push({c:col, d:minDif, r:r, g:g, b:b, index:minDifColIndex}); \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t\t \t\t\t\t\t\t \t\t\t\t\t\t \t\t\t\t\t\t \t\t\t\t\t\t \t\t\t\t\t\twhile(maxdDif!=null && palette.length&lt;255){ \t\t\t\t\t\t\tvar dif=outpalette.splice(maxdDifI,1)[0]; \t\t\t\t\t\t\t  \t\t\t\t\t\t\tmaxdDif=null; \t\t\t\t\t\t\tmaxdDifI=0; \t\t\t\t\t\t\tvar r=dif.r, g=dif.g, b=dif.b, col=dif.c; \t\t\t\t\t\t\t \t\t\t\t\t\t\tvar index=palette.length; \t\t\t\t\t\t\tpalette.push({c:col,r:r,g:g,b:b}); \t\t\t\t\t\t\t \t\t\t\t\t\t\tfor(var j=0, nj=outpalette.length; j&lt;nj; j++){ \t\t\t\t\t\t\t\tvar dif=outpalette[j], \t\t\t\t\t\t\t\t\td=(dr=dif.r-r)*dr+(dg=dif.g-g)*dg+(db=dif.b-b)*db; \t\t\t\t\t\t\t\tif(d&lt;dif.d){ \t\t\t\t\t\t\t\t\tdif.d=d; \t\t\t\t\t\t\t\t\tdif.index=index; \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\tif(dif.d &gt; maxdDif) { \t\t\t\t\t\t\t\t\tmaxdDif=dif.d; \t\t\t\t\t\t\t\t\tmaxDifI=j; \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t} \t\t\t\t\t\t\t \t\t\t\t\t\t} \t\t\t\t\t\tvar map={}; \t\t\t\t\t\tpalette.unshift({c:-1}); \t\t\t\t\t\tfor(var j=0,pal; pal=palette[j]; j++){ \t\t\t\t\t\t\tvar col=pal.c; \t\t\t\t\t\t\tmap[col]=j; \t\t\t\t\t\t\tpalette[j]=col; \t\t\t\t\t\t} \t\t\t\t\t\tfor(var j=0,dif; dif=outpalette[j]; j++){ \t\t\t\t\t\t\tmap[dif.c]=dif.index+1; \t\t\t\t\t\t} \t\t\t\t\t\tvar indexes=[]; \t\t\t\t\t\tfor(var i = 0, pixel; pixel=pixels[i]; i++){ \t\t\t\t\t\t\tindexes.push(map[pixel]); \t\t\t\t\t\t} \t\t\t\t\t\tfor(var l=2;l&lt;=256;l=l&lt;&lt;1){ \t\t\t\t\t\t\tif(palette.length==l) break; \t\t\t\t\t\t\tif(palette.length&lt;l) { \t\t\t\t\t\t\t\twhile(palette.length&lt;l) \t\t\t\t\t\t\t\t\tpalette.push(0); \t\t\t\t\t\t\t\tbreak; \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t\tvar buf = []; \t\t\t\t\t\tvar gf = new GifWriter(buf, oData.width, oData.height, {palette: palette}); \t\t\t\t\t\tgf.addFrame(0, 0, oData.width, oData.height, indexes,{transparent: 0}); \t\t\t\t\t\tvar binary_gif =  buf.slice(0, gf.end()); \t\t\t\t\t\treturn makeDataURI(encodeData(binary_gif), 'image\/gif');\t\t\t \t\t}; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u044f \u0441 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c: <br \/>   \u2014 \u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043d\u0430 Javascript!    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/173773\/\"> http:\/\/habrahabr.ru\/post\/173773\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/8bd\/2c3\/1f2\/8bd2c31f23fbe5125e76734e0abd2b9c.png\"\/><br \/>  \u0420\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u0445 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437 canvas \u0432 gif.<br \/>  \u0422\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043c\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 javascript \u043a\u043e\u0434 \u043a\u0432\u0430\u043d\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0442\u043e \u0435\u0441\u0442\u044c \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0434\u043e 256 \u0446\u0432\u0435\u0442\u043e\u0432). \u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 javascript \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-173773","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/173773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173773"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/173773\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}