{"id":6464,"date":"2022-04-27T14:13:02","date_gmt":"2022-04-27T05:13:02","guid":{"rendered":"http:\/\/www.otwo.jp\/blog\/?p=6464"},"modified":"2022-04-27T14:13:02","modified_gmt":"2022-04-27T05:13:02","slug":"js-particle","status":"publish","type":"post","link":"https:\/\/www.otwo.jp\/blog\/js-particle\/","title":{"rendered":"\u5e7e\u4f55\u5b66\u306a\u52d5\u304d\u3092\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u306e\u4f5c\u308a\u65b9\u3010JavaScript \/ \u5b66\u7fd2\u7528\u3011"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2022\/01\/particle.png\" alt=\"\" width=\"700\" height=\"400\" class=\"alignnone size-full wp-image-6489\" srcset=\"https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2022\/01\/particle.png 700w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2022\/01\/particle-150x86.png 150w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2022\/01\/particle-300x171.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><br \/>\n\u3053\u3093\u306b\u3061\u306fWEB\u306e\u4f50\u91ce\u3067\u3059\u3002<br \/>\n\u65e9\u3044\u3082\u306e\u3067\u4eca\u5e74\u3082GW\u9593\u8fd1\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u4eca\u5e74\u3082\u30aa\u30fc\u30c4\u30fc\u3092\u3069\u3046\u305e\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3044\u305f\u3057\u307e\u3059\u3002<\/p>\n<p>\u3055\u3066\u4eca\u56de\u306fJavaScript\u3067\u5e7e\u4f55\u5b66\u7684\u306a\u52d5\u304d\u3092\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u3092\u4f5c\u3063\u3066\u307f\u305f\u306e\u3067\u5171\u6709\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\nWEB\u30b5\u30a4\u30c8\u3067\u4f7f\u3046\u6a5f\u4f1a\u306f\u5c11\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304cCanvas\u3067\u5b9f\u88c5\u3057\u3066\u3044\u3066\u5b66\u7fd2\u306b\u3061\u3087\u3046\u3069\u826f\u3044\u96e3\u6613\u5ea6\u3060\u3068\u611f\u3058\u305f\u306e\u3067\u3001\u30b3\u30fc\u30c9\u3082\u8f09\u305b\u3066\u3044\u307e\u3059\u304c\u305c\u3072\u4e00\u5ea6\u3054\u81ea\u8eab\u3067\u3082\u4f5c\u3063\u3066\u307f\u3066\u307b\u3057\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div class=\"pageContents\">\n<p class=\"title\">\u3082\u304f\u3058<\/p>\n<dl>\n<dt><a href=\"#step1\">\u4eca\u56de\u306e\u5b9f\u88c5\u5185\u5bb9<\/a><\/dt>\n<dt><a href=\"#step2\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/a><\/dt>\n<dt><a href=\"#step3\">\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306b\u306frequestAnimationFrame<\/a><\/dt>\n<dd><a href=\"#step3-1\">requestAnimationFrame\u30e1\u30bd\u30c3\u30c9<\/a><\/dd>\n<dd><a href=\"#step3-2\">requestAnimationFrame\u306e\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9<\/a><\/dd>\n<dt><a href=\"#step4\">\u30ea\u30b5\u30a4\u30ba\u306b\u3064\u3044\u3066<\/a><\/dt>\n<dd><a href=\"#step4-1\">Canvas\u306f\u30ea\u30b5\u30a4\u30ba\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044<\/a><\/dd>\n<dd><a href=\"#step4-2\">\u8868\u793a\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u6570\u3092\u66f4\u65b0<\/a><\/dd>\n<\/dl>\n<\/div>\n<h2 id=\"step1\">\u4eca\u56de\u306e\u5b9f\u88c5\u5185\u5bb9<\/h2>\n<p>\u307e\u305a\u306f\u4eca\u56de\u4f5c\u3063\u305f\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p class=\"codepen\" data-height=\"500\" data-default-tab=\"result\" data-slug-hash=\"mdBgeGj\" data-user=\"otwo\" style=\"height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\">\n  <span>See the Pen <a href=\"https:\/\/codepen.io\/otwo\/pen\/mdBgeGj\"><br \/>\n  Untitled<\/a> by otwo (<a href=\"https:\/\/codepen.io\/otwo\">@otwo<\/a>)<br \/>\n  on <a href=\"https:\/\/codepen.io\">CodePen<\/a>.<\/span>\n<\/p>\n<p><script async src=\"https:\/\/cpwebassets.codepen.io\/assets\/embed\/ei.js\"><\/script><br \/>\n\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3001\u305d\u308c\u3089\u3057\u3044\u898b\u6804\u3048\u306b\u306a\u3063\u3066\u308b\u3068\u601d\u3044\u307e\u3059\uff01<\/p>\n<p>\u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u4ed5\u69d8\u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div style=\"font-size: 90%; background-color: #e6efe6; padding: 2% 2.5%; border-radius: 10px; line-height: 2.0em;\">\n\u30fb\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u540c\u58eb\u304c\u8fd1\u3065\u3044\u305f\u3089\u7dda\u3067\u7e4b\u3050<br \/>\n\u30fb\u30ea\u30b5\u30a4\u30ba\u306b\u5bfe\u5fdc\n<\/div>\n<p>\u30b7\u30f3\u30d7\u30eb\u306b\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u6b21\u306b\u79c1\u304c\u4f5c\u3063\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u51fa\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u3082\u3057\u4e00\u5ea6\u81ea\u5206\u3067\u4f5c\u3063\u3066\u307f\u305f\u3044\u65b9\u306f\u3053\u3053\u3067\u30b9\u30c8\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2 id=\"step2\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<p>\u3068\u8a00\u3046\u3053\u3068\u3067\u65e9\u901f\u79c1\u304c\u4f5c\u3063\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3059\u3002<br \/>\n\u3053\u3053\u306b\u306fJavaScript\u306e\u30b3\u30fc\u30c9\u3057\u304b\u8f09\u305b\u3066\u3044\u306a\u3044\u306e\u3067\u3001HTML\u3084CSS\u306e\u30b3\u30fc\u30c9\u306f\u4e0a\u306eCodepen\u3067\u3054\u78ba\u8a8d\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-python\"><code>\/\/ \u5404\u7a2e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\r\nconst ratio = 10;   \/\/ \u753b\u9762\u306b\u8868\u793a\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u6570\u306e\u8a08\u7b97\u306b\u5229\u7528\r\nconst min = 0.3;    \/\/ \u79fb\u52d5\u30b9\u30d4\u30fc\u30c9\u306e\u6700\u5c0f\u5024\r\nconst max = 2;      \/\/ \u79fb\u52d5\u30b9\u30d4\u30fc\u30c9\u306e\u6700\u5927\u5024\r\nconst dist = 200;   \/\/ \u7dda\u3067\u7e4b\u304c\u308b\u307e\u3067\u306e\u8ddd\u96e2\r\n\r\n\/\/ \u4ee5\u4e0b\u3001\u51e6\u7406\r\nconst cvs = document.getElementById(\"canvas\");\r\nconst ctx = cvs.getContext(\"2d\");\r\nlet intParticle = 0;    \/\/ \u8868\u793a\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u6570\r\nlet aryParticle = [];   \/\/ \u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u8981\u7d20\u306e\u60c5\u5831\r\nlet canvas = {};        \/\/ canvas\u306e\u7e26\u6a2a\u306e\u60c5\u5831\r\n\/\/ \u521d\u671f\u51e6\u7406\r\nfunction init(){\r\n  calc();\r\n  draw();\r\n}\r\ninit();\r\n\r\n\/\/ \u30ea\u30b5\u30a4\u30ba\u51e6\u7406\r\nwindow.onresize = function(){\r\n  calc();\r\n}\r\n\r\n\/\/ canvas\u30b5\u30a4\u30ba\u306e\u8abf\u6574\r\nfunction calc(){\r\n  canvas.width = cvs.width = document.body.clientWidth;\r\n  canvas.height = cvs.height = document.body.clientHeight;\r\n  intParticle = Math.floor((canvas.width \/ 300 * ratio) + (canvas.height \/ 300 * ratio));\r\n  if(aryParticle.length < intParticle){\r\n    create(aryParticle.length);\r\n  }\r\n}\r\n\r\n\/\/ \u30d1\u30fc\u30c6\u30a3\u30ab\u30eb\u8981\u7d20\u3092\u751f\u6210\r\nfunction create(start){\r\n  for(let i = start;i < intParticle;i++){\r\n    aryParticle.push({\r\n      position: {   \/\/ \u521d\u671f\u4f4d\u7f6e\r\n        x: random(0, canvas.width),\r\n        y: random(0, canvas.height)\r\n      },\r\n      direction: {  \/\/ \u9032\u884c\u65b9\u5411\r\n        x: random(min, max, true) * ((random(0, 1)? -1: 1)),\r\n        y: random(min, max, true) * ((random(0, 1)? -1: 1))\r\n      },\r\n      circle: 2     \/\/ \u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u306e\u534a\u5f84\r\n    });\r\n  }\r\n}\r\n\r\n\/\/ \u6307\u5b9a\u7bc4\u56f2\u306a\u3044\u304b\u3089\u4e71\u6570\u3092\u751f\u6210\r\nfunction random(min, max, deci = false){\r\n  let result = Math.random() * (max + 1 - min) + min;\r\n  return  (deci)? result: Math.floor(result);\r\n}\r\n\r\n\/\/ \u63cf\u753b\u51e6\u7406\r\nfunction draw(){\r\n  ctx.clearRect(0, 0, canvas.width, canvas.height);\r\n  for(let i = 0;i < intParticle;i++){\r\n    let _p = aryParticle[i];\r\n    \/\/ \u7e01\u3092\u63cf\u753b\r\n    ctx.beginPath();\r\n    ctx.fillStyle = \"#ffffff\";\r\n    ctx.globalAlpha = 1;\r\n    ctx.arc(_p.position.x, _p.position.y, _p.circle, 0, 2 * Math.PI);\r\n    ctx.fill();\r\n\r\n    \/\/ \u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u306e\u66f4\u65b0\r\n    aryParticle[i].position.x += _p.direction.x;\r\n    aryParticle[i].position.y += _p.direction.y;\r\n\r\n    \/\/ \u753b\u9762\u306e\u7aef\u306b\u5f53\u305f\u3063\u305f\u3089\u65b9\u5411\u3092\u5e30\u308b\r\n    if(_p.position.x < 0 || _p.position.x > canvas.width){\r\n      aryParticle[i].direction.x *= -1;\r\n    }\r\n    if(_p.position.y < 0 || _p.position.y > canvas.height){\r\n      aryParticle[i].direction.y *= -1;\r\n    }\r\n\r\n    \/\/ \u30ea\u30b5\u30a4\u30ba\u3067\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u304c\u5b8c\u5168\u306b\u898b\u5207\u308c\u305f\u5834\u5408\r\n    if(_p.position.x < -_p.circle) aryParticle[i].position.x = _p.circle;\r\n    if(_p.position.x > canvas.width + _p.circle) aryParticle[i].position.x = canvas.width - (_p.circle * 2);\r\n    if(_p.position.y < -_p.circle) aryParticle[i].position.y = _p.circle;\r\n    if(_p.position.y > canvas.height + _p.circle) aryParticle[i].position.y = canvas.height - (_p.circle * 2);\r\n\r\n    \/\/ \u7dda\u3067\u7e4b\u3050\r\n    for(let _i = 0;_i < intParticle;_i++){\r\n      let _n = aryParticle[_i];\r\n      if(i != _i){\r\n        let _dist = Math.abs(_p.position.x - _n.position.x) + Math.abs(_p.position.y - _n.position.y);\r\n        if(_dist < dist){\r\n          ctx.beginPath();\r\n          ctx.globalAlpha = ((dist-_dist)>(dist\/2)? 1: 1-(((dist\/2)-(dist-_dist))\/(dist\/2)));\r\n          ctx.strokeStyle = \"#ffffff\";\r\n          ctx.moveTo(_p.position.x, _p.position.y);\r\n          ctx.lineTo(_n.position.x, _n.position.y);\r\n          ctx.stroke();\r\n        }\r\n      }\r\n    }\r\n  }\r\n  requestAnimationFrame(draw);\r\n}\r\n\r\nvar requestAnimationFrame = ( function(){\r\n  return  window.requestAnimationFrame       ||\r\n          window.webkitRequestAnimationFrame ||\r\n          window.mozRequestAnimationFrame    ||\r\n          window.oRequestAnimationFrame      ||\r\n          window.msRequestAnimationFrame     ||\r\n          function( callback ){\r\n            window.setTimeout( callback, 1000 \/ 60 );\r\n          };\r\n} )();\r\n<\/code><\/pre>\n<\/div>\n<p>\u30b3\u30fc\u30c9\u306f\u77ed\u3051\u308c\u3070\u3044\u3044\u3068\u8a00\u3046\u3082\u306e\u3067\u3082\u306a\u3044\u3067\u3059\u304c\u3001\u30d6\u30ed\u30b0\u306e\u898b\u6804\u3048\u3082\u8003\u3048\u3066\u4e00\u90e8\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9(\u66f8\u5f0f\u306e\u7701\u7565)\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9\u306b\u3064\u3044\u3066\u306f\u904e\u53bb\u8a18\u4e8b\u3067\u7d39\u4ecb\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u304a\u6642\u9593\u3042\u308c\u3070\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"externalLink\"><a href=\"https:\/\/www.otwo.jp\/blog\/js-shorthand\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u521d\u5fc3\u8005\u3067\u3082\u77e5\u3063\u3066\u304a\u304d\u305f\u3044JavaScript\u306e\u4fbf\u5229\u306a\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9<\/a><\/div>\n<p>\u3042\u3068\u3001\u904e\u53bb\u306eCanvas\u7cfb\u306e\u8a18\u4e8b\u3082\u8f09\u305b\u3066\u304a\u304f\u306e\u3067\u6c17\u304c\u5411\u3044\u305f\u3089\u3069\u3046\u305e\uff01<\/p>\n<div class=\"externalLink\"><a href=\"https:\/\/www.otwo.jp\/blog\/canvas_sakura\/\" target=\"_blank\" rel=\"noopener noreferrer\">Canvas\u3067\u685c\u3092\u964d\u3089\u305b\u3066\u307f\u307e\u3057\u305f<\/a><\/div>\n<div class=\"externalLink\"><a href=\"https:\/\/www.otwo.jp\/blog\/canvas-drawing\/\" target=\"_blank\" rel=\"noopener noreferrer\">Canvas\u3092\u4f7f\u3063\u3066\u304a\u7d75\u63cf\u304d\u3068\u753b\u50cf\u306e\u4fdd\u5b58\u3092\u3057\u3066\u307f\u308b<\/a><\/div>\n<h2 id=\"step3\">\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306b\u306frequestAnimationFrame<\/h2>\n<p>Canvas\u306f\u8981\u7d20\u3092\u63cf\u753b\u2192\u524a\u9664\u2192\u63cf\u753b\u2026\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u30d1\u30e9\u30d1\u30e9\u6f2b\u753b\u306e\u69d8\u306b\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u8868\u73fe\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u306e\u30eb\u30fc\u30d7\u306bsetTimeout\u3084setInterval\u3067\u3082\u53ef\u80fd\u3067\u3059\u304c\u3001\u3053\u3053\u3067\u306frequestAnimationFrame\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u3066\u304a\u308a\u3001JavaScript\u3067\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3059\u308b\u306a\u3089\u5fc5\u305a\u899a\u3048\u3066\u304a\u3044\u305f\u65b9\u304c\u3044\u3044\u30e1\u30bd\u30c3\u30c9\u306b\u306a\u308b\u306e\u3067\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h3 id=\"step3-1\">requestAnimationFrame\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>requestAnimationFrame\u306f\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3067\u3042\u308b\u3053\u3068\u3092\u5b9a\u7fa9\u3057\u3066\u3001\u8ca0\u8377\u3092\u5c11\u306a\u304f\u51e6\u7406\u3092\u30eb\u30fc\u30d7\u3057\u3066\u304f\u308c\u308b\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\n\u4f7f\u3044\u65b9\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3054\u304f\u7c21\u5358\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-python\"><code>function loop(){\r\n  \/\/ \u25bc\u3053\u3053\u306b\u51e6\u7406\r\n\r\n  \/\/ \u25b2\u3053\u3053\u306b\u51e6\u7406\r\n  requestAnimationFrame(loop);\t\/\/ \u5f15\u6570\u306fcallback\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>requestAnimationFrame\u306fsetInterval\u306a\u3069\u3068\u9055\u3063\u3066\u3001\u767a\u706b\u306e\u30bf\u30a4\u30df\u30f3\u30b0(\u30df\u30ea\u79d2)\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u52d5\u304d\u3068\u3057\u3066\u306f\u63cf\u753b\u51e6\u7406\u304c\u3059\u3079\u3066\u5b8c\u4e86\u3057\u3001\u6b21\u306e\u63cf\u753b\u6e96\u5099\u304c\u3067\u304d\u305f\u3089\u51e6\u7406\u3092\u958b\u59cb\u3059\u308b\u3068\u8a00\u3046\u52d5\u304d\u3092\u3057\u3066\u3044\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3055\u3089\u306b\u306f\u30d6\u30e9\u30a6\u30b6\u304c\u975e\u30a2\u30af\u30c6\u30a3\u30d6\u306e\u6642\u306f\u51e6\u7406\u3092\u505c\u6b62\u3059\u308b\u306a\u3069\u30e1\u30e2\u30ea\u6d88\u8cbb\u3092\u6291\u3048\u3066\u304f\u308c\u308b\u305f\u3081\u3001\u305c\u3072\u899a\u3048\u3066\u304a\u304d\u305f\u3044\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u306d\uff01<\/p>\n<p>\u203b\u4f59\u8ac7\u3067\u3059\u304c\u3001setInterval\u306710\u30df\u30ea\u79d2\u3092\u6307\u5b9a\u3057\u3066\u7d44\u3093\u3067\u307f\u307e\u3057\u305f\u304cFireFox\u3067\u306f\u51e6\u7406\u304c\u91cd\u3059\u304e\u3066\u30ab\u30af\u30ab\u30af\u3067\u3057\u305f\u3002<\/p>\n<h3 id=\"step3-2\">requestAnimationFrame\u306e\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9<\/h3>\n<p>107\u884c\u76ee\u304b\u3089\u3053\u306e\u8a18\u8ff0\u3067\u3059\u304c\u3001requestAnimationFrame\u306f\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u304c\u3042\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u308c\u304c\u306a\u304f\u3066\u3082\u52d5\u304d\u307e\u3059\u304c\u3001\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3042\u308c\u3070\u5b9a\u7fa9\u3057\u3066\u304a\u304f\u65b9\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-python\"><code>var requestAnimationFrame = ( function(){\r\n  return  window.requestAnimationFrame       ||\r\n          window.webkitRequestAnimationFrame ||\r\n          window.mozRequestAnimationFrame    ||\r\n          window.oRequestAnimationFrame      ||\r\n          window.msRequestAnimationFrame     ||\r\n          function( callback ){\r\n            window.setTimeout( callback, 1000 \/ 60 );\r\n          };\r\n} )();\r\n<\/code><\/pre>\n<\/div>\n<p>requestAnimationFrame\u3092\u30b3\u30fc\u30eb\u3057\u305f\u6642\u306b\u5404\u30d6\u30e9\u30a6\u30b6\u306e\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u304c\u5b9f\u884c\u3055\u308c\u3001\u8a18\u8ff0\u3057\u3066\u3044\u306a\u3044\u30d6\u30e9\u30a6\u30b6\u4ee5\u5916\u3067\u306f1\u79d2\u9593\u306b60\u56de\u51e6\u7406\u3055\u308c\u308b\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4ed6\u306e\u30b5\u30a4\u30c8\u3082\u62dd\u898b\u3057\u307e\u3057\u305f\u304c\u3001\u307b\u3068\u3093\u3069\u304c\u3053\u306e\u66f8\u5f0f\u3060\u3063\u305f\u306e\u3067\u7406\u89e3\u304c\u96e3\u3057\u3044\u5834\u5408\u306b\u306f\u3068\u308a\u3042\u3048\u305a\u3067\u3082\u304a\u307e\u3058\u306a\u3044\u3068\u3057\u3066\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h2 id=\"step4\">\u30ea\u30b5\u30a4\u30ba\u306b\u3064\u3044\u3066<\/h2>\n<p>\u4eca\u56de\u306e\u8981\u4ef6\u3067\u30ea\u30b5\u30a4\u30ba\u5bfe\u5fdc\u3092\u542b\u3081\u3066\u3044\u3066\u3001\u7279\u8a18\u3059\u308b\u3053\u3068\u3082\u306a\u3044\u306e\u3067\u3059\u304c\u7c21\u5358\u306b\u30ea\u30b5\u30a4\u30ba\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h3 id=\"step4-1\">Canvas\u306f\u30ea\u30b5\u30a4\u30ba\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044<\/h3>\n<p>1\u3064\u6ce8\u610f\u3057\u3066\u304a\u304d\u305f\u3044\u70b9\u304c\u3001<span style=\"color: #f00;\">Canvas\u306f\u30ea\u30b5\u30a4\u30ba\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044<\/span>\u3068\u3044\u3046\u3053\u3068\u3002<br \/>\n\u306a\u306e\u3067\u30ea\u30b5\u30a4\u30ba\u3092\u610f\u8b58\u3059\u308b\u5834\u5408\u306f\u51e6\u7406\u3092\u81ea\u5206\u3067\u7d44\u3080\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u3068\u8a00\u3063\u3066\u3082\u96e3\u3057\u3044\u3053\u3068\u3082\u306a\u304f\u3001\u30ea\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u3066Canvas\u30bf\u30b0\u306b\u6307\u5b9a\u3057\u3066\u308b\u30b5\u30a4\u30ba\u60c5\u5831\u3092\u66f4\u65b0\u3057\u3066\u3042\u3052\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-python\"><code>\/\/ canvas\u30b5\u30a4\u30ba\u306e\u8abf\u6574\r\nfunction calc(){\r\n  canvas.width = cvs.width = document.body.clientWidth;\r\n  canvas.height = cvs.height = document.body.clientHeight;\r\n  intParticle = Math.floor((canvas.width \/ 300 * ratio) + (canvas.height \/ 300 * ratio));\r\n  if(aryParticle.length < intParticle){\r\n    create(aryParticle.length);\r\n  }\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u3053\u306e\u500b\u6240\u306b\u306a\u308a\u307e\u3059\u304c\u30013,4\u884c\u76ee\u3067\u30ea\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u3066Canvas\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306ewidth\u3068height\u3092body\u30b5\u30a4\u30ba\u3067\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3 id=\"step4-2\">\u8868\u793a\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u6570\u3092\u66f4\u65b0<\/h3>\n<p>\u30ea\u30b5\u30a4\u30ba\u6642\u306b\u8868\u793a\u7528\u57df\u306b\u5408\u308f\u305b\u3066\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u6570\u3092\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f\u7d14\u7c8b\u306b100\u500b\u8868\u793a\u3068\u3057\u305f\u6642\u306b\u30d1\u30bd\u30b3\u30f3\u3060\u3068\u4e01\u5ea6\u3088\u304f\u3066\u3082\u30b9\u30de\u30db\u3060\u3068\u591a\u3059\u304e\u3066\u898b\u3065\u3089\u3044\u2026\u3068\u8a00\u3046\u72b6\u6cc1\u3078\u306e\u5bfe\u5fdc\u3067\u3059\u3002<br \/>\n5\u884c\u76ee\u306b\u306a\u308a\u307e\u3059\u304c\u3001300\u3068\u306a\u3063\u3066\u3044\u308b\u306e\u306f\u3056\u3063\u304f\u308a\u30d0\u30e9\u30f3\u30b9\u53d6\u308c\u305d\u3046\u306a\u6570\u5b57\u3092\u5165\u308c\u3066\u3044\u308b\u3060\u3051\u306a\u306e\u3067\u6570\u5b57\u3092\u5909\u66f4\u3057\u3066\u3082\u3089\u3063\u3066\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3053\u306e\u6319\u52d5\u306fparticle.js\u3068\u8a00\u3046\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u52d5\u304d\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n<div class=\"externalLink\"><a href=\"https:\/\/vincentgarreau.com\/particles.js\/\" target=\"_blank\" rel=\"noopener noreferrer\">particles.js<\/a><\/div>\n<p>\u81ea\u5206\u3067\u8003\u3048\u305f\u6319\u52d5\u3067\u5b9f\u88c5\u3059\u308b\u306e\u3082\u52c9\u5f37\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u5b9f\u7e3e\u306e\u3042\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u53c2\u8003\u306b\u3059\u308b\u306e\u3082\u30a2\u30a4\u30c7\u30a2\u304c\u5e83\u304c\u3063\u3066\u52c9\u5f37\u306b\u306a\u308a\u307e\u3059\u306d\uff01<\/p>\n<hr>\n<\/hr>\n<p>\u3044\u304b\u304c\u3060\u3063\u305f\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u4eca\u56de\u306f\u8272\u3082\u52d5\u304d\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u3057\u3066\u3044\u308b\u306e\u3067\u5c11\u3057\u5909\u5316\u3092\u52a0\u3048\u308b\u3060\u3051\u3067\u3082\u898b\u6804\u3048\u3082\u5909\u308f\u3063\u3066\u30aa\u30b7\u30e3\u30ec\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3053\u3046\u3057\u305f\u52d5\u304d\u306e\u3042\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4f5c\u3063\u3066\u3044\u3066\u3082\u697d\u3057\u3044\u3067\u3059\u3057\u6c17\u3065\u304d\u3082\u591a\u304f\u3001\u5b66\u7fd2\u306b\u3082\u3063\u3066\u3053\u3044\u3067\u3059\u306d\uff01<br \/>\n\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059\u3001\u3067\u306f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306fWEB\u306e\u4f50\u91ce\u3067\u3059\u3002 \u65e9\u3044\u3082\u306e\u3067\u4eca\u5e74\u3082GW\u9593\u8fd1\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u4eca\u5e74\u3082\u30aa\u30fc\u30c4\u30fc\u3092\u3069\u3046\u305e\u3088\u308d\u3057\u304f\u304a\u9858\u3044\u3044\u305f\u3057\u307e\u3059\u3002 \u3055\u3066\u4eca\u56de\u306fJavaScript\u3067\u5e7e\u4f55\u5b66\u7684\u306a\u52d5\u304d\u3092\u3059\u308b\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u3092\u4f5c\u3063\u3066\u307f\u305f\u306e\u3067\u5171\u6709\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059 [&hellip;]<\/p>\n","protected":false},"author":25,"featured_media":6488,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[82,83,94],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/6464"}],"collection":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/comments?post=6464"}],"version-history":[{"count":44,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/6464\/revisions"}],"predecessor-version":[{"id":6513,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/6464\/revisions\/6513"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/media\/6488"}],"wp:attachment":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/media?parent=6464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/categories?post=6464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/tags?post=6464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}