{"id":11523,"date":"2021-07-30T17:00:00","date_gmt":"2021-07-30T08:00:00","guid":{"rendered":"https:\/\/kusakarism.info\/?p=11523"},"modified":"2021-10-10T10:29:44","modified_gmt":"2021-10-10T01:29:44","slug":"js_class","status":"publish","type":"post","link":"https:\/\/kusakarism.info\/?p=11523","title":{"rendered":"JavaScript\u306e\u300c\u30af\u30e9\u30b9\u300d\u306b\u3064\u3044\u3066\u89e3\u8aac\u3059\u308b\u52d5\u753b"},"content":{"rendered":"<h2>JavaScript\u306e\u30af\u30e9\u30b9\u3092\u89e3\u8aac\u3057\u305f\u52d5\u753b\u306e\u30b3\u30fc\u30c9<\/h2>\n<p>JavaScript\u306e\u5165\u9580\u8b1b\u5ea7\u3082\u305d\u308d\u305d\u308d\u7d42\u76e4\u3067\u3059\u3002<br \/>\u6b21\u56de\u304b\u3089\u3044\u3088\u3044\u3088\u300c\u30c6\u30c8\u30ea\u30b9\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306b\u5165\u308a\u307e\u3059\u3002<\/p>\n<p>\u30af\u30e9\u30b9\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u3057\u3066\u3044\u304f\u969b\u306e\u4e2d\u5fc3\u3068\u306a\u308b\u8003\u3048\u65b9\u3002<\/p>\n<p>\u4eca\u56de\u306e\u52d5\u753b\u3067\u306f\u3001\u305d\u306e\u30af\u30e9\u30b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u52d5\u753b\u672c\u7de8\u306f<span style=\"font-size: 18pt;\"><strong><a href=\"https:\/\/youtu.be\/ImvBFk2v40I\">\u30b3\u30c1\u30e9<\/a><\/strong><\/span><\/p>\n<p>JavaScript\u30b7\u30ea\u30fc\u30ba\u306e\u518d\u751f\u30ea\u30b9\u30c8\u306f<span style=\"font-size: 18pt;\"><strong><a href=\"https:\/\/youtube.com\/playlist?list=PLECzW07lVCizuuq4Mk8CcP828RK70cq9D\">\u30b3\u30c1\u30e9<\/a><\/strong><\/span><\/p>\n<p>\u89e3\u8aac\u306f\u52d5\u753b\u672c\u7de8\u3092\u898b\u3066\u3044\u305f\u3060\u304f\u3068\u3057\u3066\u3001\u3053\u3053\u306b\u306f\u5b66\u7fd2\u7528\u306e\u30b3\u30fc\u30c9\u3092\u63b2\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u5b8c\u6210\u6642\u306e\u6319\u52d5\u306f<strong><span style=\"font-size: 18pt;\"><a href=\"https:\/\/kusakarism.info\/programming_lesson\/Lesson_11.html\">\u30b3\u30c1\u30e9<\/a><\/span><\/strong>\u304b\u3089\u78ba\u8a8d\u3057\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u3002<\/p>\n<p><\/p>\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-html\" data-file=\"lesson_11.html\" data-lang=\"HTML\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;ja&quot;&gt;\n&lt;head&gt;\n\t&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\t&lt;canvas id=&quot;canId&quot; width=600 height=500&gt;&lt;\/canvas&gt;&lt;br&gt;\n\t&lt;button onclick=&quot;stop()&quot;&gt;STOP&lt;\/button&gt;\n\n\t&lt;script&gt;\n\t\tlet getE = document.getElementById(&quot;canId&quot;);\n\t\tgetE.style.backgroundColor = &quot;black&quot;;\n\t\tlet can = getE.getContext(&quot;2d&quot;);\n\n\t\tlet interval = setInterval(loop, 10);\t\/\/ \u7e70\u308a\u8fd4\u3057\u51e6\u7406\n\t\t\n\t\tfunction stop(){\n\t\t\t clearInterval(interval);\n\t\t\t Smiley.clearField();\n\t\t}\n\n\t\t\/\/******************** \u30b9\u30de\u30a4\u30ea\u30fc\u30af\u30e9\u30b9 ********************\n\t\tclass Smiley{\n\t\t\tconstructor(x, y, moveX, moveY){\t\/\/ \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30fc\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t\tthis.moveX = moveX;\n\t\t\t\tthis.moveY = moveY;\n\t\t\t\tthis.color = &quot;yellow&quot;;\n\t\t\t}\n\t\t\tstatic clearField(){\t\t\t\/\/ \u30af\u30ea\u30a2\u95a2\u6570\n\t\t\t\tcan.fillStyle = &quot;#000&quot;;\n\t\t\t\tcan.fillRect(0,0,600,500);\n\t\t\t}\n\t\t\tdraw(){\t\t\t\t\t\t\t\/\/ \u30c9\u30ed\u30fc\u95a2\u6570\n\t\t\t\tcan.beginPath();\t\t\t\t\t\t\/\/ \u30cb\u30b3\u3061\u3083\u3093\u8f2a\u90ed\n\t\t\t\tcan.arc(50+this.x, 50+this.y, 50, 0, Math.PI*2);\n\t\t\t\tcan.fillStyle = this.color;\n\t\t\t\tcan.fill();\n\t\t\t\tcan.beginPath();\t\t\t\t\t\t\/\/ \u30cb\u30b3\u3061\u3083\u3093\u306e\u53e3\n\t\t\t\tcan.arc(50+this.x, 50+this.y, 35, 0, Math.PI);\n\t\t\t\tcan.strokeStyle = &quot;black&quot;;\n\t\t\t\tcan.lineWidth = 4;\n\t\t\t\tcan.stroke();\n\t\t\t\tcan.beginPath();\t\t\t\t\t\t\/\/ \u30cb\u30b3\u3061\u3083\u3093\u306e\u76ee\n\t\t\t\tcan.ellipse(35+this.x, 40+this.y, 5, 8, 0, 0, Math.PI*2);\n\t\t\t\tcan.ellipse(65+this.x, 40+this.y, 5, 8, 0, 0, Math.PI*2);\n\t\t\t\tcan.fillStyle = &quot;black&quot;;\n\t\t\t\tcan.fill();\n\t\t\t}\n\t\t\tmove(){\t\t\t\t\t\t\t\/\/ \u30e0\u30fc\u30d6\u95a2\u6570\n\t\t\t\tif (this.x&lt;0 || this.x&gt;500){ this.moveX *= -1;}\t\t\/\/ \u5de6\u53f3\u58c1\u3068\u306e\u885d\u7a81\u5224\u5b9a\n\t\t\t\tif (this.y&lt;0 || this.y&gt;400){ this.moveY *= -1;}\t\t\/\/ \u5929\u4e95\u3068\u5e8a\u3068\u306e\u885d\u7a81\u5224\u5b9a\n\n\t\t\t\tthis.x += this.moveX;\t\t\t\t\t\t\t\t\/\/ \u6b21\u56de\u63cf\u753b\u4f4d\u7f6e\u3092\u8a2d\u5b9a\n\t\t\t\tthis.y += this.moveY;\n\t\t\t}\n\t\t}\n\n\t\t\/\/******************** \u30b9\u30de\u30a4\u30ea\u30fc\uff12\u30af\u30e9\u30b9 ********************\n\t\tclass Smiley2 extends Smiley{\t\/\/\u30b9\u30de\u30a4\u30ea\u30fc\u30af\u30e9\u30b9\u3092\u7d99\u627f\n\t\t\tmove(){\t\t\t\t\t\t\/\/move()\u30e1\u30bd\u30c3\u30c9\u3060\u3051\u5909\u66f4\u2192\u5929\u4e95\u3068\u5e8a\u3067\u53cd\u5c04\u3068\u540c\u6642\u306b\u8272\u304c\u5909\u5316\n\t\t\t\tlet arrayColor = [&quot;white&quot;,&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;];\n\t\t\t\tif (this.x&lt;0 || this.x&gt;500){ this.moveX *= -1;}\t\n\t\t\t\tif (this.y&lt;0 || this.y&gt;400){\n\t\t\t\t\tthis.moveY *= -1;\n\t\t\t\t\tthis.color = arrayColor[Math.floor(Math.random()*4)];\n\t\t\t\t}\t\n\t\t\t\tthis.x += this.moveX;\t\n\t\t\t\tthis.y += this.moveY;\n\t\t\t}\n\t\t}\n\n\t\t\/\/******************** \u30b9\u30de\u30a4\u30ea\u30fc\uff13 ********************\n\t\tclass Smiley3 extends Smiley2{\t\/\/\u30b9\u30de\u30a4\u30ea\u30fc\uff12\u30af\u30e9\u30b9\u3092\u7d99\u627f\n\t\t\tdraw(){\t\t\t\t\t\t\/\/draw()\u30e1\u30bd\u30c3\u30c9\u3060\u3051\u5909\u66f4\u2192\u56db\u89d2\u3044\u30cb\u30b3\u3061\u3083\u3093\n\t\t\t\tcan.beginPath();\t\t\t\t\t\t\n\t\t\t\tcan.rect(this.x, this.y, 100, 100);\n\t\t\t\tcan.fillStyle = this.color;\n\t\t\t\tcan.fill();\n\t\t\t\tcan.beginPath();\t\t\t\t\t\t\n\t\t\t\tcan.arc(50+this.x, 50+this.y, 35, 0, Math.PI);\n\t\t\t\tcan.strokeStyle = &quot;black&quot;;\n\t\t\t\tcan.lineWidth = 4;\n\t\t\t\tcan.stroke();\n\t\t\t\tcan.beginPath();\t\t\t\t\t\t\n\t\t\t\tcan.ellipse(35+this.x, 40+this.y, 5, 8, 0, 0, Math.PI*2);\n\t\t\t\tcan.ellipse(65+this.x, 40+this.y, 5, 8, 0, 0, Math.PI*2);\n\t\t\t\tcan.fillStyle = &quot;black&quot;;\n\t\t\t\tcan.fill();\n\t\t\t}\n\t\t}\n\n\n\t\t\/\/ \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u306a\u3069\n\t\tlet smileys = [];\n\t\tlet nico_1 = new Smiley3(0,0,3,5);\n\t\tlet nico_2 = new Smiley2(0,0,1,5);\n\t\tsmileys.push(nico_1);\n\t\tsmileys.push(nico_2);\n\t\tfor (let i=0; i&lt;10; i++){\n\t\t\tlet moveX = Math.floor(Math.random()*5)+1;\n\t\t\tlet moveY = Math.floor(Math.random()*5)+1;\n\t\t\tlet smile = new Smiley(0,0,moveX,moveY);\n\t\t\tsmileys.push(smile);\t\t\t\n\t\t}\n\n\t\tfunction loop(){\n\t\t\tSmiley.clearField();\n\t\t\tfor (let i=0; i&lt;smileys.length; i++){\n\t\t\t\tsmileys[i].draw();\n\t\t\t\tsmileys[i].move();\n\t\t\t}\n\t\t}\n\n\n\n\t&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript\u306e\u30af\u30e9\u30b9\u3092\u89e3\u8aac\u3057\u305f\u52d5\u753b\u306e\u30b3\u30fc\u30c9 JavaScript\u306e\u5165\u9580\u8b1b\u5ea7\u3082\u305d\u308d\u305d\u308d\u7d42\u76e4\u3067\u3059\u3002\u6b21\u56de\u304b\u3089\u3044\u3088\u3044\u3088\u300c\u30c6\u30c8\u30ea\u30b9\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306b\u5165\u308a\u307e\u3059\u3002 \u30af\u30e9\u30b9\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11594,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[350,340],"tags":[],"class_list":["post-11523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-programming"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts\/11523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11523"}],"version-history":[{"count":4,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts\/11523\/revisions"}],"predecessor-version":[{"id":11678,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts\/11523\/revisions\/11678"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/media\/11594"}],"wp:attachment":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}